예제 #1
0
void CDFData::SetUInt32ToGenericHdr(const std::wstring& name, u_int32_t value)
{
	ParameterNameValueType paramType;
	paramType.SetName(name);
	paramType.SetValueUInt32(value);
	GenericDataHeader* hdr = genericData.Header().GetGenericDataHdr();
	hdr->AddNameValParam(paramType);
}
/** 
 * 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;
}
예제 #3
0
void CalvinCHPMultiDataFileUpdaterTest::CreateReferenceFile2()
{
	CHPMultiDataData data(TEST2_FILE);
    vector<ColumnInfo> cols;
    ParameterNameValueType nv;

    ByteColumn bcol(L"byte");
    cols.push_back(bcol);

    UByteColumn ubcol(L"ubyte");
    cols.push_back(ubcol);

    ShortColumn scol(L"short");
    cols.push_back(scol);

    UShortColumn uscol(L"ushort");
    cols.push_back(uscol);

    IntColumn icol(L"int");
    cols.push_back(icol);

    UIntColumn uicol(L"uint");
    cols.push_back(uicol);

    FloatColumn fcol(L"float");
    cols.push_back(fcol);

    ASCIIColumn acol(L"ascii", 7);
    cols.push_back(acol);

    UnicodeColumn tcol(L"text", 10);
    cols.push_back(tcol);


	ProbeSetMultiDataGenotypeData e;
	data.SetEntryCount(GenotypeMultiDataType, 4, 10, cols);
	CHPMultiDataFileWriter *writer = new CHPMultiDataFileWriter(data);

    nv.SetName(L"byte");
    nv.SetValueInt8(8);
    e.metrics.push_back(nv);
    nv.SetName(L"ubyte");
    nv.SetValueUInt8(8);
    e.metrics.push_back(nv);

    nv.SetName(L"short");
    nv.SetValueInt16(16);
    e.metrics.push_back(nv);
    nv.SetName(L"ushort");
    nv.SetValueUInt16(16);
    e.metrics.push_back(nv);

    nv.SetName(L"int");
    nv.SetValueInt32(32);
    e.metrics.push_back(nv);
    nv.SetName(L"uint");
    nv.SetValueUInt32(32);
    e.metrics.push_back(nv);

    nv.SetName(L"float");
    nv.SetValueFloat(44.0f);
    e.metrics.push_back(nv);

    nv.SetName(L"ascii");
    nv.SetValueAscii("ascii");
    e.metrics.push_back(nv);

    nv.SetName(L"text");
    nv.SetValueText(L"text");
    e.metrics.push_back(nv);


	writer->SeekToDataSet(GenotypeMultiDataType);
	e.name = "1";
    e.call = 1;
    e.confidence = 10.0f;
	writer->WriteEntry(e);
	e.name = "2";
    e.call = 2;
    e.confidence = 20.0f;
	writer->WriteEntry(e);
	e.name = "3";
    e.call = 3;
    e.confidence = 30.0f;
	writer->WriteEntry(e);
	e.name = "4";
    e.call = 4;
    e.confidence = 40.0f;
	writer->WriteEntry(e);

	delete writer;
}
예제 #4
0
void CalvinCHPMultiDataFileUpdaterTest::CreateReferenceFile3()
{
	CHPMultiDataData data(TEST3_FILE);
    vector<ColumnInfo> cols;
    ParameterNameValueType nv;

    ByteColumn bcol(L"byte");
    cols.push_back(bcol);

    UByteColumn ubcol(L"ubyte");
    cols.push_back(ubcol);

    ShortColumn scol(L"short");
    cols.push_back(scol);

    UShortColumn uscol(L"ushort");
    cols.push_back(uscol);

    IntColumn icol(L"int");
    cols.push_back(icol);

    UIntColumn uicol(L"uint");
    cols.push_back(uicol);

    FloatColumn fcol(L"float");
    cols.push_back(fcol);

    ASCIIColumn acol(L"ascii", 7);
    cols.push_back(acol);

    UnicodeColumn tcol(L"text", 10);
    cols.push_back(tcol);


	ProbeSetMultiDataCopyNumberData e;
	ProbeSetMultiDataCytoRegionData c;
	data.SetEntryCount(CopyNumberMultiDataType, 4, 10, cols);
	data.SetEntryCount(CytoMultiDataType, 2, 10);
	CHPMultiDataFileWriter *writer = new CHPMultiDataFileWriter(data);

    nv.SetName(L"byte");
    nv.SetValueInt8(8);
    e.metrics.push_back(nv);
    nv.SetName(L"ubyte");
    nv.SetValueUInt8(8);
    e.metrics.push_back(nv);

    nv.SetName(L"short");
    nv.SetValueInt16(16);
    e.metrics.push_back(nv);
    nv.SetName(L"ushort");
    nv.SetValueUInt16(16);
    e.metrics.push_back(nv);

    nv.SetName(L"int");
    nv.SetValueInt32(32);
    e.metrics.push_back(nv);
    nv.SetName(L"uint");
    nv.SetValueUInt32(32);
    e.metrics.push_back(nv);

    nv.SetName(L"float");
    nv.SetValueFloat(44.0f);
    e.metrics.push_back(nv);

    nv.SetName(L"ascii");
    nv.SetValueAscii("ascii");
    e.metrics.push_back(nv);

    nv.SetName(L"text");
    nv.SetValueText(L"text");
    e.metrics.push_back(nv);


	writer->SeekToDataSet(CopyNumberMultiDataType);
	e.name = "1";
    e.chr = 1;
    e.position = 10;
	writer->WriteEntry(e);
	e.name = "2";
    e.chr = 2;
    e.position = 20;
	writer->WriteEntry(e);
	e.name = "3";
    e.chr = 3;
    e.position = 30;
	writer->WriteEntry(e);
	e.name = "4";
    e.chr = 4;
    e.position = 40;
	writer->WriteEntry(e);

	writer->SeekToDataSet(CytoMultiDataType);
	c.name = "1";
    c.chr= 1;
    c.startPosition = 1;
    c.stopPosition = 2;
    c.call = 1;
    c.confidenceScore = 10.0f;
	writer->WriteEntry(c);
	c.name = "2";
    c.chr= 2;
    c.startPosition = 2;
    c.stopPosition = 3;
    c.call = 2;
    c.confidenceScore = 20.0f;
	writer->WriteEntry(c);

	delete writer;
}