Exemplo n.º 1
0
void testMetadata(MSDataCache& cache)
{
    if (os_) *os_ << "testMetadata()\n";

    if (os_) *os_ << "spectrumCount: " << cache.size() << endl;
    unit_assert(cache.size() == 5);

    unit_assert(cache[0].index == 0);
    unit_assert(cache[0].id == "scan=19");
    unit_assert(cache[0].scanNumber == 19); // TODO: change to nativeID 
    unit_assert(cache[0].massAnalyzerType == MS_QIT);
    unit_assert(cache[0].msLevel == 1);
    unit_assert_equal(cache[0].retentionTime, 353.43, epsilon_);
    unit_assert_equal(cache[0].mzLow, 400.39, epsilon_);
    unit_assert_equal(cache[0].mzHigh, 1795.56, epsilon_);
    unit_assert(cache[0].precursors.empty());

    unit_assert(cache[1].index == 1);
    unit_assert(cache[1].id == "scan=20");
    unit_assert(cache[1].scanNumber == 20); // TODO:  change to nativeID
    unit_assert(cache[1].massAnalyzerType == MS_QIT);
    unit_assert(cache[1].msLevel == 2);
    unit_assert_equal(cache[1].retentionTime, 359.43, epsilon_);
    unit_assert_equal(cache[1].mzLow, 320.39, epsilon_);
    unit_assert_equal(cache[1].mzHigh, 1003.56, epsilon_);
    unit_assert(cache[1].precursors.size() == 1);
    unit_assert(cache[1].precursors[0].index == 0);
    unit_assert_equal(cache[1].precursors[0].mz, 445.34, epsilon_);
    unit_assert_equal(cache[1].precursors[0].intensity, 120053, epsilon_);
    unit_assert(cache[1].precursors[0].charge == 2);

    if (os_) *os_ << endl;
}
Exemplo n.º 2
0
void printCache(ostream& os, const MSDataCache& cache)
{
    os << "cached binary data:\n";
    for (vector<SpectrumInfo>::const_iterator it=cache.begin(); it!=cache.end(); ++it) 
    {
        os << it->index << " " 
           << it->data.size() << "/"
           << it->data.capacity() << endl;
    }
    os << endl;
}
Exemplo n.º 3
0
void testAutomaticUpdate()
{
    if (os_) *os_ << "testAutomaticUpdate()\n";

    vector<MZIntensityPair> pairs(100);

    SpectrumListSimplePtr sl(new SpectrumListSimple);
    for (size_t i=0; i<10; i++)
    {
        SpectrumPtr spectrum(new Spectrum);
        spectrum->setMZIntensityPairs(pairs, MS_number_of_detector_counts);
        spectrum->index = i;
        spectrum->id = "scan=" + lexical_cast<string>(i);
        sl->spectra.push_back(spectrum);
    }

    MSData msd;
    msd.run.spectrumListPtr = sl;

    MSDataCache cache;
    cache.open(msd);

    unit_assert(cache.size() == sl->size());
    for (size_t i=0; i<cache.size(); i++)
        unit_assert(cache[i].index == (size_t)-1);

    const SpectrumInfo& info5 = cache.spectrumInfo(5, true);
    unit_assert(cache[5].data.size() == 100);

    cache.spectrumInfo(7); // getBinaryData==false -> doesn't change cached binary data
    unit_assert(cache[5].data.size() == 100);
    unit_assert(cache[7].data.size() == 0);

    const SpectrumInfo& info7 = cache.spectrumInfo(7, true);

    if (os_)
    {
        for (size_t i=0; i<cache.size(); i++)
            *os_ << i << " " << cache[i].index << " " << cache[i].id << " "
                 << cache[i].data.size() << endl;
    }     

    unit_assert(info7.data.size() == 100);
    unit_assert(info5.data.size() == 0);

    unit_assert(info5.index==5 && info5.id=="scan=5");
    unit_assert(cache[5].index==5 && cache[5].id=="scan=5");
    unit_assert(info7.index==7 && info7.id=="scan=7");
    unit_assert(cache[7].index==7 && cache[7].id=="scan=7");

    for (size_t i=0; i<cache.size(); i++)
        if (i!=5 && i!=7)
            unit_assert(cache[i].index == (size_t)-1);
}
Exemplo n.º 4
0
void testDefault()
{
    MSData tiny;
    examples::initializeTiny(tiny);

    MSDataCache cache;

    cache.open(tiny);

    cache.update(tiny, *tiny.run.spectrumListPtr->spectrum(0));
    unit_assert(!cache[0].data.empty());
    unit_assert(cache[1].data.empty());

    cache.update(tiny, *tiny.run.spectrumListPtr->spectrum(1));
    unit_assert(cache[0].data.empty());
    unit_assert(!cache[1].data.empty());

    testMetadata(cache);
}
void FeatureDetectorSimple::Impl::detect(const MSData& msd, FeatureField& detected) const 
{   
    // initialize buffer maps    
    map<FeatureKey, FeatureID> grandparentBuffer;
    map<FeatureKey, FeatureID> parentBuffer;

    map<FeatureID, FeaturePtr> featureMap;
    size_t featureCount = 0;

    MSDataCache cache;
    cache.open(msd);
   
    for(size_t spectrum_index = 0; spectrum_index < cache.size(); spectrum_index ++) 
    {
   
        map<FeatureKey, FeatureID> buffer;
        const SpectrumInfo info = cache.spectrumInfo(spectrum_index, true); //getBinaryData ? 
        // if info.PrecursorInfo ? 
        // call peak family detector on each scan
      
        vector<MZIntensityPair> mzIntensityPairs = info.data;       

        vector<PeakFamily> result;
                
        if (info.massAnalyzerType != MS_FT_ICR && info.massAnalyzerType != MS_orbitrap)
            {
               cerr << "Skipping non-FT scan number " << info.scanNumber << endl;
               continue;

            }
      
        _pfd->detect(mzIntensityPairs,result);

        // iterate thru peak families

        vector<PeakFamily>::iterator result_it = result.begin();
        double rt = info.retentionTime;
        int id = info.scanNumber;

        for(; result_it != result.end(); ++result_it)
            {
               
                // set ID attribute
                for_each(result_it->peaks.begin(), result_it->peaks.end(), SetID(id));

                // set RT attribute
                for_each(result_it->peaks.begin(), result_it->peaks.end(), SetRT(rt));
                
                // make keys for search
                FeatureKey featureKey(floor(result_it->mzMonoisotopic*100)/100, result_it->charge, result_it->peaks.size()); // no digits past 10e-3
                map<FeatureKey,FeatureID>::iterator grandparentLocation = grandparentBuffer.find(featureKey);
                map<FeatureKey,FeatureID>::iterator parentLocation = parentBuffer.find(featureKey);
                

                if ( parentLocation == parentBuffer.end() && grandparentLocation == grandparentBuffer.end())
                    {   
                       
                        // feature doesn't exist, make new feature
                        
                        FeatureID featureID = boost::lexical_cast<string>(++featureCount);
                        FeaturePtr feature(makeFeature(*result_it,featureID));
                       
                        featureMap.insert(pair<FeatureID, FeaturePtr>(featureID, feature));                               buffer.insert(pair<FeatureKey, FeatureID>(featureKey, featureID));
                                        

                    }

                else
                    {                      
                      // if parent location update from parent
                        FeatureID foundID;

                        if ( parentLocation != parentBuffer.end() ) foundID = parentLocation->second;
                        else foundID = grandparentLocation->second;
                        
                        // update existing feature
                        updateFeature(*result_it, featureMap[foundID]);
                        buffer.insert(pair<FeatureKey, FeatureID>(featureKey,foundID));

                    }
                   
            }

        // old buffer map := new buffer map
        //  bufferMap.swap(updatedBufferMap);

        grandparentBuffer.swap(parentBuffer);
        parentBuffer.swap(buffer);

    }
 
    // write output vector<Feature>
    map<FeatureID, FeaturePtr>::iterator the_it = featureMap.begin();
    for(; the_it != featureMap.end(); ++the_it)
        {
            if(the_it->second->peakels.front()->peaks.size()>1) // for now only write features lasting > 1 scan
                {
                    the_it->second->calculateMetadata();
                    detected.insert(the_it->second);
                }
        }
    
    return; 
}