private void AddIonSeries(GraphPane peakPane, GraphPane ppmPane, PeakList <MatchedPeak> mgf, double mzTolerance, double minIntensity, IPeptideFragmentationBuilder <MatchedPeak> builder, string sequence, Color tagColor)
        {
            MatchedPeakUtils.Match(mgf, builder.Build(sequence), mzTolerance, minIntensity);

            var ionType     = builder.SeriesType.ToString();
            var matchedIons = (from m in mgf
                               where m.Matched && m.PeakType == builder.SeriesType
                               select m).ToList();

            var ppl = new PointPairList();

            foreach (var m in matchedIons)
            {
                ppl.Add(new PointPair(m.Mz, m.Intensity, m.Information));
            }

            peakPane.AddIndividualLine("", ppl, Color.Black, tagColor);

            if (ppmPane != null)
            {
                var diff = new PointPairList();
                foreach (var m in matchedIons)
                {
                    if (isPPM)
                    {
                        diff.Add(new PointPair(m.Mz, PrecursorUtils.mz2ppm(m.Mz, m.Mz - m.MatchedMZ)));
                    }
                    else
                    {
                        diff.Add(new PointPair(m.Mz, m.Mz - m.MatchedMZ));
                    }
                }
                ppmPane.AddPoints(diff, tagColor);
            }
        }
コード例 #2
0
 public void InitalizePPMTolerance()
 {
     foreach (var peak in Peaks)
     {
         peak.PPMDistance = PrecursorUtils.mz2ppm(peak.Mz, peak.Mz - this.Mz);
     }
 }
        private void AddPeak(Dictionary <int, List <PeakEntry> > map, double maxPeakIntensity, int scan, Peak peak)
        {
            var mz = (int)(Math.Round(peak.Mz));

            List <PeakEntry> entries;

            if (!map.TryGetValue(mz, out entries))
            {
                entries = new List <PeakEntry>();
                map[mz] = entries;
            }

            var relativeIntensity = peak.Intensity / maxPeakIntensity;

            var       gap   = PrecursorUtils.ppm2mz(peak.Mz, options.ProductIonPPM);
            PeakEntry entry = new PeakEntry()
            {
                Ion    = new Peak(peak.Mz, peak.Intensity),
                FromMz = peak.Mz - gap,
                ToMz   = peak.Mz + gap
            };

            entry.Intensities.Add(new SourcePeak(scan, peak.Mz, relativeIntensity));
            entries.Add(entry);
        }
コード例 #4
0
        public PeakList <T> Process(PeakList <T> t)
        {
            var shiftMz = PrecursorUtils.ppm2mz(t.PrecursorMZ, ShiftPPM);

            t.PrecursorMZ = t.PrecursorMZ + shiftMz;
            return(t);
        }
コード例 #5
0
        protected override void DoWritePeakList(IRawFile rawReader, PeakList <Peak> pkl, string rawFileName, List <string> result)
        {
            var sw   = GetStreamWriter(rawReader, pkl.ScanMode, pkl.MsLevel, rawFileName);
            var scan = pkl.ScanTimes[0].Scan;

            if (pkl.MsLevel == 1)
            {
                sw.Flush();

                sw1Index.Write("{0}\t{1}\n", scan, sw.BaseStream.Position);

                sw.Write("S\t{0}\t{0}\n", scan);
                sw.Write("I\tRetTime\t{0:0.####}\n", pkl.ScanTimes[0].RetentionTime);

                foreach (Peak p in pkl)
                {
                    sw.Write("{0:0.#####} {1:0.#} {2}\n", p.Mz, p.Intensity, p.Charge);
                }
            }
            else
            {
                sw.WriteLine("S\t{0}\t{1}\t{2}", scan, scan, pkl.PrecursorMZ);
                int[] charges = 0 != pkl.PrecursorCharge ? new[] { pkl.PrecursorCharge } : new[] { 2, 3 };
                foreach (var charge in charges)
                {
                    sw.WriteLine("Z\t{0}\t{1:0.#####}", charge, PrecursorUtils.MzToMH(pkl.PrecursorMZ, charge, true));
                }
                foreach (var peak in pkl)
                {
                    sw.WriteLine("{0:0.#####}\t{1:0.#}", peak.Mz, peak.Intensity);
                }
            }
        }
コード例 #6
0
        public static void Alignment <T, U>(PeakList <T> lst1, PeakList <U> lst2, double ppmTolerance)
            where T : Peak
            where U : Peak
        {
            //Initialize score matrix
            var scores = new double[lst1.Count, lst2.Count];

            for (int i = 0; i < lst1.Count; i++)
            {
                var mz    = lst1[i].Mz;
                var delta = PrecursorUtils.ppm2mz(mz, ppmTolerance);
                var minMz = mz - delta;
                var maxMz = mz + delta;
                for (int j = 0; j < lst2.Count; j++)
                {
                    if (lst2[j].Mz < minMz)
                    {
                        scores[i, j] = 0;
                        continue;
                    }

                    if (lst2[j].Mz > maxMz)
                    {
                        for (int k = j; k < lst2.Count; k++)
                        {
                            scores[i, k] = 0;
                        }
                        break;
                    }

                    scores[i, j] = lst1[i].Intensity * lst2[j].Intensity;
                }
            }
        }
コード例 #7
0
        private bool AcceptScan(SilacPeakListPair pair, SilacCompoundInfo sci, int lightMaxIndex, double lightMinPPM, double lightMaxPPM, int heavyMaxIndex, double heavyMinPPM, double heavyMaxPPM)
        {
            //如果轻重标中任意一个最高峰不存在,循环结束。
            if (pair.Light[lightMaxIndex].Intensity == 0 || pair.Heavy[heavyMaxIndex].Intensity == 0)
            {
                return(false);
            }

            //轻标最高峰的ppm
            double lightPPM = PrecursorUtils.mz2ppm(pair.Light[lightMaxIndex].Mz, sci.Light.Profile[lightMaxIndex].Mz - pair.Light[lightMaxIndex].Mz);

            if (lightPPM < lightMinPPM || lightPPM > lightMaxPPM)
            {
                return(false);
            }

            //重标最高峰的ppm
            double heavyPPM = PrecursorUtils.mz2ppm(pair.Heavy[heavyMaxIndex].Mz, sci.Heavy.Profile[heavyMaxIndex].Mz - pair.Heavy[heavyMaxIndex].Mz);

            if (heavyPPM < heavyMinPPM || heavyPPM > heavyMaxPPM)
            {
                return(false);
            }

            return(true);
        }
コード例 #8
0
        /// <summary>
        /// 将实际离子与理论离子进行匹配。对于已经被匹配上的实际离子或者强度小于给定阈值的实际离子,不进行匹配。
        /// 对于匹配到相同理论离子的不同实际离子,保留强度最大的为实际匹配结果。
        /// </summary>
        /// <param name="exprimentalPeaks">实际离子</param>
        /// <param name="theoreticalPeaks">理论离子</param>
        /// <param name="mzTolerance">离子误差</param>
        /// <param name="minIntensity">匹配离子最小强度</param>
        public static void MatchPPM(List <MatchedPeak> exprimentalPeaks, List <MatchedPeak> theoreticalPeaks, double ppmTolerance, double minIntensity = 0.0)
        {
            foreach (MatchedPeak peak in exprimentalPeaks)
            {
                if (peak.Matched || peak.Intensity < minIntensity)
                {
                    continue;
                }

                var mzTolerance = PrecursorUtils.ppm2mz(peak.Mz, ppmTolerance);

                foreach (MatchedPeak thePeak in theoreticalPeaks)
                {
                    if (Math.Abs(peak.Mz - thePeak.Mz) <= mzTolerance)
                    {
                        peak.Matched    = true;
                        thePeak.Matched = true;

                        peak.MatchedMZ   = thePeak.Mz;
                        peak.PeakType    = thePeak.PeakType;
                        peak.Charge      = thePeak.Charge;
                        peak.DisplayName = thePeak.DisplayName;
                        peak.PeakIndex   = thePeak.PeakIndex;
                        break;
                    }
                }
            }

            RemoveDuplicateMatch(exprimentalPeaks);
        }
コード例 #9
0
        public List <O18PPMEntry> GetPPMList()
        {
            int pepCharge = GetCharge();

            var gap = (Atom.O18.MonoMass - Atom.O.MonoMass) / pepCharge;

            double mzO16  = TheoreticalO16Mz;
            double mzO181 = TheoreticalO16Mz + gap;
            double mzO182 = mzO181 + gap;

            var result = new List <O18PPMEntry>();

            ObservedEnvelopes.ForEach(m =>
            {
                var entry = new O18PPMEntry()
                {
                    Scan = m.Scan
                };
                entry.O16  = m[0].Intensity > 0 ? PrecursorUtils.mz2ppm(m[0].Mz, m[0].Mz - mzO16) : double.NaN;
                entry.O181 = m[2].Intensity > 0 ? PrecursorUtils.mz2ppm(m[2].Mz, m[2].Mz - mzO181) : double.NaN;
                entry.O182 = m[4].Intensity > 0 ? PrecursorUtils.mz2ppm(m[4].Mz, m[4].Mz - mzO182) : double.NaN;
                result.Add(entry);
            });

            return(result);
        }
        private void MergeIons(List <PeakEntry> e)
        {
            e.Sort((m1, m2) => m2.Intensities.Count.CompareTo(m1.Intensities.Count));
            for (int i = e.Count - 1; i >= 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (e[i].Ion.Mz >= e[j].FromMz && e[i].Ion.Mz <= e[j].ToMz)
                    {
                        var allIntensity = e[i].Ion.Intensity + e[j].Ion.Intensity;

                        e[j].Ion.Mz        = (e[i].Ion.Mz * e[i].Ion.Intensity + e[j].Ion.Mz * e[j].Ion.Intensity) / allIntensity;
                        e[j].Ion.Intensity = allIntensity;
                        e[j].Intensities.AddRange(e[i].Intensities);

                        var gap = PrecursorUtils.ppm2mz(e[j].Ion.Mz, options.ProductIonPPM);
                        e[j].FromMz = e[j].Ion.Mz - gap;
                        e[j].ToMz   = e[j].Ion.Mz + gap;

                        e.RemoveAt(i);

                        break;
                    }
                }
            }
        }
コード例 #11
0
        public void InitializeIsotopicIons(double ppmTolerance, double minimumPercentage = 0.05, int maxProfileLength = int.MaxValue)
        {
            var atomComposition = aas.GetPeptideAtomComposition(this.Sequence);
            var profiles        = profileBuilder.GetProfile(atomComposition, this.Charge, minimumPercentage).Take(maxProfileLength);

            this.IsotopicIons = (from peak in profiles
                                 select new IsotopicIon()
            {
                Mz = peak.Mz,
                Intensity = peak.Intensity,
            }).ToArray();
            var diff = this.TheoreticalMz - this.IsotopicIons[0].Mz;

            //Replace the ion m/z to real ion m/z but keep the distance between ions in case of the peptide contains modification
            foreach (var ion in this.IsotopicIons)
            {
                ion.Mz += diff;
                var mzdiff = PrecursorUtils.ppm2mz(ion.Mz, ppmTolerance);
                ion.MinimumMzWithinTolerance = ion.Mz - mzdiff;
                ion.MaximumMzWithinTolerance = ion.Mz + mzdiff;
            }

            this.IsotopicIntensities = (from ion in this.IsotopicIons
                                        select ion.Intensity).ToArray();
        }
コード例 #12
0
 private void InitializeTargetPeaks()
 {
     targetPeaks.ForEach(m =>
     {
         m.MzTolerance = PrecursorUtils.ppm2mz(m.Mz, ppmTolerance);
     });
 }
コード例 #13
0
        private void MergePeak(T p, List <T> other, int iOtherTopIndex, double ppmTolerance)
        {
            double mzTolerance = PrecursorUtils.ppm2mz(p.Mz, ppmTolerance);

            //consider merge with peak having large intensity first.
            int i = iOtherTopIndex;

            while (i < other.Count)
            {
                T      o   = other[i];
                double gap = Math.Abs(p.Mz - o.Mz);
                if (gap <= mzTolerance)
                {
                    if (p.Charge == o.Charge || 0 == p.Charge || 0 == o.Charge)
                    {
                        double mz = (p.Mz * p.Intensity + o.Mz * o.Intensity) / (p.Intensity + o.Intensity);

                        p.Mz        = mz;
                        p.Intensity = p.Intensity + o.Intensity;
                        p.Charge    = Math.Max(p.Charge, o.Charge);
                        other.RemoveAt(i);
                        continue;
                    }
                }
                i++;
            }
        }
コード例 #14
0
        public void FilterByTolerance(double ppmTolerance)
        {
            Sort((m1, m2) => m1.Mz.CompareTo(m2.Mz));

            for (int start = 0; start < Count - 1;)
            {
                double mzTolerance = 2 * PrecursorUtils.ppm2mz(this[start].Mz, ppmTolerance);

                int next = start + 1;
                while (next < Count)
                {
                    if (this[next].Mz - this[start].Mz > mzTolerance)
                    {
                        start++;
                        break;
                    }

                    if (this[start].Intensity > this[next].Intensity)
                    {
                        RemoveAt(next);
                    }
                    else
                    {
                        RemoveAt(start);
                    }
                }
            }
        }
        public QuantificationChromotograph Build(IIdentifiedSpectrum mphit, IRawFile reader)
        {
            QuantificationChromotograph result = new QuantificationChromotograph();

            var envelopes = builder.Build(mphit);

            int startScan = mphit.Query.FileScan.FirstScan;

            double mzTolerance = PrecursorUtils.ppm2mz(envelopes[0][0], ppmTolerance);

            bool bFirst = true;

            int firstScanNumber = reader.GetFirstSpectrumNumber();
            int lastScanNumber  = reader.GetLastSpectrumNumber();

            //backward
            for (int scan = startScan; scan >= firstScanNumber; scan--)
            {
                if (1 == reader.GetMsLevel(scan))
                {
                    QuantificationScan qscan = reader.GetPeakList(scan).GetQuantificationScan(envelopes, mzTolerance);

                    if (!validate(qscan))
                    {
                        break;
                    }

                    if (bFirst)
                    {
                        qscan.IsIdentified = true;
                        bFirst             = false;
                    }
                    result.Insert(0, qscan);
                }
            }

            //forward
            for (int scan = startScan + 1; scan <= lastScanNumber; scan++)
            {
                if (1 == reader.GetMsLevel(scan))
                {
                    QuantificationScan qscan = reader.GetPeakList(scan).GetQuantificationScan(envelopes, mzTolerance);

                    if (!validate(qscan))
                    {
                        break;
                    }

                    result.Add(qscan);
                }
            }

            if (result.Count > 0)
            {
                result.IdentifiedSpectra.Add(mphit);
            }

            return(result);
        }
 public PeakList <T> Process(PeakList <T> t)
 {
     foreach (var peak in t)
     {
         var shiftMz = PrecursorUtils.ppm2mz(peak.Mz, shiftPPM);
         peak.Mz += shiftMz;
     }
     return(t);
 }
        protected List <PeakList <Peak> > MergePeakList(List <PeakList <Peak> > pklList)
        {
            int index = 0;

            Progress.SetRange(0, pklList.Count);
            Progress.Begin();
            try
            {
                while (index < pklList.Count)
                {
                    if (Progress.IsCancellationPending())
                    {
                        throw new UserTerminatedException();
                    }
                    Progress.SetPosition(index);

                    PeakList <Peak> currentPkl = pklList[index];
                    double          maxGap     = PrecursorUtils.ppm2mz(currentPkl.PrecursorMZ, this.ppmPrecursorTolerance);

                    int next = index + 1;
                    while (next < pklList.Count)
                    {
                        PeakList <Peak> nextPkl          = pklList[next];
                        double          retentionTimeGap = nextPkl.ScanTimes[0].RetentionTime -
                                                           currentPkl.ScanTimes[0].RetentionTime;
                        if (retentionTimeGap > this.retentionTimeTolerance)
                        {
                            break;
                        }

                        if (nextPkl.PrecursorCharge != currentPkl.PrecursorCharge)
                        {
                            next++;
                            continue;
                        }

                        double precursorMzGap = Math.Abs(nextPkl.PrecursorMZ - currentPkl.PrecursorMZ);
                        if (precursorMzGap < maxGap)
                        {
                            currentPkl.MergeByMZFirst(nextPkl, this.ppmPeakTolerance);
                            pklList.RemoveAt(next);
                            continue;
                        }

                        next++;
                    }
                    index++;
                }
                Progress.SetPosition(pklList.Count);
            }
            finally
            {
                Progress.End();
            }

            return(pklList);
        }
コード例 #18
0
        public static void ExtendEnvelope <T>(PeakList <T> pkl, double ppmTolerance) where T : Peak
        {
            for (int i = 0; i < pkl.Count; i++)
            {
                if (0 == pkl[i].Charge)
                {
                    continue;
                }

                double mzTolerance = 2 * PrecursorUtils.ppm2mz(pkl[i].Mz, ppmTolerance);

                double priorMz = pkl[i].Mz - ChargeDeconvolution.C_GAP / pkl[i].Charge;
                for (int j = i - 1; j >= 0; j--)
                {
                    if (pkl[j].Charge > 0)
                    {
                        continue;
                    }

                    if (pkl[j].Mz > priorMz + mzTolerance)
                    {
                        continue;
                    }

                    if (pkl[j].Mz < priorMz - mzTolerance)
                    {
                        break;
                    }

                    pkl[j].Charge = pkl[i].Charge;
                }

                double nextMz = pkl[i].Mz + ChargeDeconvolution.C_GAP / pkl[i].Charge;
                for (int j = i + 1; j < pkl.Count; j++)
                {
                    if (pkl[j].Charge > 0)
                    {
                        continue;
                    }

                    if (pkl[j].Mz < nextMz - mzTolerance)
                    {
                        continue;
                    }

                    if (pkl[j].Mz > nextMz + mzTolerance)
                    {
                        break;
                    }

                    pkl[j].Charge = pkl[i].Charge;
                }
            }

            return;
        }
コード例 #19
0
 public void InitalizePPMTolerance()
 {
     foreach (var peaks in Profiles)
     {
         for (int i = 0; i < peaks.Count; i++)
         {
             peaks[i].PPMDistance = PrecursorUtils.mz2ppm(peaks[i].Mz, IsotopicIons[i].Mz - peaks[i].Mz);
         }
     }
 }
コード例 #20
0
        public IFilter <IIdentifiedSpectrum> GetFilter(IEnumerable <IIdentifiedSpectrum> t)
        {
            var result = new List <FilterItem>();

            List <double> iso0 = new List <double>();
            List <double> iso1 = new List <double>();
            List <double> iso2 = new List <double>();

            foreach (var pep in t)
            {
                var iso0ppm = PrecursorUtils.mz2ppm(pep.TheoreticalMass, pep.TheoreticalMinusExperimentalMass);
                if (Math.Abs(iso0ppm) < this.maxPPM)
                {
                    iso0.Add(iso0ppm);
                    continue;
                }

                if (filterByPrecursorIsotopic)
                {
                    var iso1ppm = PrecursorUtils.mz2ppm(pep.TheoreticalMass, pep.TheoreticalMinusExperimentalMass + IsotopicConsts.AVERAGE_ISOTOPIC_MASS);
                    if (Math.Abs(iso1ppm) < this.maxPPM)
                    {
                        iso1.Add(iso1ppm);
                        continue;
                    }

                    var iso2ppm = PrecursorUtils.mz2ppm(pep.TheoreticalMass, pep.TheoreticalMinusExperimentalMass + IsotopicConsts.DOUBLE_AVERAGE_ISOTOPIC_MASS);
                    if (Math.Abs(iso2ppm) < this.maxPPM)
                    {
                        iso2.Add(iso2ppm);
                    }
                }
            }

            List <FilterItem> items = new List <FilterItem>();

            AddFilter(items, iso0, 0.0, 3);
            if (filterByPrecursorIsotopic)
            {
                if (iso1.Count == 0)
                {
                    iso1 = iso0;
                }

                if (iso2.Count == 0)
                {
                    iso2 = iso1;
                }

                AddFilter(items, iso1, IsotopicConsts.AVERAGE_ISOTOPIC_MASS, 2);
                AddFilter(items, iso2, IsotopicConsts.DOUBLE_AVERAGE_ISOTOPIC_MASS, 1);
            }

            return(new FixedPrecursorPPMFilter(items));
        }
コード例 #21
0
 public void WriteToFile(string dtaFilename, PeakList <T> t)
 {
     using (var sw = new StreamWriter(dtaFilename))
     {
         sw.WriteLine(MyConvert.Format("{0:0.####}\t{1}", PrecursorUtils.MzToMH(t.PrecursorMZ, t.PrecursorCharge, true),
                                       t.PrecursorCharge));
         foreach (T peak in t)
         {
             sw.WriteLine(MyConvert.Format("{0:0.####} {1:0.#}", peak.Mz, peak.Intensity));
         }
     }
 }
        private ChromatographProfileScan FindEnvelope(PeakList <Peak> curPeaks, IsotopicIon[] isotopicIons, double mzTolerancePPM)
        {
            var result = new ChromatographProfileScan();

            result.Scan          = curPeaks.FirstScan;
            result.RetentionTime = curPeaks.ScanTimes[0].RetentionTime;
            int peakIndex = 0;

            foreach (var peak in isotopicIons)
            {
                Peak findPeak = null;
                while (peakIndex < curPeaks.Count)
                {
                    var curPeak = curPeaks[peakIndex];
                    if (curPeak.Mz < peak.MinimumMzWithinTolerance)
                    {
                        peakIndex++;
                        continue;
                    }

                    if (curPeak.Mz > peak.MaximumMzWithinTolerance)
                    {
                        break;
                    }

                    if (findPeak == null || findPeak.Intensity < curPeak.Intensity)
                    {
                        findPeak = curPeak;
                    }

                    peakIndex++;
                }

                if (findPeak == null)
                {
                    break;
                }
                else
                {
                    result.Add(new ChromatographProfileScanPeak()
                    {
                        Mz          = findPeak.Mz,
                        Intensity   = findPeak.Intensity,
                        Charge      = findPeak.Charge,
                        Noise       = findPeak.Noise,
                        PPMDistance = PrecursorUtils.mz2ppm(findPeak.Mz, findPeak.Mz - peak.Mz)
                    });
                }
            }

            return(result);
        }
        protected override void PrepareBeforeProcessing(string peptideFile)
        {
            Progress.SetMessage("Reading peptides from " + peptideFile);

            var peptides = new MascotPeptideTextFormat().ReadFromFile(peptideFile);

            var expMap = peptides.GroupBy(m => m.Query.FileScan.Experimental).ToDictionary(m => m.Key);

            expPPMMap = (from exp in expMap
                         let mean = Statistics.Mean(from pep in exp.Value select PrecursorUtils.mz2ppm(pep.TheoreticalMass, pep.TheoreticalMinusExperimentalMass))
                                    orderby exp.Key descending
                                    select new Pair <string, double>(exp.Key, mean)).ToList();
        }
コード例 #24
0
        public void CalculatePPMToMaxIntensity()
        {
            foreach (var dic in Peaks.Values)
            {
                var maxIntensityPeak = (from p in dic.Values
                                        orderby p.Intensity descending
                                        select p).FirstOrDefault();

                foreach (var peak in dic.Values)
                {
                    peak.PPM = PrecursorUtils.mz2ppm(peak.Mz, peak.Mz - maxIntensityPeak.Mz);
                }
            }
        }
コード例 #25
0
        public static double GetPrecursorPercentage(this PeakList <Peak> isolationPeaks, double ppmTolerance)
        {
            var defaultValue = 0.0;

            if (isolationPeaks.Count == 0)
            {
                return(defaultValue);
            }

            //parentPkl.ForEach(m => Console.WriteLine("new Peak({0:0.0000},{1:0.0},{2}),",m.Mz, m.Intensity,m.Charge));

            var totalIntensity = isolationPeaks.Sum(m => m.Intensity);

            if (0.0 == totalIntensity)
            {
                throw new ArgumentException("There is no intensity information in argument isolationPeaks");
            }

            var precursorPeak = isolationPeaks.Precursor;
            var mzTolerance   = PrecursorUtils.ppm2mz(precursorPeak.MonoIsotopicMass, ppmTolerance);

            if (precursorPeak.Charge == 0)
            {
                var pPeak = isolationPeaks.FindAll(m => Math.Abs(m.Mz - precursorPeak.MonoIsotopicMass) < mzTolerance);
                if (0 == pPeak.Count)
                {
                    return(defaultValue);
                }

                var maxIntensity = pPeak.Max(m => m.Intensity);
                pPeak.Find(m => m.Intensity == maxIntensity).Tag = 1;
                return(maxIntensity / totalIntensity);
            }
            else
            {
                var pPeak = isolationPeaks.FindEnvelope(precursorPeak.MonoIsotopicMass, precursorPeak.Charge, mzTolerance, true);
                if (0 == pPeak.Count)
                {
                    return(defaultValue);
                }

                for (int i = 0; i < pPeak.Count; i++)
                {
                    pPeak[i].Tag = i + 1;
                }

                return(pPeak.GetTotalIntensity() / totalIntensity);
            }
        }
        public PeakList <T> Process(PeakList <T> t)
        {
            if (!t.Any(m => m.Charge > 0))
            {
                return(t);
            }

            Parallel.ForEach(t, m =>
            {
                if (m.Charge > 1)
                {
                    m.Mz     = m.Mz * m.Charge - Atom.H.MonoMass * (m.Charge - 1);
                    m.Charge = 1;
                }
            });

            var peaks = (from p in t
                         where p.Charge == 1
                         orderby p.Intensity
                         select p).ToList();

            var deleted = new HashSet <T>();

            while (peaks.Count > 0)
            {
                var mz          = peaks[0].Mz;
                var mzTolerance = PrecursorUtils.ppm2mz(mz, ppmTolerance);
                var minMz       = mz - mzTolerance;
                var maxMz       = mz + mzTolerance;
                var curPeaks    = (from p in peaks
                                   where p.Mz >= minMz && p.Mz <= maxMz
                                   select p).ToList();
                if (curPeaks.Count > 1)
                {
                    var nIntensity = curPeaks.Sum(m => m.Intensity);
                    var nMz        = curPeaks.Sum(m => m.Mz * m.Intensity) / nIntensity;
                    peaks[0].Mz        = nMz;
                    peaks[0].Intensity = nIntensity;
                    curPeaks.Remove(peaks[0]);
                    deleted.UnionWith(curPeaks);
                }
                peaks.RemoveAll(m => curPeaks.Contains(m));
            }

            t.RemoveAll(m => deleted.Contains(m));

            t.SortByMz();
            return(t);
        }
コード例 #27
0
        public IdentifiedSpectrumPrecursorFilter(double ppmTolerance, bool filterIsotopic)
        {
            this._ppmTolerance = ppmTolerance;

            if (filterIsotopic)
            {
                acceptFunc = m => Math.Abs(PrecursorUtils.mz2ppm(m.ExperimentalMass, m.TheoreticalMinusExperimentalMass)) <= _ppmTolerance ||
                             Math.Abs(PrecursorUtils.mz2ppm(m.ExperimentalMass, m.TheoreticalMinusExperimentalMass + IsotopicConsts.AVERAGE_ISOTOPIC_MASS)) <= _ppmTolerance ||
                             Math.Abs(PrecursorUtils.mz2ppm(m.ExperimentalMass, m.TheoreticalMinusExperimentalMass + IsotopicConsts.DOUBLE_AVERAGE_ISOTOPIC_MASS)) <= _ppmTolerance;
            }
            else
            {
                acceptFunc = m => Math.Abs(PrecursorUtils.mz2ppm(m.ExperimentalMass, m.TheoreticalMinusExperimentalMass)) <= _ppmTolerance;
            }
        }
コード例 #28
0
        public Dictionary <IsobaricChannel, double> GetChannelMzToleranceMap(double ppmTolerance)
        {
            Dictionary <IsobaricChannel, double> result;

            if (!mzToleranceMap.TryGetValue(ppmTolerance, out result))
            {
                result = new Dictionary <IsobaricChannel, double>();
                foreach (var cha in this.Channels)
                {
                    result[cha] = PrecursorUtils.ppm2mz(cha.Mz, ppmTolerance);
                }
                mzToleranceMap[ppmTolerance] = result;
            }

            return(result);
        }
        public List <IIdentifiedSpectrum> ExtractPeptides(Dictionary <string, MaxQuantModificationItem> shortModMap, string peptideFile)
        {
            var mods = MaxQuantModificationList.ReadFromFile(_option.MaxQuantModificationXml);

            var sites   = new AnnotationFormat().ReadFromFile(_option.MaxQuantSiteFile);
            var msmsIds = new HashSet <string>(from s in sites
                                               let msmsids = s.Annotations["MS/MS IDs"] as string
                                                             let msmsIdList = msmsids.Split(';')
                                                                              from msmsId in msmsIdList
                                                                              select msmsId);
            var format   = new AnnotationFormat();
            var msmsList = format.ReadFromFile(_option.MaxQuantMSMSFile);

            msmsList.RemoveAll(l => !msmsIds.Contains(l.Annotations["id"].ToString()));

            using (var sw = new StreamWriter(peptideFile))
            {
                sw.WriteLine("FileScan\tSequence\tMH+\tDiff(MH+)\tCharge\tScore\tReference\tModification\tRetentionTime");
                foreach (var msms in msmsList)
                {
                    string modification;
                    string modifiedSequence;

                    ParseModification(msms, shortModMap, mods, out modification, out modifiedSequence);

                    var mh      = double.Parse(msms.Annotations["Mass"].ToString()) + Atom.H.MonoMass;
                    var diffStr = msms.Annotations["Mass Error [ppm]"].ToString();
                    var diffmh  = diffStr.Equals("NaN") ? 0 : PrecursorUtils.ppm2mz(mh, double.Parse(diffStr));

                    sw.WriteLine("{0},{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}",
                                 msms.Annotations["Raw file"],
                                 msms.Annotations["Scan number"],
                                 modifiedSequence,
                                 mh,
                                 diffmh,
                                 msms.Annotations["Charge"],
                                 msms.Annotations["Score"],
                                 msms.Annotations["Proteins"].ToString().Replace(";", "/"),
                                 modification,
                                 msms.Annotations["Retention time"]);
                }
            }

            return(new MascotPeptideTextFormat().ReadFromFile(peptideFile));
        }
コード例 #30
0
        protected List <Pair <double, double> > GetOffsetsFromPeakList(Spectrum.PeakList <Spectrum.Peak> pkl)
        {
            var offsetValues = new List <Pair <double, double> >();

            for (int i = 0; i < monitorIons.Length; i++)
            {
                var peaks = pkl.FindAll(m => m.Charge <= 1 && m.Mz >= monitorIons[i].MinMz && m.Mz <= monitorIons[i].MaxMz);
                if (peaks.Count > 0)
                {
                    var mz = (from p in peaks
                              orderby p.Intensity descending
                              select p).First();
                    var offset = PrecursorUtils.mz2ppm(monitorIons[i].Mz, monitorIons[i].Mz - mz.Mz);
                    offsetValues.Add(new Pair <double, double>(offset, mz.Intensity));
                }
            }
            return(offsetValues);
        }