/// <summary> /// Returns the index of the most intense peak in the window. /// Returns -1 if none is found. /// </summary> /// <param name="scan">The scan that will be searched</param> /// <param name="targetMz">The center of the window where peaks will be considered</param> /// <param name="tolerance">window will be +/- this value</param> /// <param name="tolUnits">Units can be DALTON or PPM</param> /// <returns></returns> public static int MostIntenseIndex(Scan scan, double targetMz, double tolerance, int tolUnits) { double lowMz = targetMz - tolerance; double highMz = targetMz + tolerance; if (tolUnits == PPM) { double delta = tolerance * targetMz / 1000000; lowMz = targetMz - delta; highMz = targetMz + delta; } var peaks = scan.Centroids; int i = PeakMatcher.NearestIndex(peaks, lowMz); if (peaks[i].Mz < lowMz) { ++i; } double maxIntensity = 0; int bestIndex = -1; for ( ; i < peaks.Count && peaks[i].Mz < highMz; ++i) { if (peaks[i].Intensity > maxIntensity) { maxIntensity = peaks[i].Intensity; bestIndex = i; } } return(bestIndex); }
/// <summary> /// Extract peaks that may be isotopes of the peak indicated by targetMz /// </summary> /// <param name="scans">Peaks will be extracted from this list of scans</param> /// <param name="targetMz">The m/z to start extraction</param> /// <param name="charge">The charge used to find neighboring isotopes</param> /// <param name="left">A negative or zero number to indicate the number of isotopes to extract to the left of targetMz</param> /// <param name="numIsotopes">The total number of isotopes to extract including the number indicated by "left"</param> /// <returns></returns> public static PeptideEnvelope Extract(List <Scan> scans, double targetMz, int charge, int left, int numIsotopes) { PeptideEnvelope output = new PeptideEnvelope(numIsotopes, scans.Count); foreach (Scan scan in scans) { for (int i = 0; i < numIsotopes; ++i) { double matchMz = targetMz + (((i + left) * Mass.AVERAGINE_DIFF) / charge); int index = PeakMatcher.Match(scan, matchMz, 3, PeakMatcher.PPM); if (index >= 0) { double mz = scan.Centroids[index].Mz; double intensity = scan.Centroids[index].Intensity; output.mzs[i].Add(mz); output.intensities[i].Add(intensity); } } } int max = 0; foreach (var intensities in output.intensities) { if (intensities.Count > max) { max = intensities.Count; } output.averageIntensity.Add(Vector.Average(intensities)); } output.MaxPeakCount = max; return(output); }
public static double calculate(List <Centroid> peaks, double isolationMz, double precursorMz, int charge, double isolationWindow) { if (peaks.Count == 0) { return(0); } double precursorIntensity = 0; double totalIntensity = 0; double lowMz = isolationMz - (isolationWindow / 2.0); double highMz = isolationMz + (isolationWindow / 2.0); int i = PeakMatcher.NearestIndex(peaks, lowMz); if (peaks[i].Mz < lowMz) { ++i; } for ( ; i < peaks.Count && peaks[i].Mz < highMz; ++i) { var peak = peaks[i]; // if the peak is within 20 ppm of any isotope bool isPrecursor = false; for (int j = -6; j < 7; ++j) { double theoreticalMass = precursorMz + (j * (Mass.AVERAGINE_DIFF / charge)); if (System.Math.Abs(PeakMatcher.getPpm(theoreticalMass, peak.Mz)) < 20) { isPrecursor = true; break; } } if (isPrecursor) { precursorIntensity += peak.Intensity; } totalIntensity += peak.Intensity; } if (totalIntensity < 1) { return(0); } return(precursorIntensity / totalIntensity); }