Ejemplo n.º 1
0
        public void TestOutput()
        {
            double isolationMz     = 1000.0;
            double precursorMz     = 999.5;
            int    charge          = 2;
            double isolationWindow = 1.0;

            var peaks = new List <Centroid> {
                new Centroid {
                    Mz = 800.0, Intensity = 100
                },
                new Centroid {
                    Mz = 999.5, Intensity = 100
                },
                new Centroid {
                    Mz = 999.9, Intensity = 100
                },
                new Centroid {
                    Mz = 1000.0, Intensity = 100
                },
                new Centroid {
                    Mz = 1000.1, Intensity = 100
                },
                new Centroid {
                    Mz = 1200.0, Intensity = 100
                }
            };

            double output = IsolationSpecificityCalculator.calculate(peaks, isolationMz, precursorMz, charge, isolationWindow);

            Assert.Equal(0.5, output, 3);
        }
Ejemplo n.º 2
0
        /// <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
                );
        }