예제 #1
0
void CDFFileReader::Read(CDFData& data, ReadMode mode)
{
	data.Clear();
	//data.GetGenericData().UseMemoryMapping(false);
	GenericFileReader reader;
	if (fileName.empty())
		fileName = data.GetFilename();
	reader.SetFilename(fileName);
	reader.ReadHeader(data.GetGenericData(), GenericFileReader::ReadNoDataGroupHeader);

	switch(mode)
	{
	case ReadSequential:
		data.PrepareForSequentialAccess();
		break;
	case ReadByProbeSetNumber:
		data.PrepareForAccessByProbeSetIndex();
		break;
	case ReadByProbeSetName:
		data.PrepareForAccessByProbeSetName();
		break;
	default:
		data.PrepareForSequentialAccess();
		break;
	}
}
예제 #2
0
void GenericDataTest_MinDPH::setUp()
{
	// Create generic data header
	data = new GenericData;
	GenericFileReader reader;
	std::string name = TEST_DATA_DAT_FILE;
	reader.SetFilename(name);
	reader.ReadHeader(*data, GenericFileReader::ReadMinDataGroupHeader);
}
void CHPTilingFileReader::Read(CHPTilingData& data)
{
	data.Clear();
	GenericFileReader reader;
	if (fileName.empty())
	{
		fileName = data.GetFilename();
	}
	reader.SetFilename(fileName);
	reader.ReadHeader(data.GetGenericData());
}
void CHPQuantificationDetectionFileReader::Read(CHPQuantificationDetectionData& data)
{
	data.Clear();
	GenericFileReader reader;
	if (fileName.empty())
	{
		fileName = data.GetFilename();
	}
	reader.SetFilename(fileName);
	reader.ReadHeader(data.GetGenericData());
}
예제 #5
0
/*
 * Determines if a CDF file is of the Calvin format.
 */
bool FusionCDFData::IsCalvinCompatibleFile(const char *fileName)
{
    GenericData data;
    GenericFileReader reader;
    reader.SetFilename(fileName);
    try
    {
        reader.ReadHeader(data, GenericFileReader::ReadNoDataGroupHeader);
        return true;
    }
    catch (affymetrix_calvin_exceptions::CalvinException)
    {
    }
    return false;
}
예제 #6
0
void DataSetTest_DATGridSet::setUp()
{
	data = new GenericData;
	GenericFileReader reader;
	std::string name = TEST_DATA_DAT_FILE_WITH_GRIDS;
	reader.SetFilename(name);
	reader.ReadHeader(*data);
	try
	{
		dataPlane = data->DataSet(0,1);	// grids is the second DataSet of the first DataGroup.
	}
	catch(affymetrix_calvin_exceptions::CalvinException&)
	{
		dataPlane = 0;
	}
}
예제 #7
0
void DataSetTest_GenericData::ColsFromDataSetWithZeroRows()
{
	GenericData gd;
	GenericFileReader reader;
	reader.SetFilename("../data/small_cel_file_with_dataset_of_zero_rows");
	reader.ReadHeader(gd);

	// Open a DataSet that has 0 rows.
	DataSet* ds = gd.DataSet(0,3);
	CPPUNIT_ASSERT(ds);
	CPPUNIT_ASSERT(ds->Cols() == 2);
	CPPUNIT_ASSERT(ds->Rows() == 0);

	ds->Delete();

	// Open another DataSet that has 0 rows.
	ds = gd.DataSet(0,4);
	CPPUNIT_ASSERT(ds);
	CPPUNIT_ASSERT(ds->Cols() == 2);
	CPPUNIT_ASSERT(ds->Rows() == 0);

	ds->Delete();
}
/** 
 * No more probesets will be processed, this is a chance to finish outputting
 * results and clean up.
 * @param qMethod - Quantification method that was used.
 * @return true if success, false otherwise.
 */
bool QuantMethodExprCCCHPReport::finish(QuantMethod &qMethod) 
{
    // Sanity to check we saw all the probe sets we were expecting.
    if (m_CurrentProbeSetCount != m_Info.m_NumProbeSets) {
        Err::errAbort("QuantMethodExprCCCHPReport::finish() - Expecting: " + ToStr(m_Info.m_NumProbeSets) +
            " but got: " + ToStr(m_CurrentProbeSetCount) + ". Command Console CHP file will be corrupt.");
    }

    // Flush remaining signal entries in the buffer.
    m_ExpressionQuantificationBufferWriter.FlushBuffer();

    // Rewrite CHP files to get chip summary entires
    Verbose::out(1,"Creating final files for CHP output");
    Verbose::progressBegin(1, ToStr("Finalizing Expression CHP Files"), 
                           m_CHPFileNames.size(), 1, m_CHPFileNames.size());
    try {
        for (unsigned int chip = 0; chip < m_CHPFileNames.size(); chip++) {
            // open up tmp chp file to pull results from
            GenericData data;
            GenericFileReader reader;
            std::string filename = m_CHPFileNames[chip]+".tmp";
            reader.SetFilename(filename);
            reader.ReadHeader(data);

            GenericDataHeader* hdr = data.Header().GetGenericDataHdr();
            GenericDataHeader updateHdr;
            for (int source = 0; source < m_ChipSummaries.size(); source++) {
                ChipSummary::metricDefVec_t metricDefs = m_ChipSummaries[source]->getMetricDefs();
                for (int i = 0; i < metricDefs.size(); i++) {
                    ChipSummary::Metric metric;
                    if (!m_ChipSummaries[source]->getMetric(chip, metricDefs[i].m_name, metric)) {
                        Err::errAbort("QuantMethodExprCCCHPReport: metric '" + metricDefs[i].m_name +
                                      "' was not found");
                    }
                    std::wstring mName(CHIP_SUMMARY_PARAMETER_NAME_PREFIX);
                    mName += StringUtils::ConvertMBSToWCS(metric.m_Name);
                    ParameterNameValueType param;
                    if (hdr->FindNameValParam(mName, param) == false) {
                        Err::errAbort("QuantMethodExprCCCHPReport: metric name '" + StringUtils::ConvertWCSToMBS(mName) +
                                      "' could not be found in the header of " + filename);
                    }

                    switch (param.GetParameterType()) {
                    case ParameterNameValueType::Int8Type:
                        param.SetValueInt8((int8_t)metric.m_Integer);
                        break;
                    
                    case ParameterNameValueType::UInt8Type:
                        param.SetValueUInt8((u_int8_t)metric.m_Integer);
                        break;
                    
                    case ParameterNameValueType::Int16Type:
                        param.SetValueInt16((int16_t)metric.m_Integer);
                        break;
                    
                    case ParameterNameValueType::UInt16Type:
                        param.SetValueUInt16((u_int16_t)metric.m_Integer);
                        break;
                    
                    case ParameterNameValueType::Int32Type:
                        param.SetValueInt32((int32_t)metric.m_Integer);
                        break;
                    
                    case ParameterNameValueType::UInt32Type:
                        param.SetValueUInt32((u_int32_t)metric.m_Integer);
                        break;
                
                    case ParameterNameValueType::FloatType:
                        param.SetValueFloat((float)metric.m_Double);
                        break;
                
                    case ParameterNameValueType::TextType:
                        param.SetValueText(StringUtils::ConvertMBSToWCS(metric.m_String), (int) metric.m_String.length());
                        break;
                
                    case ParameterNameValueType::AsciiType:
                        if (metric.m_String.size() > 256) {
                            Err::errAbort("QuantMethodExprCCCHPReport: string header parameter too long, name = '" +
                                          metric.m_Name + "', value = '" + metric.m_String + "'");
                        }
                        param.SetValueAscii(metric.m_String, (int) metric.m_String.length());
                        break;

                    default:
                        Err::errAbort("QuantMethodExprCCCHPReport: unknown header parameter type found in file " +
                                      filename);
                    }
                    updateHdr.AddNameValParam(param);
                }
            }
            std::ofstream os;
            Fs::aptOpen(os, filename, std::ios::out|std::ios::binary|std::ios::in);
            if (!os) {
                Err::errAbort("QuantMethodExprCCCHPReport: file " + filename +
                              " could not be opened for writing");
            }
            GenericDataHeaderUpdater updater;
            updater.Update(os, updateHdr, *hdr);
            os.close();

            Verbose::progressStep(1);
        }
    } catch (...) {
        removeAllChps();
        Err::errAbort("Error in creating final CHP output.");
    }
    Verbose::progressEnd(1, ToStr("Done."));

    // Remove .tmp extension
    for (unsigned int i = 0; i < m_CHPFileNames.size(); i++) {
        std::string from = m_CHPFileNames[i] + ".tmp";
        std::string to = m_CHPFileNames[i];
        if (!Fs::fileRename(from.c_str(),to.c_str())) {
            removeAllChps();
            Err::errAbort("Unable to rename '" + from + "' to '" + to + "'");
        }
    }
    removeTmpChps();

    return true;
}
/*
 * Read the file contents into the data object.
 */
void GridControlFileReader::Read(const std::string &fileName, GridControlData& data)
{
	// Clear the old data and read the file.
	data.Clear();
	GenericFileReader reader;
	GenericData gdata;
	reader.SetFilename(fileName);
	reader.ReadHeader(gdata);

	// Check the file identifier
	if (gdata.FileIdentifier() != GRD_FILE_TYPE_IDENTIFIER)
	{
		affymetrix_calvin_exceptions::InvalidFileTypeException e(L"Calvin",L"Default Description, Please Update!",affymetrix_calvin_utilities::DateTime::GetCurrentDateTime().ToString(),std::string(__FILE__),(u_int16_t)__LINE__,0);
		throw e;
	}

	// Get the header parameters.
	ParameterNameValueType param;
	gdata.Header().GetGenericDataHdr()->FindNameValParam(GRD_ROWS_PARAMETER_NAME, param);
	data.SetRows(param.GetValueInt32());
	gdata.Header().GetGenericDataHdr()->FindNameValParam(GRD_COLUMNS_PARAMETER_NAME, param);
	data.SetColumns(param.GetValueInt32());

	// Get the XY coordinates from the dataSets.
	FeatureCoordinate coord;
	u_int16_t x;
	u_int16_t y;
	int nRows;
	DataSet *dataSet;

	// First the B1 probes.
	dataSet = gdata.DataSet(GRD_FILE_COORDINATE_GROUP_NAME, GRD_FILE_B1_SET_NAME);
	if (dataSet->Open() == false)
	{
		affymetrix_calvin_exceptions::DataSetNotOpenException e(L"Calvin",L"Default Description, Please Update!",affymetrix_calvin_utilities::DateTime::GetCurrentDateTime().ToString(),std::string(__FILE__),(u_int16_t)__LINE__,0);
		throw e;
	}
	nRows = dataSet->Rows();
	data.ResizeB1(nRows);
	for (int iRow=0; iRow<nRows; iRow++)
	{
		dataSet->GetData(iRow, 0, x);
		dataSet->GetData(iRow, 1, y);
		coord.x = x;
		coord.y = y;
		data.SetB1(iRow, coord);
	}
	dataSet->Close();
	dataSet->Delete();

	// Next the B2 probes.
	dataSet = gdata.DataSet(GRD_FILE_COORDINATE_GROUP_NAME, GRD_FILE_B2_SET_NAME);
	if (dataSet->Open() == false)
	{
		affymetrix_calvin_exceptions::DataSetNotOpenException e(L"Calvin",L"Default Description, Please Update!",affymetrix_calvin_utilities::DateTime::GetCurrentDateTime().ToString(),std::string(__FILE__),(u_int16_t)__LINE__,0);
		throw e;
	}
	nRows = dataSet->Rows();
	data.ResizeB2(nRows);
	for (int iRow=0; iRow<nRows; iRow++)
	{
		dataSet->GetData(iRow, 0, x);
		dataSet->GetData(iRow, 1, y);
		coord.x = x;
		coord.y = y;
		data.SetB2(iRow, coord);
	}
	dataSet->Close();
	dataSet->Delete();

	// Last the NS probes.
	dataSet = gdata.DataSet(GRD_FILE_COORDINATE_GROUP_NAME, GRD_FILE_NS_SET_NAME);
	if (dataSet->Open() == false)
	{
		affymetrix_calvin_exceptions::DataSetNotOpenException e(L"Calvin",L"Default Description, Please Update!",affymetrix_calvin_utilities::DateTime::GetCurrentDateTime().ToString(),std::string(__FILE__),(u_int16_t)__LINE__,0);
		throw e;
	}
	nRows = dataSet->Rows();
	data.ResizeNS(nRows);
	for (int iRow=0; iRow<nRows; iRow++)
	{
		dataSet->GetData(iRow, 0, x);
		dataSet->GetData(iRow, 1, y);
		coord.x = x;
		coord.y = y;
		data.SetNS(iRow, coord);
	}
	dataSet->Close();
	dataSet->Delete();
}
static int Fusion_GetDataSetOffsetAndSize
(
	const char *file_name,
	const char *wavelength,

	int &offset,
	int &size,

	char *err_msg,
	int err_msg_alloc_sz
	)
{
	GenericFileReader reader;

	string fname = file_name;
	reader.SetFilename (fname);

	GenericData hdr_data;
	reader.ReadHeader (hdr_data);

	GenericDataHeader *hdr = hdr_data.Header ().GetGenericDataHdr ();

	ParameterNameValueType cel_cols,cel_rows;	
	if (hdr->FindNameValParam(L"affymetrix-cel-cols",cel_cols) == false || 
		hdr->FindNameValParam(L"affymetrix-cel-cols",cel_rows) == false)
	{
		strncpy  (err_msg,"Invalid cel file",sizeof(err_msg_alloc_sz)-1);
		return FALSE;
	}

	string err_s;

	while (1)
	{
		size_t len = strlen (wavelength)+1;
		wchar_t *_wavelength = new wchar_t[len];
		for (UINT i=0; i<len; i++)
		{
			_wavelength[i] = (WORD)wavelength[i];
		}

		wstring group_name = _wavelength;
		delete [] _wavelength;

		DataGroupHeader *data_group_header = hdr_data.Header ().FindDataGroupHeader (group_name);

		if (data_group_header == 0)
		{
			err_s = "Missing data group ";
			err_s += wavelength;
			break;
		}

		DataSet *data_set = GetDataSet (L"Intensity", group_name, hdr_data);

		if (data_set == 0)
		{
			err_s = "Missing data set \"Intensity\"";
			break;
		}

		offset = data_set->Header ().GetDataStartFilePos ();
		size = data_set->Header ().GetDataSize ();

		break;
	}

	if (strlen (err_s.c_str ()))
	{
		strncpy (err_msg,err_s.c_str (),sizeof(err_msg_alloc_sz)-1);
		return FALSE;
	}

	return TRUE;
}