public PeakList <Peak> Process(PeakList <Peak> t) { if (t.Count == 0) { return(t); } t.SortByMz(); List <Peak> final = new List <Peak>(); List <Peak> kept = new List <Peak>(); double minMz = 0; double lastMz = t.Last().Mz; int index = 0; while (index < t.Count) { var maxMz = minMz + 100; kept.Clear(); while (index < t.Count) { if (t[index].Mz > maxMz) { break; } kept.Add(t[index]); index++; } if (kept.Count > count) { kept.Sort((m1, m2) => m2.Intensity.CompareTo(m1.Intensity)); kept.RemoveRange(count, kept.Count - count); } final.AddRange(kept); minMz += 100; } t.Clear(); t.AddRange(final); return(t); }
public List <PeakList <T> > GetEnvelopes(double ppmTolerance) { var tmp = new PeakList <T>(this); var result = new List <PeakList <T> >(); while (tmp.Count > 0) { double mzTolerance = 2 * PrecursorUtils.ppm2mz(tmp[0].Mz, ppmTolerance); PeakList <T> envelope = tmp.FindEnvelope(tmp[0], mzTolerance, true); result.Add(envelope); foreach (T peak in envelope) { //Remove all peaks around current peak PeakList <T> findPeaks = tmp.FindPeak(peak.Mz, peak.Charge, mzTolerance); foreach (T findPeak in findPeaks) { tmp.Remove(findPeak); } } } result.Sort(new PeakListMzAscendingComparer <T>()); int current = 0; while (current < result.Count - 1) { PeakList <T> currentPkl = result[current]; if (currentPkl[0].Charge > 0) { double expectMz = currentPkl[currentPkl.Count - 1].Mz + ChargeDeconvolution.C_GAP / currentPkl[0].Charge; double mzTolerance = 4 * PrecursorUtils.ppm2mz(currentPkl[0].Mz, ppmTolerance); int next = current + 1; while (next < result.Count) { double gap = result[next][0].Mz - expectMz; if (gap >= 2.0) { break; } if (Math.Abs(gap) > mzTolerance) { next++; continue; } if (result[next][0].Charge != currentPkl[0].Charge) { next++; continue; } currentPkl.AddRange(result[next]); result.RemoveAt(next); } } current++; } return(result); }