예제 #1
0
void PeakelGrower_Proximity::sowPeak(PeakelField& peakelField, const Peak& peak) const
{
    vector<PeakelPtr> candidates = peakelField.find(peak.mz, config_.mzTolerance,
        RTMatches_Contains<Peakel>(peak.retentionTime, config_.rtTolerance));

    if (candidates.empty())
        insertNewPeakel(peakelField, peak);
    else if (candidates.size() == 1)
        updatePeakel(*candidates.front(), peak);
    else
    {
        if (config_.log)
        {
            *config_.log << "[PeakelGrower_Proximity::sowPeak()] Warning: multiple candidate peakels.\n"
                 << "  peak: " << peak
                 << "  candidates: " << candidates.size() << endl;
            for (vector<PeakelPtr>::const_iterator it=candidates.begin(); it!=candidates.end(); ++it)
                *config_.log << **it << endl;
            *config_.log << endl;
        }
    }
}
예제 #2
0
void testPeakelField()
{
    if (os_) *os_ << "testPeakelField()\n";

    PeakelPtr a(new Peakel(Peak(1.0, 1.0)));
    PeakelPtr b(new Peakel(Peak(2.0, 1.0)));
    PeakelPtr c(new Peakel(Peak(1.0, 2.0)));

    PeakelField pf;

    pf.insert(a);
    pf.insert(b);
    pf.insert(c);

    if (os_) *os_ << pf << endl;

    unit_assert(pf.size() == 3);

    PeakelField::const_iterator it = pf.begin();
    unit_assert(*it == a);

    // note that std::set allows only const access
    // however, we can modify **it
    (*it)->peaks.push_back(Peak()); 
    (*it)->peaks.clear();

    ++it;
    unit_assert(*it == c);

    ++it;
    unit_assert(*it == b);

    // find()

    if (os_) *os_ << "testPeakelField(): find()\n";

    vector<PeakelPtr> v = pf.find(1.5, .6, RTMatches_Contains<Peakel>(1, .5));

    if (os_) 
    {
        *os_ << "find(): " << v.size() << endl;
        for (vector<PeakelPtr>::const_iterator it=v.begin(); it!=v.end(); ++it)
            *os_ << **it << endl;
    }

    unit_assert(v.size()==2 && v[0]==a && v[1]==b);
    v = pf.find(1.5, .4, RTMatches_Contains<Peakel>(1, .5));
    unit_assert(v.empty());
    v = pf.find(2, .1, RTMatches_Contains<Peakel>(1, .1));
    unit_assert(v.size()==1 && v[0]==b);

    MZTolerance fiveppm(5, MZTolerance::PPM);
    v = pf.find(1.000001, fiveppm, RTMatches_Contains<Peakel>(1, 10));
    unit_assert(v.size()==2 && v[0]==a && v[1]==c);
    v = pf.find(1.000006, fiveppm, RTMatches_Contains<Peakel>(1, 10));
    unit_assert(v.empty());

    // remove()

    if (os_) *os_ << "testPeakelField(): remove()\n";

    pf.remove(a); 
    unit_assert(pf.size() == 2);
    it = pf.begin();
    unit_assert(*it == c);
    ++it; 
    unit_assert(*it == b);

    bool caught = false;
    try { 
        pf.remove(a); 
    }
    catch (exception& e) {
        if (os_) *os_ << "Caught exception correctly: " << e.what() << endl;
        caught = true; 
    }
    unit_assert(caught);

    pf.remove(b);
    unit_assert(pf.size() == 1);
    it = pf.begin();
    unit_assert(*it == c);

    pf.remove(c);
    unit_assert(pf.empty());

    if (os_) *os_ << endl;
}