Exemplo n.º 1
0
void CHPMultiDataDataTest::test_SumParams()
{
	ParameterNameValueTypeList params;
	ParameterNameValueType param;
	CHPMultiDataData data;

	param.SetName(L"n1");
	param.SetValueText(L"v1");
	params.push_back(param);

	param.SetName(L"n2");
	param.SetValueText(L"v2");
	params.push_back(param);

	data.AddSummaryParams(params);

	ParameterNameValueTypeList params_out = data.GetSummaryParams();
	CPPUNIT_ASSERT(params_out.size() == 2);
	ParameterNameValueTypeList::iterator it = params_out.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"n1");
	CPPUNIT_ASSERT(param.GetValueText() == L"v1");
	++it;
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"n2");
	CPPUNIT_ASSERT(param.GetValueText() == L"v2");

}
void CHPQuantificationDataTest::test_AlgParams()
{
	ParameterNameValueTypeList params;
	ParameterNameValueType param;
	CHPQuantificationData data;

	param.SetName(L"n1");
	param.SetValueText(L"v1");
	params.push_back(param);

	param.SetName(L"n2");
	param.SetValueText(L"v2");
	params.push_back(param);

	data.AddAlgParams(params);

	ParameterNameValueTypeList params_out = data.GetAlgParams();
	CPPUNIT_ASSERT(params_out.size() == 2);
	ParameterNameValueTypeList::iterator it = params_out.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"n1");
	CPPUNIT_ASSERT(param.GetValueText() == L"v1");
	++it;
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"n2");
	CPPUNIT_ASSERT(param.GetValueText() == L"v2");

}
void CHPMultiDataData::AddAppMetaInfo(const ParameterNameValueTypeList& params)
{
	ParameterNameValueType param;
	GenericDataHeader* hdr = genericData.Header().GetGenericDataHdr();
	for (ParameterNameValueTypeList::const_iterator it=params.begin(); it != params.end(); ++it)
	{
		param = *it;
		param.SetName(APPLICATION_META_INFO_PREFIX_S + param.GetName());
		hdr->AddNameValParam(param);
	}
}
void CHPMultiDataData::AddAlgParams(const ParameterNameValueTypeList& params)
{
	ParameterNameValueType param;
	GenericDataHeader* hdr = genericData.Header().GetGenericDataHdr();
	for (ParameterNameValueTypeList::const_iterator it=params.begin(); it != params.end(); it++)
	{
		param = *it;
		param.SetName(ALGORITHM_PARAM_NAME_PREFIX_S + param.GetName());
		hdr->AddNameValParam(param);
	}
}
Exemplo n.º 5
0
void CHPQuantificationData::AddSummaryParams(const ParameterNameValueTypeList& params)
{
	ParameterNameValueType param;
	GenericDataHeader* hdr = genericData.Header().GetGenericDataHdr();
	for (ParameterNameValueTypeList::const_iterator it=params.begin(); it != params.end(); it++)
	{
		param = *it;
		param.SetName(CHIP_SUMMARY_PARAMETER_NAME_PREFIX_S + param.GetName());
		hdr->AddNameValParam(param);
	}
}
void CHPMultiDataFileReaderTest::testReadCNV()
{
    affymetrix_calvin_data::ProbeSetMultiDataCopyNumberVariationRegionData e;
	ParameterNameValueType param;

    CHPMultiDataData data2;
	CHPMultiDataFileReader reader;
	reader.SetFilename("../data/CHP_MultiData_file_cnv");
	reader.Read(data2);
  
	CPPUNIT_ASSERT(data2.GetAlgName() == L"canary");
	CPPUNIT_ASSERT(data2.GetAlgVersion() == L"1.0");
	CPPUNIT_ASSERT(data2.GetArrayType() == L"test3");
    CPPUNIT_ASSERT(data2.GetEntryCount(CopyNumberVariationMultiDataType) == 2);
	CPPUNIT_ASSERT(data2.GetEntryCount(CopyNumberMultiDataType) == 0);
	CPPUNIT_ASSERT(data2.GetEntryCount(GenotypeMultiDataType) == 0);
	CPPUNIT_ASSERT(data2.GetEntryCount(ExpressionMultiDataType) == 0);

	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.GetCopyNumberVariationEntry(CopyNumberVariationMultiDataType, 0, e);
	CPPUNIT_ASSERT(e.call == 1);
	CPPUNIT_ASSERT(e.name == "abc");
    CPPUNIT_ASSERT_DOUBLES_EQUAL(e.confidenceScore, 1.1f, 0.0001f);
    CPPUNIT_ASSERT(e.signal == 100);
	data2.GetCopyNumberVariationEntry(CopyNumberVariationMultiDataType, 1, e);
	CPPUNIT_ASSERT(e.call == 2);
	CPPUNIT_ASSERT(e.name == "xyz");
    CPPUNIT_ASSERT_DOUBLES_EQUAL(e.confidenceScore, 2.2, 0.0001f);
    CPPUNIT_ASSERT(e.signal == 200);
}
ParameterNameValueTypeList CHPMultiDataData::GetAlgParams()
{
	ParameterNameValueTypeList nvt;
	ParameterNameValueTypeIt begin, end;
	ParameterNameValueType param;

	genericData.Header().GetGenericDataHdr()->GetNameValIterators(begin, end);
	while(begin != end)
	{
		std::wstring key = begin->GetName();
		if(key.compare(0, ALGORITHM_PARAM_NAME_PREFIX_S.size(),ALGORITHM_PARAM_NAME_PREFIX_S) == 0)
		{
			param = *begin;
			key.erase(0, ALGORITHM_PARAM_NAME_PREFIX_S.size());
			param.SetName(key);
			nvt.push_back(param);
		}
		begin++;
	}
	return nvt;
}
Exemplo n.º 8
0
ParameterNameValueTypeList CHPQuantificationData::GetSummaryParams()
{
	ParameterNameValueTypeList nvt;
	ParameterNameValueTypeIt begin, end;
	ParameterNameValueType param;

	genericData.Header().GetGenericDataHdr()->GetNameValIterators(begin, end);
	while(begin != end)
	{
		std::wstring key = begin->GetName();
		if(key.compare(0, CHIP_SUMMARY_PARAMETER_NAME_PREFIX_S.size(),CHIP_SUMMARY_PARAMETER_NAME_PREFIX_S) == 0)
		{
			param = *begin;
			key.erase(0, CHIP_SUMMARY_PARAMETER_NAME_PREFIX_S.size());
			param.SetName(key);
			nvt.push_back(param);
		}
		begin++;
	}
	return nvt;
}
Exemplo n.º 9
0
void CHPQuantificationDetectionFileReaderTest::testReadId()
{
    CHPQuantificationDetectionData data;
    CHPQuantificationDetectionFileReader reader;
    CPPUNIT_ASSERT_NO_THROW(reader.SetFilename("../data/CHP_quantification_detection_file_id"));
    CPPUNIT_ASSERT_NO_THROW(reader.Read(data));

    CPPUNIT_ASSERT(data.GetFilename() == "../data/CHP_quantification_detection_file_id");
    CPPUNIT_ASSERT(data.GetAlgName() == L"sig");
    CPPUNIT_ASSERT(data.GetAlgVersion() == L"1.0");
    CPPUNIT_ASSERT(data.GetArrayType() == L"test3");
    CPPUNIT_ASSERT(data.GetEntryCount() == 2);

    ParameterNameValueTypeList params = data.GetAlgParams();
    CPPUNIT_ASSERT(params.size() == 1);
    ParameterNameValueTypeList::iterator it=params.begin();
    ParameterNameValueType param = *it;
    CPPUNIT_ASSERT(param.GetName() == L"an1");
    CPPUNIT_ASSERT(param.GetValueText() == L"av1");

    params = data.GetSummaryParams();
    CPPUNIT_ASSERT(params.size() == 1);
    it=params.begin();
    param = *it;
    CPPUNIT_ASSERT(param.GetName() == L"sn1");
    CPPUNIT_ASSERT(param.GetValueText() == L"sv1");

    ProbeSetQuantificationDetectionData e;
    data.GetQuantificationDetectionEntry(0, e);
    CPPUNIT_ASSERT(e.id == 10);
    CPPUNIT_ASSERT(e.quantification == 10.0f);
    CPPUNIT_ASSERT(e.pvalue == 0.1f);
    CPPUNIT_ASSERT(e.name == "");
    data.GetQuantificationDetectionEntry(1, e);
    CPPUNIT_ASSERT(e.id == 20);
    CPPUNIT_ASSERT(e.quantification == 20.0f);
    CPPUNIT_ASSERT(e.pvalue == 0.2f);
    CPPUNIT_ASSERT(e.name == "");
}
Exemplo n.º 10
0
void FusionCHPQuantificationDataTest::testRead()
{
	FusionCHPData *chp = FusionCHPDataReg::Read("../../parsers/data/CHP_quantification_file");
	CPPUNIT_ASSERT(chp != NULL);
	FusionCHPQuantificationData *sigChp = FusionCHPQuantificationData::FromBase(chp); 
	CPPUNIT_ASSERT(sigChp != NULL);

	CPPUNIT_ASSERT(sigChp->GetAlgName() == L"sig");
	CPPUNIT_ASSERT(sigChp->GetAlgVersion() == L"1.0");
	CPPUNIT_ASSERT(sigChp->GetArrayType() == L"test3");
	CPPUNIT_ASSERT(sigChp->GetEntryCount() == 2);
	
	ParameterNameValueTypeList params = sigChp->GetAlgParams();
	CPPUNIT_ASSERT(params.size() == 1);
	ParameterNameValueTypeList::iterator it=params.begin();
	ParameterNameValueType &param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"an1");
	CPPUNIT_ASSERT(param.GetValueText() == L"av1");

	params = sigChp->GetSummaryParams();
	CPPUNIT_ASSERT(params.size() == 1);
	it=params.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"sn1");
	CPPUNIT_ASSERT(param.GetValueText() == L"sv1");

	affymetrix_calvin_data::ProbeSetQuantificationData e;
	sigChp->GetQuantificationEntry(0, e);
	CPPUNIT_ASSERT(e.name == "abc");
    CPPUNIT_ASSERT(e.quantification == 10.0f);
	sigChp->GetQuantificationEntry(1, e);
	CPPUNIT_ASSERT(e.name == "xyz");
	CPPUNIT_ASSERT(e.quantification == 20.0f);

	
	delete sigChp;
}
void CHPMultiDataFileReaderTest::testReadCN()
{
   	affymetrix_calvin_data::ProbeSetMultiDataCopyNumberData e;
	ParameterNameValueType param;
	CHPMultiDataData data2;
	CHPMultiDataFileReader reader;
	reader.SetFilename("../data/CHP_MultiData_file_cn");
	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(CopyNumberMultiDataType) == 2);
	CPPUNIT_ASSERT(data2.GetEntryCount(GenotypeMultiDataType) == 0);
	CPPUNIT_ASSERT(data2.GetEntryCount(ExpressionMultiDataType) == 0);

	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.GetCopyNumberEntry(CopyNumberMultiDataType, 0, e);
	CPPUNIT_ASSERT(e.chr == 10);
	CPPUNIT_ASSERT(e.position == 11);
	CPPUNIT_ASSERT(e.name == "abc");
	data2.GetCopyNumberEntry(CopyNumberMultiDataType, 1, e);
	CPPUNIT_ASSERT(e.chr == 20);
	CPPUNIT_ASSERT(e.position == 21);
	CPPUNIT_ASSERT(e.name == "xyz");
}
/** 
 * Get set up for a run of reporting probesets. Often used to open file
 * streams and print headers to files etc.
 * 
 * @param qMethod - Quantification method to be used.
 * @param layout - Where the probesets, probes, etc are on the chip.
 * 
 * @return true if success, false otherwise.
 */
bool QuantMethodExprCCCHPReport::prepare(QuantMethod &qMethod, const IntensityMart &iMart) 
{
    QuantExprMethod *eMethod = dynamic_cast<QuantExprMethod *>(&qMethod);
    if (eMethod == NULL) { Err::errAbort("Can only use a QuantMethodExprReport with a QuantExprMethod."); }
    
    setupFileNames(iMart);
    int nfiles = m_CHPFileNames.size();
    
    // Make sure our output directory exists.
    if (!Fs::isWriteableDir(m_Prefix.c_str()) &&
        (Fs::mkdirPath(m_Prefix, false) != APT_OK)) {
        APT_ERR_ABORT("Can't make or write to directory: " + m_Prefix);
    }
    
    removeAllChps();
    
    // Get CEL file GUIDs
    ///@todo This be computed by the engine and passed in via AnalysisInfo
    m_celGuids.resize(nfiles);
    std::string tmp_unc_name;
    for (int chip=0; chip<nfiles; chip++) {
        FusionCELData cel;
        try {
            tmp_unc_name=Fs::convertToUncPath(m_CELFileNames[chip]);
            cel.SetFileName(tmp_unc_name.c_str());
            if (!cel.ReadHeader()) {
                Err::errAbort("Unable to read CEL file: "+FS_QUOTE_PATH(tmp_unc_name));
            }
            GenericData *gdata = cel.GetGenericData();
            if (gdata != NULL) {
                m_celGuids[chip] = gdata->Header().GetGenericDataHdr()->GetFileId();
            }
            cel.Close();
        }
        catch (...) {
            Err::errAbort("Unable to read CEL file " + tmp_unc_name);
        }
    }

    int maxProbeSetNameLength = 0;
    for (int i=0; i<m_Info.m_ProbesetNames.size(); i++) {
        int len = (int)strlen(m_Info.m_ProbesetNames.at(i));
        if (m_Info.m_ProbesetDisplayNames.size() > 0 && m_Info.m_ProbesetDisplayNames.at(i) != NULL)
            len = (int)strlen(m_Info.m_ProbesetDisplayNames.at(i));
        maxProbeSetNameLength = Max(maxProbeSetNameLength, len);
    }

    // Prepare headers for all CHP files.
    wstring algName = StringUtils::ConvertMBSToWCS(m_Info.m_AlgName);
    wstring algVersion = StringUtils::ConvertMBSToWCS(m_Info.m_AlgVersion);
    wstring chipType = StringUtils::ConvertMBSToWCS(m_Info.m_ChipType);

    // For each chip, precreate all probeset signal entries (default to 0.0).
    Verbose::out(1,"QuantMethodExprCCCHPReport: Creating temporary files for CHP output");
    for (int chip=0; chip<nfiles; chip++) {
        try {
            ParameterNameValueType param;

            // Create tmp chp file
            std::string tmp_chp_name=m_CHPFileNames[chip] + ".tmp";
            CHPQuantificationData *data = new CHPQuantificationData(tmp_chp_name);
            m_TmpChpFiles.push_back(tmp_chp_name);

            // set parent header
            FusionCELData cel;
            try {
                tmp_unc_name=Fs::convertToUncPath(m_CELFileNames[chip]);
                cel.SetFileName(tmp_unc_name.c_str());
                if (!cel.ReadHeader()) {
                  Err::errAbort("Unable to read CEL file: "+FS_QUOTE_PATH(tmp_unc_name));
                }
                GenericData *gdata = cel.GetGenericData();
                if (gdata != NULL) {
                    data->GetFileHeader()->GetGenericDataHdr()->AddParent(*gdata->Header().GetGenericDataHdr());
                }
                cel.Close();
            }
            catch (...) {
              Err::errAbort("Unable to read CEL file: "+FS_QUOTE_PATH(tmp_unc_name));
            }

            data->SetEntryCount(m_Info.m_NumProbeSets, maxProbeSetNameLength); 
            data->SetAlgName(algName);
            data->SetAlgVersion(algVersion);
            data->SetArrayType(chipType);

            param.SetName(L"program-name");
            param.SetValueText(StringUtils::ConvertMBSToWCS(m_Info.m_ProgramName));
            data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
            param.SetName(L"program-version");
            param.SetValueText(StringUtils::ConvertMBSToWCS(m_Info.m_ProgramVersion));
            data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);
            param.SetName(L"program-company");
            param.SetValueText(StringUtils::ConvertMBSToWCS(m_Info.m_ProgramCompany));
            data->GetGenericData().Header().GetGenericDataHdr()->AddNameValParam(param);

            // Add algorithm parameters to list.
            ParameterNameValueTypeList paramList;
            assert(m_Info.m_ParamNames.size() == m_Info.m_ParamValues.size());
            for (int i=0; i<m_Info.m_ParamNames.size(); i++) {
                if (m_Info.m_ParamValues[i].length() > 0) {
                    param.SetName(StringUtils::ConvertMBSToWCS(m_Info.m_ParamNames[i]));
                    param.SetValueText(StringUtils::ConvertMBSToWCS(m_Info.m_ParamValues[i]));
                    paramList.push_back(param);
                }
            }

            // Add list of all CEL GUIDs in batch
            ///@todo should this be computed by the engine and passed in via AnalysisInfo?
            string prefix = "apt-opt-";
            for (int chip=0; chip<m_CHPFileNames.size(); chip++) {
                if (m_celGuids[chip].empty() == false) {
                    string paramName = prefix + "cel-guid-" + ToStr(chip+1);
                    param.SetName(StringUtils::ConvertMBSToWCS(paramName));
                    param.SetValueText(StringUtils::ConvertMBSToWCS(m_celGuids[chip]));
                    paramList.push_back(param);
                }
            }
            data->AddAlgParams(paramList);

            // Add the run report parameters to the list
            ParameterNameValueTypeList summaryParamList;
            std::string blankStr(256, ' ');
            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++) {
                    param.SetName(StringUtils::ConvertMBSToWCS(metricDefs[i].m_name));
                    if (metricDefs[i].m_type == ChipSummary::Metric::Double) {
                        param.SetValueFloat(-1.0);
                    } 
                    else if (metricDefs[i].m_type == ChipSummary::Metric::Integer) {
                        param.SetValueInt32(-1);
                    } 
                    else if (metricDefs[i].m_type == ChipSummary::Metric::String) {
                        param.SetValueAscii(blankStr);
                    } 
                    else {
                        Err::errAbort("QuantMethodExprCCCHPReport: Unable to handle unknown type: " + 
                                      ToStr(metricDefs[i].m_type) );
                    }
                    summaryParamList.push_back(param);
                }
            }
            data->AddSummaryParams(summaryParamList);
			
            ProbeSetQuantificationData entry;
            CHPQuantificationFileWriter writer(*data);
            writer.SeekToDataSet();        // seek to data table location
            for (int index=0; index<m_Info.m_ProbesetNames.size(); index++) {
                if (m_Info.m_ProbesetDisplayNames.size() > 0 && m_Info.m_ProbesetDisplayNames[index] != NULL)
                    entry.name = m_Info.m_ProbesetDisplayNames[index];
                else
                    entry.name = m_Info.m_ProbesetNames[index];
                entry.quantification = 0.0f;
                writer.WriteEntry(entry);
            }
            
            delete data;
        }
        catch (...) {
            Err::errAbort("QuantMethodExprCHPReport::prepare() - Unable to write header and/or precreate signal entries to file: " + m_CHPFileNames[chip] + ".tmp");
        }
    }
    
    // initialize expression signal buffer writer
    m_ExpressionQuantificationBufferWriter.Initialize(&m_TmpChpFiles);

    return true;
}
Exemplo n.º 13
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);
    }
}
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");

}
Exemplo n.º 15
0
void FusionCHPTilingDataTest::testRead()
{
	FusionCHPData *chp = FusionCHPDataReg::Read("../../parsers/data/CHP_tiling_file");
	CPPUNIT_ASSERT(chp != NULL);
	FusionCHPTilingData *tileChp = FusionCHPTilingData::FromBase(chp); 
	CPPUNIT_ASSERT(tileChp != NULL);

	CPPUNIT_ASSERT(tileChp->GetNumberSequences() == 2);
	CPPUNIT_ASSERT(tileChp->GetAlgName() == L"tile");
	CPPUNIT_ASSERT(tileChp->GetAlgVersion() == L"1.0");

	ParameterNameValueTypeList params = tileChp->GetAlgParams();
	CPPUNIT_ASSERT(params.size() == 1);
	ParameterNameValueTypeList::iterator it=params.begin();
	ParameterNameValueType &param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"p1");
	CPPUNIT_ASSERT(param.GetValueText() == L"v1");

	const double eps=0.00001;
	CHPTilingEntry e;
	TilingSequenceData seq;

	tileChp->OpenTilingSequenceDataSet(0);
	seq = tileChp->GetTilingSequenceData();
	
	CPPUNIT_ASSERT(seq.name == L"n1");
	CPPUNIT_ASSERT(seq.groupName == L"g1");
	CPPUNIT_ASSERT(seq.version == L"v1");
	CPPUNIT_ASSERT(seq.parameters.size() == 1);
	it = seq.parameters.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"seq1_p1");
	CPPUNIT_ASSERT(param.GetValueText() == L"seq1_v1");

	CPPUNIT_ASSERT(tileChp->GetTilingSequenceEntryCount(0) == 2);
	tileChp->GetTilingSequenceEntry(0, e);
	CPPUNIT_ASSERT(e.position == 10);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.value, 10.0f, eps);

	tileChp->GetTilingSequenceEntry(1, e);
	CPPUNIT_ASSERT(e.position == 20);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.value, 20.0f, eps);


	tileChp->OpenTilingSequenceDataSet(1);
	seq = tileChp->GetTilingSequenceData();
	
	CPPUNIT_ASSERT(seq.name == L"n2");
	CPPUNIT_ASSERT(seq.groupName == L"g2");
	CPPUNIT_ASSERT(seq.version == L"v2");
	CPPUNIT_ASSERT(seq.parameters.size() == 1);
	it = seq.parameters.begin();
	param = *it;
	CPPUNIT_ASSERT(param.GetName() == L"seq2_p1");
	CPPUNIT_ASSERT(param.GetValueText() == L"seq2_v1");

	CPPUNIT_ASSERT(tileChp->GetTilingSequenceEntryCount(1) == 3);
	tileChp->GetTilingSequenceEntry(0, e);
	CPPUNIT_ASSERT(e.position == 11);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.value, 11.0f, eps);

	tileChp->GetTilingSequenceEntry(1, e);
	CPPUNIT_ASSERT(e.position == 21);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.value, 21.0f, eps);

	tileChp->GetTilingSequenceEntry(2, e);
	CPPUNIT_ASSERT(e.position == 31);
	CPPUNIT_ASSERT_DOUBLES_EQUAL(e.value, 31.0f, eps);
	
	delete tileChp;
}
Exemplo n.º 16
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);
}
Exemplo n.º 17
0
/*
 * Create a results file with the CEL file header and other parameters.
 */
void CopyNumberResultWriter::CreateResultFile(affymetrix_fusion_io::FusionCELData& cel, const std::string& fileName)
{
    try
    {
        // Create the results file with the header.
        CHPMultiDataData *data = new CHPMultiDataData(fileName);
        data->SetEntryCount(CopyNumberMultiDataType, numberProbeSets, maxProbeSetNameLength[CopyNumberMultiDataType], columns);
		if (numberCytoRegions > 0)
			data->SetEntryCount(CytoMultiDataType, numberCytoRegions, maxProbeSetNameLength[CytoMultiDataType],cytoRegionColumns);
		if (numberGenotypeProbeSets > 0)
			data->SetEntryCount(GenotypeMultiDataType, numberGenotypeProbeSets, maxProbeSetNameLength[GenotypeMultiDataType], genotypeColumns);
        data->SetAlgName(StringUtils::ConvertMBSToWCS(algName));
        data->SetAlgVersion(StringUtils::ConvertMBSToWCS(algVersion));
        data->SetArrayType(cel.GetChipType());
        GenericDataHeader *gdh = data->GetFileHeader()->GetGenericDataHdr();
        ParameterNameValueType param;
        param.SetName(PROGRAM_NAME);
        param.SetValueText(StringUtils::ConvertMBSToWCS(programName));
        gdh->AddNameValParam(param);
        param.SetName(L"program-version");
        param.SetValueText(StringUtils::ConvertMBSToWCS(programVersion));
        gdh->AddNameValParam(param);
        param.SetName(PROGRAM_COMPANY);
        param.SetValueText(StringUtils::ConvertMBSToWCS(programCompany));
        gdh->AddNameValParam(param);
        ParameterNameValueTypeList params = algParams;
        param.SetName(L"ArraySet");
        param.SetValueText(cel.GetChipType());
        params.push_back(param);
        data->AddAlgParams(params);
        data->AddSummaryParams(summaryParams);
        DataSetHeader *dsh = data->GetDataSetHeader(CopyNumberMultiDataType);
        for (ParameterNameValueTypeList::iterator it=chrStartStop.begin(); it!=chrStartStop.end(); it++)
            dsh->AddNameValParam(*it);
        GenericData *gdata = cel.GetGenericData();
        if (gdata != NULL)
            gdh->AddParent(*gdata->Header().GetGenericDataHdr());
        CHPMultiDataFileWriter *writer = new CHPMultiDataFileWriter(*data);
        delete writer;
        delete data;

        // Create a buffer writer object
        outputFiles.clear();
        outputFiles.push_back(fileName);
        vector<MultiDataType> dataTypes;
        dataTypes.push_back(CopyNumberMultiDataType);
		if (numberCytoRegions > 0)
			dataTypes.push_back(CytoMultiDataType);
		if (numberGenotypeProbeSets > 0)
			dataTypes.push_back(GenotypeMultiDataType);
        bufferWriter = new CHPMultiDataFileBufferWriter();
        bufferWriter->Initialize(&outputFiles, dataTypes, maxProbeSetNameLength);
    }
    catch (CalvinException &ex)
    {
        string err = "Error creating the output file: " + fileName;
        wstring msg = ex.ToString();
        if (msg.empty() == false)
            err += " " + StringUtils::ConvertWCSToMBS(msg);
        throw err;
    }
    catch (...)
    {
        string err = "Error creating the output file: " + fileName;
        throw err;
    }
}