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); } }