const bool CMSPeak::ContainsFast(const int value, const EMSPeakListTypes Which) const { int x(0), l, r; CRef <CMSPeakList> PeakList = GetPeakLists()[Which]; l = 0; r = PeakList->GetNum() - 1; while(l <= r) { x = (l + r)/2; if (PeakList->GetMZI()[x].GetMZ() < value - tol) l = x + 1; else if (PeakList->GetMZI()[x].GetMZ() > value + tol) r = x - 1; else return true; } if (x < PeakList->GetNum() - 1 && PeakList->GetMZI()[x+1].GetMZ() < value + tol && PeakList->GetMZI()[x+1].GetMZ() > value - tol) return true; return false; }
int CMSPeak::CompareSortedRank(CLadder& Ladder, EMSPeakListTypes Which, vector<bool>& usedPeaks) { int i(0), j(0); int retval(0); CRef <CMSPeakList> PeakList = SetPeakLists()[Which]; if (Ladder.size() == 0 || PeakList->GetNum() == 0) return 0; Ladder.SetM() = 0; Ladder.SetSum() = 0; do { if (PeakList->GetMZI()[j].GetMZ() < Ladder[i] - tol) { j++; if (j >= PeakList->GetNum()) break; continue; } else if (PeakList->GetMZI()[j].GetMZ() > Ladder[i] + tol) { i++; if (i >= Ladder.size()) break; continue; } else { // avoid double count if (!usedPeaks[j]) { usedPeaks[j] = true; Ladder.GetHit()[i] = Ladder.GetHit()[i] + 1; // sum up the ranks Ladder.SetSum() += PeakList->GetMZI()[j].GetRank(); Ladder.SetM()++; } retval++; // record the intensity for scoring Ladder.SetIntensity()[i] = PeakList->GetMZI()[j].GetIntensity(); Ladder.SetDelta()[i] = PeakList->GetMZI()[j].GetMZ() - Ladder[i]; j++; if (j >= PeakList->GetNum()) break; i++; if (i >= Ladder.size()) break; } } while (true); return retval; }
const bool CMSPeak::CompareTop(CLadder& Ladder) { int i; CRef <CMSPeakList> PeakList = SetPeakLists()[eMSPeakListTop]; for(i = 0; i < PeakList->GetNum(); i++) { // cout << PeakList->GetMZI()[i].GetMZ() << " tol " << tol << endl; if(Ladder.ContainsFast(PeakList->GetMZI()[i].GetMZ(), tol)) return true; } return false; }