Exemple #1
0
        /// <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);
        }
Exemple #2
0
        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);
        }