void CHPQuantificationFileWriterTest::WriteTest()
{
	ParameterNameValueTypeList params;
	ParameterNameValueType param;

	CHPQuantificationData data("CHP_quantification_file");

	data.SetAlgName(L"sig");
	data.SetAlgVersion(L"1.0");
	data.SetArrayType(L"test3");
	data.SetEntryCount(2, 10);

	param.SetName(L"an1");
	param.SetValueText(L"av1");
	params.push_back(param);
	data.AddAlgParams(params);

	params.clear();
	param.SetName(L"sn1");
	param.SetValueText(L"sv1");
	params.push_back(param);
	data.AddSummaryParams(params);


	CHPQuantificationFileWriter *writer = new CHPQuantificationFileWriter(data);
	affymetrix_calvin_data::ProbeSetQuantificationData e;

	writer->SeekToDataSet();
	e.name = "abc";
	e.quantification = 10.0f;
	writer->WriteEntry(e);
	e.name = "xyz";
	e.quantification = 20.0f;
	writer->WriteEntry(e);

	delete writer;

	CPPUNIT_ASSERT(1);




	CHPQuantificationData data2;
	CHPQuantificationFileReader reader;
	reader.SetFilename("CHP_quantification_file");
	reader.Read(data2);

	CPPUNIT_ASSERT(data2.GetAlgName() == L"sig");
	CPPUNIT_ASSERT(data2.GetAlgVersion() == L"1.0");
	CPPUNIT_ASSERT(data2.GetArrayType() == L"test3");
	CPPUNIT_ASSERT(data2.GetEntryCount() == 2);

	ParameterNameValueTypeList p = data2.GetAlgParams();
	ParameterNameValueTypeList::iterator it = p.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"an1");
	CPPUNIT_ASSERT(param.GetValueText() == L"av1");

	p = data2.GetSummaryParams();
	it = p.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"sn1");
	CPPUNIT_ASSERT(param.GetValueText() == L"sv1");


	data2.GetQuantificationEntry(0, e);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.quantification, 10.0f, 0.0001f);
	CPPUNIT_ASSERT(e.name == "abc");
	data2.GetQuantificationEntry(1, e);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.quantification, 20.0f, 0.0001f);
	CPPUNIT_ASSERT(e.name == "xyz");

}
Ejemplo n.º 2
0
/*! Create a "quantification" CHP file with just the header information. The remainder of the file
 * will be created at a later time using the buffer writer technique.
 * The CHP file will contain only "quantification" results from an expression analysis.
 * @param execId The execution identifier. This identifier is used to identify the batch run that created the CHP files.
 * @param celFile The full path to the parent CEL file. The header of the CEL file is copied to the CHP file.
 * @param outFile The name of the output CHP file.
 * @param probeSetNames The probe set names.
 * @param algName The name of the algorithm used to create the results.
 * @param algVersion The algorithm version.
 * @param chipType the chip type, also known as the probe array type.
 * @param programName The name of the program used to create the CHP file.
 * @param programVersion The version of the program.
 * @param programCompany The company or institution who developed the CHP creating software.
 * @param paramNames A list of parameter names to store in the CHP file header.
 * @param paramValues A list of parameter values to store in the CHP file header.
 * @param sumNames A list of summary statistic names to store in the CHP file header.
 * @param sumValues A list of summary statistic values to store in the CHP file header.
*/
static void CreateFileWithHeader
(
	const string &execId,
	const string &celFile,
	const string &outFile,
	const list<string> &probeSetNames,
	const string &algName,
	const string &algVersion,
	const string &chipType,
	const string &programName,
	const string &programVersion,
	const string &programCompany,
	const vector<string>& paramNames,
	const vector<string>& paramValues,
	const vector<string>& sumNames,
	const vector<string>& sumValues
)
{
	// Determine the max probe set name.
	int numEntries = (int) probeSetNames.size();
	int maxProbeSetNameLength = 0;
	for (list<string>::const_iterator it=probeSetNames.begin(); it!=probeSetNames.end(); it++)
	{
		maxProbeSetNameLength = max(maxProbeSetNameLength, (int) it->length());
	}

	// Create the data object
	CHPQuantificationData *data = new CHPQuantificationData(outFile);
    data->SetEntryCount(numEntries, maxProbeSetNameLength);
	data->SetAlgName(StringUtils::ConvertMBSToWCS(algName));
	data->SetAlgVersion(StringUtils::ConvertMBSToWCS(algVersion));
	data->SetArrayType(StringUtils::ConvertMBSToWCS(chipType));

	// Store the CEL header
	if (celFile.length() > 0 && FileUtils::Exists(celFile.c_str()) == true)
	{
		FusionCELData cel;
		cel.SetFileName(celFile.c_str());
        cel.ReadHeader();
	    GenericData *gdata = cel.GetGenericData();
	    if (gdata != NULL)
			data->GetFileHeader()->GetGenericDataHdr()->AddParent(*gdata->Header().GetGenericDataHdr()); 
	    cel.Close();
	}

	// Add algorithm parameters to list.
    ParameterNameValueTypeList params;
    ParameterNameValueType param;
    
	if (programName.empty() == false)
	{
		param.SetName(L"program-name");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programName));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	if (programVersion.empty() == false)
	{
		param.SetName(L"program-version");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programVersion));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	if (programCompany.empty() == false)
	{
		param.SetName(L"program-company");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programCompany));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	int nparams = (int) paramNames.size();
	param.SetName(L"exec-guid");
	param.SetValueAscii(execId);
	params.push_back(param);
	for(int iparam=0; iparam<nparams; iparam++)
	{
		param.SetName(StringUtils::ConvertMBSToWCS(paramNames[iparam]));
        param.SetValueAscii(paramValues[iparam]);
        params.push_back(param);
	}
	if (params.empty() == false)
		data->AddAlgParams(params);

	params.clear();
	nparams = (int) sumNames.size();
	for(int iparam=0; iparam<nparams; iparam++)
	{
		param.SetName(StringUtils::ConvertMBSToWCS(sumNames[iparam]));
        param.SetValueAscii(sumValues[iparam]);
        params.push_back(param);
	}
	if (params.empty() == false)
		data->AddSummaryParams(params);

	// Creating the writer object will create the file with the header information.
	CHPQuantificationFileWriter writer(*data);

	// Write the probe set names.
	writer.SeekToDataSet();
	ProbeSetQuantificationData entry;
	for (list<string>::const_iterator it=probeSetNames.begin(); it!=probeSetNames.end(); it++)
	{
        entry.name = *it;
        entry.quantification = 0.0f;
        writer.WriteEntry(entry);
    }
}
Ejemplo n.º 3
0
/*! Create a "multi-data" CHP file with just the header information. The remainder of the file
 * will be created at a later time using the buffer writer technique.
 * The CHP file will contain only "genotyping" results.
 * @param execId The execution identifier. This identifier is used to identify the batch run that created the CHP files.
 * @param celFile The full path to the parent CEL file. The header of the CEL file is copied to the CHP file.
 * @param outFile The name of the output CHP file.
 * @param extraColNames The names of the extra data columns. Should not include probe set name, call and confidence columns.
 * @param extraColTypes The types (float, int, ubyte) of the extra columns.
 * @param numEntries The number of rows (entries) of results to store in the CHP file.
 * @param maxProbeSetNameLength The maximum length of the probe set names.
 * @param algName The name of the algorithm used to create the results.
 * @param algVersion The algorithm version.
 * @param chipType the chip type, also known as the probe array type.
 * @param programName The name of the program used to create the CHP file.
 * @param programVersion The version of the program.
 * @param programCompany The company or institution who developed the CHP creating software.
 * @param paramNames A list of parameter names to store in the CHP file header.
 * @param paramValues A list of parameter values to store in the CHP file header.
 * @param sumNames A list of summary statistic names to store in the CHP file header.
 * @param sumValues A list of summary statistic values to store in the CHP file header.
*/
static void CreateFileWithHeader
(
	const string &execId,
	const string &celFile,
	const string &outFile,
	const vector<string>& extraColNames,
	const vector<string>& extraColTypes,
	unsigned long numEntries,
	int maxProbeSetNameLength,
	const string &algName,
	const string &algVersion,
	const string &chipType,
	const string &programName,
	const string &programVersion,
	const string &programCompany,
	const vector<string>& paramNames,
	const vector<string>& paramValues,
	const vector<string>& sumNames,
	const vector<string>& sumValues,
	const vector<string>& extraNames,
	const vector<string>& extraValues
)
{
	// Create the vector of extra columns. The sample code here supports only float, 32 bit integers and 8 bit unsigned integers.
	vector<ColumnInfo> extraColumns;
	int ncols = (int)extraColNames.size();
	for (int icol=0; icol<ncols; icol++)
	{
		if (extraColTypes[icol] == "float")
		{
			FloatColumn fcol(StringUtils::ConvertMBSToWCS(extraColNames[icol]));
			extraColumns.push_back(fcol);
		}
		else if (extraColTypes[icol] == "int")
		{
			IntColumn intcol(StringUtils::ConvertMBSToWCS(extraColNames[icol]));
			extraColumns.push_back(intcol);
		}
		else if (extraColTypes[icol] == "ubyte")
		{
			UByteColumn ubcol(StringUtils::ConvertMBSToWCS(extraColNames[icol]));
			extraColumns.push_back(ubcol);
		}
		else
		{
			throw string("Unsupported column type: ") + extraColTypes[icol];
		}
	}

	// Create the data object
	CHPMultiDataData *data = new CHPMultiDataData(outFile);
    data->SetEntryCount(GenotypeMultiDataType, numEntries, maxProbeSetNameLength, extraColumns);
	data->SetAlgName(StringUtils::ConvertMBSToWCS(algName));
	data->SetAlgVersion(StringUtils::ConvertMBSToWCS(algVersion));
	data->SetArrayType(StringUtils::ConvertMBSToWCS(chipType));

	// Store the CEL header
	if (celFile.length() > 0 && FileUtils::Exists(celFile.c_str()) == true)
	{
		FusionCELData cel;
		cel.SetFileName(celFile.c_str());
        cel.ReadHeader();
	    GenericData *gdata = cel.GetGenericData();
	    if (gdata != NULL)
			data->GetFileHeader()->GetGenericDataHdr()->AddParent(*gdata->Header().GetGenericDataHdr()); 
	    cel.Close();
	}

	// Add algorithm parameters to list.
    ParameterNameValueTypeList params;
    ParameterNameValueType param;
    
	if (programName.empty() == false)
	{
		param.SetName(L"program-name");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programName));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	if (programVersion.empty() == false)
	{
		param.SetName(L"program-version");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programVersion));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	if (programCompany.empty() == false)
	{
		param.SetName(L"program-company");
		param.SetValueText(StringUtils::ConvertMBSToWCS(programCompany));
		data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	int nparams = (int) extraNames.size();
	for(int iparam=0; iparam<nparams; iparam++)
	{
		param.SetName(StringUtils::ConvertMBSToWCS(extraNames[iparam]));
        param.SetValueAscii(extraValues[iparam]);
        data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
	}

	nparams = (int) paramNames.size();
	param.SetName(L"exec-guid");
	param.SetValueAscii(execId);
	params.push_back(param);
	for(int iparam=0; iparam<nparams; iparam++)
	{
		param.SetName(StringUtils::ConvertMBSToWCS(paramNames[iparam]));
        param.SetValueAscii(paramValues[iparam]);
        params.push_back(param);
	}
	if (params.empty() == false)
		data->AddAlgParams(params);

	params.clear();
	nparams = (int) sumNames.size();
	for(int iparam=0; iparam<nparams; iparam++)
	{
		param.SetName(StringUtils::ConvertMBSToWCS(sumNames[iparam]));
        param.SetValueAscii(sumValues[iparam]);
        params.push_back(param);
	}
	if (params.empty() == false)
		data->AddSummaryParams(params);

	// Creating the writer object will create the file with the header information.
	CHPMultiDataFileWriter writer(*data);
}