bool FusionCHPMultiDataAccessor::Initialize(const vector<string> &chps)
{
    // Clear the map
    snpNameIndexMap.clear();

    // Store the chp file names.
    chpFileNames = chps;
    if (chps.size() == 0)
        return false;

    // Read the first chp file.
    FusionCHPData *chp = FusionCHPDataReg::Read(chpFileNames[0]);
    if (chp == NULL)
        return false;
    FusionCHPMultiDataData *mchp = FusionCHPMultiDataData::FromBase(chp);
    if (mchp == NULL)
    {
        delete chp;
        return false;
    }

    // Extract the probe set names
    int n = mchp->GetEntryCount(GenotypeMultiDataType);
    for (int i=0; i<n; i++)
        snpNameIndexMap[mchp->GetProbeSetName(GenotypeMultiDataType, i)] = i;

    // Close the file and return
    delete mchp;
    return true;
}
void FusionCHPMultiDataAccessor::ExtractData(const vector<string> &snps, vector<vector<u_int8_t> > &calls, vector<vector<float> > &confidences)
{
    int nchps = (int)chpFileNames.size();
    calls.resize(nchps);
    confidences.resize(nchps);

    // Create a vector of CHP file indicies given the SNP names. This is
    // done to reduce the number of lookups in the map object.
    int nsnps = (int)snps.size();
    vector<int> snpIndicies(nsnps);
    for (int isnp=0; isnp<nsnps; isnp++)
    {
        snpIndicies[isnp] = snpNameIndexMap[snps[isnp]];
    }

    // Loop over the chp files and extract the snp data
    FusionCHPData *chp = NULL;
    FusionCHPMultiDataData *mchp = NULL;
    for (int ichp=0; ichp<nchps; ichp++)
    {
        // Open the CHP file
        chp = FusionCHPDataReg::Read(chpFileNames[ichp]);
        mchp = FusionCHPMultiDataData::FromBase(chp);
        if (mchp == NULL)
        {
            calls[ichp].clear();
            confidences[ichp].clear();
            delete chp;
            chp = NULL;
            mchp = NULL;
            continue;
        }

        // Extract the data
        calls[ichp].resize(nsnps);
        confidences[ichp].resize(nsnps);
        for (int isnp=0; isnp<nsnps; isnp++)
        {
            calls[ichp][isnp] = mchp->GetGenoCall(GenotypeMultiDataType, snpIndicies[isnp]);
            confidences[ichp][isnp] = mchp->GetGenoConfidence(GenotypeMultiDataType, snpIndicies[isnp]);
        }

        // Close the file
        delete mchp;
   }
}
Ejemplo n.º 3
0
void CopyNumberResultWriterTest::testWrite()
{
	CopyNumberResultWriter writer;
    const char *fileNames[] = {"test1.cn", "test2.cn"};

    list<ParameterNameValueType> algParams;
    list<ParameterNameValueType> sumParams;
    vector<ColumnInfo> cols;

    writer.MaximumProbeSetNameLength(12);
    writer.MaximumCytoRegionNameLength(12);
	writer.MaximumGenotypeProbeSetNameLength(12);
    writer.AlgName() = "MYALG";
    writer.AlgVersion() = "1.0";
    writer.NumberProbeSets() = 10;
    writer.NumberCytoRegions() = 10;
	writer.NumberGenotypeProbeSets() = 10;
    writer.Columns() = cols;
    writer.AlgParams() = algParams;
    writer.SetChromosomeProbeSetIndexInformation(X_CHR, 0, writer.NumberProbeSets());
    for (int i=0; i<2; i++)
    {
        FusionCELData cel;
        cel.SetFileName("../data/small_cel_file");
        cel.Read(false);

        writer.SummaryParams() = sumParams;
        writer.CreateResultFile(cel, fileNames[i]);
        cel.Close();

        ProbeSetMultiDataCopyNumberData entry;
        char buf[64];
        for (int j=0; j<writer.NumberProbeSets(); j++)
        {
            entry.chr = X_CHR;
            entry.position = j+i;
            snprintf(buf, 64, "%d", j+i);
            entry.name = buf;
            writer.WriteProbeSetResult(entry);
        }
        ProbeSetMultiDataCytoRegionData cy;
        for (int j=0; j<writer.NumberCytoRegions(); j++)
        {
            cy.call = 1;
            cy.confidenceScore = (float)(j+i);
            snprintf(buf, 64, "%d", j+i);
            cy.name = buf;
            writer.WriteCytoRegionResult(cy);
        }
        ProbeSetMultiDataGenotypeData gt;
        for (int j=0; j<writer.NumberGenotypeProbeSets(); j++)
        {
            gt.call = 1;
			gt.confidence = (float)(j+i);
            snprintf(buf, 64, "%d", j+i);
            gt.name = buf;
			writer.WriteGenotypeProbeSetResult(gt);
        }
        writer.CloseResultsFile();
    }

    for (int i=0; i<2; i++)
    {
        FusionCHPData *chp = FusionCHPDataReg::Read(fileNames[i]);
	    CPPUNIT_ASSERT(chp != NULL);
	    FusionCHPMultiDataData *genoChp = FusionCHPMultiDataData::FromBase(chp); 
	    CPPUNIT_ASSERT(genoChp != NULL);

	    CPPUNIT_ASSERT(genoChp->GetAlgName() == L"MYALG");
	    CPPUNIT_ASSERT(genoChp->GetAlgVersion() == L"1.0");
	    CPPUNIT_ASSERT(genoChp->GetArrayType() == L"Hg-small");
	    CPPUNIT_ASSERT(genoChp->GetEntryCount(ExpressionMultiDataType) == 0);
	    CPPUNIT_ASSERT(genoChp->GetEntryCount(GenotypeMultiDataType) == 10);
	    CPPUNIT_ASSERT(genoChp->GetEntryCount(CopyNumberMultiDataType) == 10);
	    CPPUNIT_ASSERT(genoChp->GetEntryCount(CytoMultiDataType) == 10);

        DataSetHeader *dsh = genoChp->GetDataSetHeader(CopyNumberMultiDataType);
        CPPUNIT_ASSERT(dsh->GetNameValParamCnt() == 3);
        ParameterNameValueTypeConstIt begin;
        ParameterNameValueTypeConstIt end;
        ParameterNameValueTypeConstIt it;
        dsh->GetNameValIterators(begin, end);
        it = begin;
        CPPUNIT_ASSERT(it->GetValueInt32() == 0);
        ++it;
        CPPUNIT_ASSERT(it->GetValueInt32() == 10);
        ++it;
        CPPUNIT_ASSERT(it->GetValueAscii() == "X");
        
        ProbeSetMultiDataCopyNumberData entry;
        char buf[64];
        for (int j=0; j<10; j++)
        {
            genoChp->GetCopyNumberEntry(CopyNumberMultiDataType, j, entry);
            CPPUNIT_ASSERT(entry.chr == X_CHR);
            CPPUNIT_ASSERT(entry.position == j+i);
            snprintf(buf, 64, "%d", j+i);
            CPPUNIT_ASSERT(entry.name.compare(buf) == 0);
        }

        ProbeSetMultiDataCytoRegionData cy;
        for (int j=0; j<10; j++)
        {
            genoChp->GetCytoRegionEntry(CytoMultiDataType, j, cy);
            CPPUNIT_ASSERT(cy.call == 1);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(cy.confidenceScore, j+i, 0.0001f);
            snprintf(buf, 64, "%d", j+i);
            CPPUNIT_ASSERT(cy.name.compare(buf) == 0);
        }

        ProbeSetMultiDataGenotypeData gt;
        for (int j=0; j<10; j++)
        {
            genoChp->GetGenotypeEntry(GenotypeMultiDataType, j, gt);
            CPPUNIT_ASSERT(gt.call == 1);
            CPPUNIT_ASSERT_DOUBLES_EQUAL(gt.confidence, j+i, 0.0001f);
            snprintf(buf, 64, "%d", j+i);
            CPPUNIT_ASSERT(gt.name.compare(buf) == 0);
        }

        delete chp;
    }
}