protected PeakList <T> FindEnvelope(PeakList <T> t, T peak, double mzTolerance) { IsotopicType itype = IsotopicType.NONE; var env = t.FindEnvelope(peak, mzTolerance, true); if (env.Count <= 2) { return(env); } for (int i = 1; i < env.Count; i++) { if (env[i].Intensity >= env[i - 1].Intensity) //递增 { if (itype == IsotopicType.DECREASING) //如果前面是递减,则这次递增无效。 { env.RemoveRange(i, env.Count - i); break; } } else//递减 { itype = IsotopicType.DECREASING; } } return(env); }
public static double GetPrecursorPercentage(this PeakList <Peak> isolationPeaks, double ppmTolerance) { var defaultValue = 0.0; if (isolationPeaks.Count == 0) { return(defaultValue); } //parentPkl.ForEach(m => Console.WriteLine("new Peak({0:0.0000},{1:0.0},{2}),",m.Mz, m.Intensity,m.Charge)); var totalIntensity = isolationPeaks.Sum(m => m.Intensity); if (0.0 == totalIntensity) { throw new ArgumentException("There is no intensity information in argument isolationPeaks"); } var precursorPeak = isolationPeaks.Precursor; var mzTolerance = PrecursorUtils.ppm2mz(precursorPeak.MonoIsotopicMass, ppmTolerance); if (precursorPeak.Charge == 0) { var pPeak = isolationPeaks.FindAll(m => Math.Abs(m.Mz - precursorPeak.MonoIsotopicMass) < mzTolerance); if (0 == pPeak.Count) { return(defaultValue); } var maxIntensity = pPeak.Max(m => m.Intensity); pPeak.Find(m => m.Intensity == maxIntensity).Tag = 1; return(maxIntensity / totalIntensity); } else { var pPeak = isolationPeaks.FindEnvelope(precursorPeak.MonoIsotopicMass, precursorPeak.Charge, mzTolerance, true); if (0 == pPeak.Count) { return(defaultValue); } for (int i = 0; i < pPeak.Count; i++) { pPeak[i].Tag = i + 1; } return(pPeak.GetTotalIntensity() / totalIntensity); } }
public static List <PeakList <T> > GetEnvelopes <T>(PeakList <T> pkl, double ppmTolerance) where T : IPeak { var tmp = new PeakList <T>(pkl); 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); } } } /* * Console.Out.WriteLine("---before merge"); * foreach (PeakList<T> pkl in result) * { * Console.Out.WriteLine("---"); * foreach (Peak p in pkl) * { * Console.Out.WriteLine(p); * } * } * * 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 * Precursor.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; * } * * Console.Out.WriteLine("Current----"); * foreach (T p in currentPkl) * { * Console.Out.WriteLine(p); * } * Console.Out.WriteLine("Add----"); * foreach (T p in result[next]) * { * Console.Out.WriteLine(p); * } * * currentPkl.AddRange(result[next]); * * Console.Out.WriteLine("To----"); * foreach (T p in currentPkl) * { * Console.Out.WriteLine(p); * } * * result.RemoveAt(next); * } * } * * current++; * } * * Console.Out.WriteLine("---after merge"); * foreach (PeakList<T> pkl in result) * { * Console.Out.WriteLine("---"); * foreach (Peak p in pkl) * { * Console.Out.WriteLine(p); * } * } */ return(result); }