Esempio n. 1
0
        private Tuple <Peak, PeakDataPoint> GetMatch(Peak peak, PeakDataPoint[] fragmentPeaks)
        {
            var           peakDataPoint = new PeakDataPoint(peak.Mz, peak.Intensity, 0, 0, string.Empty);
            var           index         = Array.BinarySearch(fragmentPeaks, peakDataPoint, new PeakDataPoint.MzComparer());
            PeakDataPoint matchedPeak   = null;

            if (index >= 0)
            {
                matchedPeak = fragmentPeaks[index];
            }

            return(new Tuple <Peak, PeakDataPoint>(peak, matchedPeak));
        }
        /// <summary>
        /// Get the peak data points from a list of peaks.
        /// </summary>
        /// <param name="peaks">The peaks to convert.</param>
        /// <returns>Array of peaks converted to PeakDataPoints.</returns>
        private PeakDataPoint[] GetPeakDataPoints(IList <Peak> peaks)
        {
            var max            = peaks.Max(p => p.Intensity);
            var peakDataPoints = new PeakDataPoint[peaks.Count];

            for (var i = 0; i < peaks.Count; i++)
            {
                var peak = peaks[i];
                peakDataPoints[i] = new PeakDataPoint(peak.Mz, peak.Intensity / max, 0.0, 0.0, string.Empty)
                {
                    Index = i
                };
            }

            return(peakDataPoints);
        }
        /// <summary>
        /// Build the isotope plot showing theoretical isotopic profile and
        /// actual isotopic profile.
        /// This will calculate the theoretical using averagine from the provided monoisotopic mass.
        /// </summary>
        /// <param name="actual">Actual isotopic profile.</param>
        /// <param name="mass">Monoisotopic mass, for calculating theoretical isotopic profile.</param>
        /// <param name="charge">Charge, for calculating actual isotopic profile.</param>
        public void BuildPlot(Isotope[] actual, double mass, int charge)
        {
            // Calculate theoretical isotopic profile using averagine
            var theoEnvelope = Averagine.GetIsotopomerEnvelope(mass);
            var theoretical  = new PeakDataPoint[theoEnvelope.Envelope.Length];

            // Calculate m/z for each isotope index (observed)
            for (var isotopeIndex = 0; isotopeIndex < theoEnvelope.Envelope.Length; isotopeIndex++)
            {
                var intensity = theoEnvelope.Envelope[isotopeIndex];
                var mz        = Ion.GetIsotopeMz(mass, charge, isotopeIndex);
                var m         = (mz * charge * Constants.Proton) - (charge * Constants.Proton);
                theoretical[isotopeIndex] = new PeakDataPoint(m, intensity, 0.0, 0.0, string.Empty);
            }

            // Create peak data points from isotopes and calculate m/z values (actual)
            var observed = actual.Select(i => new PeakDataPoint(theoretical[i.Index].X, i.Ratio, 0.0, 0.0, string.Empty)
            {
                Index = i.Index
            }).ToArray();

            BuildPlot(theoretical, observed, false);
        }