public void EmptyTest() { var scan = new List <Centroid>(); int i = PeakMatcher.NearestIndex(scan, 1000.0); Assert.Equal(0, i); }
public void NearestStartTest() { double targetMz = 1; var peaks = GetTestPeaks(); int i = PeakMatcher.NearestIndex(peaks, targetMz); Assert.Equal(0, i); }
public void NoMatchTest() { double targetMz = 400; double tolerance = 10; var units = PeakMatcher.PPM; var scan = GetTestScan(); int i = PeakMatcher.Match(scan, targetMz, tolerance, units); Assert.Equal(-1, i); }
public void MostIntenseTest() { double targetMz = 980; double tolerance = 30; var units = PeakMatcher.DALTON; var scan = GetTestScan(); int i = PeakMatcher.MostIntenseIndex(scan, targetMz, tolerance, units); Assert.Equal(3, i); targetMz = 400; tolerance = 10; i = PeakMatcher.MostIntenseIndex(scan, targetMz, tolerance, units); Assert.Equal(-1, i); targetMz = 1000; tolerance = 300; i = PeakMatcher.MostIntenseIndex(scan, targetMz, tolerance, units); Assert.Equal(0, i); }
/// <summary> /// Run a single Monocle scan. /// </summary> /// <param name="Ms1ScansCentroids"></param> /// <param name="ParentScan"></param> /// <param name="precursor"></param> public static void Run(List <Scan> Ms1ScansCentroids, Scan ParentScan, Precursor precursor, MonocleOptions Options) { double precursorMz = precursor.IsolationMz; if (precursorMz < 1) { precursorMz = precursor.Mz; } int precursorCharge = precursor.Charge; if (Options.UseMostIntense && precursor.IsolationWidth > 0) { // Re-assign the precursor m/z to that of the most intense peak in the isolation window. int peakIndex = PeakMatcher.MostIntenseIndex(ParentScan, precursor.IsolationMz, precursor.IsolationWidth / 2, PeakMatcher.DALTON); if (peakIndex >= 0) { precursorMz = ParentScan.Centroids[peakIndex].Mz; } } // Search for ion in parent scan, use parent ion mz for future peaks int index = PeakMatcher.Match(ParentScan, precursorMz, 50, PeakMatcher.PPM); if (index >= 0) { precursorMz = ParentScan.Centroids[index].Mz; } // For charge detection int bestCharge = 0; double bestScore = -1; int bestIndex = 0; List <double> bestPeaks = new List <double>(); List <double> bestPeakIntensities = new List <double>(); //Create new class to maintain ref class options ChargeRange chargeRange = new ChargeRange(precursorCharge, precursorCharge); if (Options.Charge_Detection || precursorCharge == 0) { chargeRange.Low = Options.Charge_Range.Low; chargeRange.High = Options.Charge_Range.High; } for (int charge = chargeRange.Low; charge <= chargeRange.High; charge++) { // Restrict number of isotopes to consider based on precursor mass. double mass = precursor.Mz * charge; var isotopeRange = new IsotopeRange(mass); // Generate expected relative intensities. List <double> expected = PeptideEnvelopeCalculator.GetTheoreticalEnvelope(precursorMz, charge, isotopeRange.CompareSize); Vector.Scale(expected); PeptideEnvelope envelope = PeptideEnvelopeExtractor.Extract(Ms1ScansCentroids, precursorMz, charge, isotopeRange.Left, isotopeRange.Isotopes); // Get best match using dot product. // Limit the number of isotopeRange peaks to test for (int i = 0; i < (isotopeRange.Isotopes - (isotopeRange.CompareSize - 1)); ++i) { List <double> observed = envelope.averageIntensity.GetRange(i, expected.Count); Vector.Scale(observed); PeptideEnvelopeExtractor.ScaleByPeakCount(observed, envelope, i); double score = Vector.Dot(observed, expected); // add 5% to give bias toward left peaks. if (score > bestScore * 1.05) { bestScore = score; if (score > 0.1) { // A peak to the left is included, so add // offset to get monoisotopic index. bestIndex = i + 1; bestCharge = charge; bestPeaks = envelope.mzs[bestIndex]; bestPeakIntensities = envelope.intensities[bestIndex]; } } } } // end charge for loop if (bestCharge > 0) { precursor.Charge = bestCharge; } // Calculate m/z if (bestPeaks.Count > 0) { precursor.Mz = Vector.WeightedAverage(bestPeaks, bestPeakIntensities); } else { precursor.Mz = precursorMz; } precursor.IsolationSpecificity = IsolationSpecificityCalculator.calculate( ParentScan.Centroids, precursor.IsolationMz, precursor.Mz, precursor.Charge, precursor.IsolationWidth ); }