コード例 #1
0
        private IEnumerable <DeisotopedPeak> GetDeisotopedPeaks(List <Peak> specWindow, IEnumerable <Peak> peakList, int numDeisotopedPeaksToGet)
        {
            var peakListSortedByIntensity = new List <Peak>(peakList);

            peakListSortedByIntensity.Sort(new IntensityComparer());
            var remainingPeakList = new LinkedList <Peak>(peakListSortedByIntensity);

            var deisotopedPeakSet = new SortedSet <DeisotopedPeak>();

            while (remainingPeakList.Any())
            {
                var peakWithHighestIntensity = remainingPeakList.First.Value;
                var peakMz = peakWithHighestIntensity.Mz;
                var score  = new double[_maxCharge + 1];
                for (var charge = _maxCharge; charge >= _minCharge; charge--)
                {
                    // check whether next isotope peak exists
                    var nextIsotopeMz   = peakMz + Constants.C13MinusC12 / charge;
                    var nextIsotopePeak = PeakListUtils.FindPeak(specWindow, nextIsotopeMz, _tolerance);
                    if (nextIsotopePeak == null)
                    {
                        continue;
                    }
                    var mostAbundantIsotopeMass        = (peakMz - Constants.Proton) * charge;
                    var averagineIsoEnv                = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass);
                    var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex;
                    var monoIsotopicMass               = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12;
                    var averagineIsotopeProfile        = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge);
                    var corr = PeakListUtils.GetPearsonCorrelation(specWindow, averagineIsotopeProfile, _comparer);

                    score[charge] = corr;
                    var isValid = true;
                    for (var mult = 2; mult <= _maxCharge / charge; mult++)
                    {
                        var multiple = charge * mult;
                        if (score[multiple] > 0.8 * corr)
                        {
                            isValid = false;
                            break;
                        }
                    }
                    if (!isValid)
                    {
                        continue;
                    }
                    deisotopedPeakSet.Add(new DeisotopedPeak(monoIsotopicMass, charge, corr));
                    if (deisotopedPeakSet.Count > numDeisotopedPeaksToGet)
                    {
                        deisotopedPeakSet.Remove(deisotopedPeakSet.Min);
                    }
                }
                remainingPeakList.RemoveFirst();
            }
            return(deisotopedPeakSet);
        }
コード例 #2
0
        private void ApplyDeconvolution(List <Peak> specWindow, ref LinkedList <Peak> remainingPeakList, ref List <double> deisotopedMassList)
        {
            if (!remainingPeakList.Any())
            {
                return;
            }

            var peakWithHighestIntensity = remainingPeakList.First.Value;
            var peakMz = peakWithHighestIntensity.Mz;
            var score  = new double[_maxCharge + 1];

            for (var charge = _maxCharge; charge >= _minCharge; charge--)
            {
                // check whether next isotope peak exists
                var nextIsotopeMz   = peakMz + Constants.C13MinusC12 / charge;
                var nextIsotopePeak = PeakListUtils.FindPeak(specWindow, nextIsotopeMz, _tolerance);
                if (nextIsotopePeak == null)
                {
                    continue;
                }
                var mostAbundantIsotopeMass        = (peakMz - Constants.Proton) * charge;
                var averagineIsoEnv                = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass);
                var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex;
                var monoIsotopicMass               = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12;
                var averagineIsotopeProfile        = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge);
                var corr = PeakListUtils.GetPearsonCorrelation(specWindow, averagineIsotopeProfile, _comparer);

                score[charge] = corr;
                var isValid = true;
                for (var mult = 2; mult <= _maxCharge / charge; mult++)
                {
                    var multiple = charge * mult;
                    if (score[multiple] > 0.8 * corr)
                    {
                        isValid = false;
                        break;
                    }
                }
                if (!isValid)
                {
                    continue;
                }

                if (corr > _corrThreshold)
                {
                    deisotopedMassList.Add(monoIsotopicMass);
                }
            }
            remainingPeakList.RemoveFirst();
        }
コード例 #3
0
        public void TestAveragine()
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            ShowStarting(methodName);

            const double monoMass = 10247.5293287335;
            const int    charge   = 14;
            var          profile  = Averagine.GetTheoreticalIsotopeProfile(monoMass, charge);

            Console.WriteLine("Isotope ions:");
            foreach (var p in profile)
            {
                Console.WriteLine("{0}\t{1}", p.Mz, p.Intensity);
            }
            Console.WriteLine();
        }
コード例 #4
0
        /// <summary>
        /// Read a line from the feature file containing a single feature.
        /// </summary>
        /// <param name="line">The line from the feature file.</param>
        /// <param name="delimeter">The delimiter used in feature file.</param>
        /// <param name="headers">The headers of the feature file columns.</param>
        /// <returns>Parsed feature.</returns>
        private static Feature ReadFeature(string line, char delimeter, IReadOnlyDictionary <string, int> headers)
        {
            var expectedHeaders = new List <string>
            {
                "MonoMass",
                "Abundance",
                "LikelihoodRatio",
                "Envelope",
                "MinCharge",
                "MaxCharge",
                ////"SummedCorr",
                "MinScan",
                "MaxScan"
            };

            string likelihoodVarHeader = "LikelihoodRatio";

            foreach (var header in expectedHeaders.Where(header => !headers.ContainsKey(header)))
            {
                if (header == "LikelihoodRatio" && headers.ContainsKey("Probability"))
                {
                    likelihoodVarHeader = "Probability";
                }
                else
                {
                    throw new KeyNotFoundException(string.Format("Missing expected column header \"{0}\" in feature file.", header));
                }
            }

            var parts     = line.Split(delimeter);
            var mass      = Convert.ToDouble(parts[headers["MonoMass"]]);
            var abundance = Convert.ToDouble(parts[headers["Abundance"]]);
            var score     = Convert.ToDouble(parts[headers[likelihoodVarHeader]]);
            var isotopes  = ReadIsotopicEnvelope(parts[headers["Envelope"]]);
            var minCharge = Convert.ToInt32(parts[headers["MinCharge"]]);
            var maxCharge = Convert.ToInt32(parts[headers["MaxCharge"]]);
            int id        = -1;

            if (headers.ContainsKey("FeatureID"))
            {
                id = Convert.ToInt32(parts[headers["FeatureID"]]);
            }

            var summedCorr = headers.ContainsKey("SummedCorr") ? Convert.ToDouble(parts[headers["SummedCorr"]]) : 0.0;

            int         mostAbundantIsotopeIndex = Averagine.GetIsotopomerEnvelope(mass).MostAbundantIsotopeIndex;
            List <Peak> minIsotopicProfile       = Averagine.GetTheoreticalIsotopeProfile(mass, minCharge, 0);
            List <Peak> maxIsotopicProfile       = Averagine.GetTheoreticalIsotopeProfile(mass, maxCharge, 0);

            var minPoint = new Feature.FeaturePoint
            {
                Id          = id,
                Mass        = mass,
                Scan        = Convert.ToInt32(parts[headers["MinScan"]]),
                Mz          = minIsotopicProfile[mostAbundantIsotopeIndex].Mz,
                Charge      = minCharge,
                Abundance   = abundance,
                Score       = score,
                Isotopes    = isotopes,
                Correlation = summedCorr
            };
            var maxPoint = new Feature.FeaturePoint
            {
                Id          = id,
                Mass        = mass,
                Scan        = Convert.ToInt32(parts[headers["MaxScan"]]),
                Mz          = maxIsotopicProfile[mostAbundantIsotopeIndex].Mz,
                Charge      = maxCharge,
                Abundance   = abundance,
                Score       = score,
                Isotopes    = isotopes,
                Correlation = summedCorr,
            };

            return(new Feature(minPoint, maxPoint)
            {
                Id = id
            });
        }
コード例 #5
0
        private void SetLcMsMatches(double peakMz, int scanNum, IList <Peak> precursorSpecWindow, IList <Peak> nextMs1SpecWindow)
        {
            var xicThisPeak = _run.GetPrecursorExtractedIonChromatogram(peakMz, _tolerance, scanNum);

            if (xicThisPeak.Count < 2)
            {
                return;
            }

            for (var charge = _maxCharge; charge >= _minCharge; charge--)
            {
                // check whether next isotope peak exists
                var nextIsotopeMz  = peakMz + Constants.C13MinusC12 / charge;
                var xicNextIsotope = _run.GetPrecursorExtractedIonChromatogram(nextIsotopeMz, _tolerance, scanNum);
                if (!xicNextIsotope.Any())
                {
                    continue;
                }
                if (xicThisPeak.GetCorrelation(xicNextIsotope) < _mostAbundantPlusOneIsotopeCorrThreshold)
                {
                    continue;
                }

                var mostAbundantIsotopeMass        = (peakMz - Constants.Proton) * charge;
                var averagineIsoEnv                = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass);
                var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex;
                var monoIsotopicMass               = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12;

                // Isotope correlation
                var averagineIsotopeProfile = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge);
                var precursorIsotopeCorr    = precursorSpecWindow != null?PeakListUtils.GetPearsonCorrelation(precursorSpecWindow, averagineIsotopeProfile, _comparer) : 0;

                var nextMs1IsotopeCorr = nextMs1SpecWindow != null?PeakListUtils.GetPearsonCorrelation(nextMs1SpecWindow, averagineIsotopeProfile, _comparer) : 0;

                var isotopeCorr = Math.Max(precursorIsotopeCorr, nextMs1IsotopeCorr);
                if (isotopeCorr < _isotopeCorrThresholdThreshold)
                {
                    continue;
                }

                if (_chargeCorrThresholdThreshold > 0.0)
                {
                    var mzChargePlusOne   = Ion.GetIsotopeMz(monoIsotopicMass, charge + 1, approxMostAbundantIsotopeIndex);
                    var xicPlusOneCharge  = _run.GetPrecursorExtractedIonChromatogram(mzChargePlusOne, _tolerance, scanNum);
                    var corrPlusOneCharge = xicPlusOneCharge.Count >= 3 ? xicThisPeak.GetCorrelation(xicPlusOneCharge) : 0;

                    double corrMinusOneCharge;
                    if (charge > 1)
                    {
                        var mzChargeMinusOne  = Ion.GetIsotopeMz(monoIsotopicMass, charge - 1, approxMostAbundantIsotopeIndex);
                        var xicMinusOneCharge = _run.GetPrecursorExtractedIonChromatogram(mzChargeMinusOne, _tolerance, scanNum);
                        corrMinusOneCharge = xicMinusOneCharge.Count >= 3 ? xicThisPeak.GetCorrelation(xicMinusOneCharge) : 0;
                    }
                    else
                    {
                        corrMinusOneCharge = 0.0;
                    }

                    var chargeCorr = Math.Max(corrPlusOneCharge, corrMinusOneCharge);
                    if (chargeCorr < _chargeCorrThresholdThreshold)
                    {
                        continue;
                    }
                }

                _lcMsMatchMap.SetMatches(monoIsotopicMass, xicThisPeak[0].ScanNum, xicThisPeak[xicThisPeak.Count - 1].ScanNum);
            }
        }