Exemplo n.º 1
0
        public override void Match(IIdentifiedPeptideResult sr)
        {
            PeakList <MatchedPeak> peaks = sr.ExperimentalPeakList;

            double minBYNeutralLossIntensity = peaks.FindMaxIntensityPeak().Intensity *minBYNeutralLossIntensityScale;

            NeutralLossCandidates candidates = new NeutralLossCandidates(sr.Peptide);

            List <MatchedPeak> byNeutralLossPeaks = GetNeutralLossPeaks(sr.GetIonSeries(), sr.ExperimentalPeakList.PrecursorCharge, candidates);

            MatchedPeakUtils.Match(peaks, byNeutralLossPeaks, PeakMzTolerance, minBYNeutralLossIntensity);
        }
        public override void Match(IIdentifiedPeptideResult sr)
        {
            PeakList <MatchedPeak> peaks = sr.ExperimentalPeakList;

            double minBYNeutralLossIntensity = peaks.FindMaxIntensityPeak().Intensity *minBYNeutralLossIntensityScale;

            NeutralLossCandidates candidates = new NeutralLossCandidates(sr.Peptide);

            List <MatchedPeak> byPhosphoNeutralLossPeaks = GetPhosphoNeutralLossPeaks(sr, candidates);

            //byPhosphoNeutralLossPeaks.ForEach(m => Console.WriteLine(m.DisplayName + "," + m.Mz));

            MatchedPeakUtils.Match(peaks, byPhosphoNeutralLossPeaks, PeakMzTolerance, minBYNeutralLossIntensity);
        }
Exemplo n.º 3
0
        public override void Match(IIdentifiedPeptideResult sr)
        {
            NeutralLossCandidates candidates = new NeutralLossCandidates(sr.Peptide);

            List <INeutralLossType> nlTypes = GetNeutralLossTypes(candidates.CanLossWater, candidates.CanLossAmmonia);

            PeakList <MatchedPeak> expPeaks = sr.ExperimentalPeakList;

            List <MatchedPeak> nlPeaks = GetNeutralLossPeaks(IonType.PRECURSOR_NEUTRAL_LOSS, new MatchedPeak(expPeaks.PrecursorMZ, 0.0, expPeaks.PrecursorCharge), nlTypes, (m => true));

            //nlPeaks.ForEach(m => Console.WriteLine(m.DisplayName + "," + m.Mz));

            double minNeutralLossIntensity = expPeaks.FindMaxIntensityPeak().Intensity *minPrecursorNeutralLossIntensityScale;

            MatchedPeakUtils.Match(expPeaks, nlPeaks, PeakMzTolerance, minNeutralLossIntensity);
        }
        private static Rectangle GetSpectrumRectangle(Graphics g2, PeakList <MatchedPeak> peaks, Rectangle rec)
        {
            MatchedPeak maxIntensityPeak = peaks.FindMaxIntensityPeak();

            MatchedPeak highestPeak = maxIntensityPeak;

            RectangleTransform rt = new RectangleTransform(rec, 1.0, highestPeak.Intensity);
            int top = rt.GetTransformY(highestPeak.Intensity);
            int highestTextLength = 0;

            if (highestPeak.Matched)
            {
                highestTextLength = 10 + (int)GetStringWidth(g2, bigFont, highestPeak.Information);
                top -= highestTextLength;
            }

            foreach (MatchedPeak peak in peaks)
            {
                if (!peak.Matched)
                {
                    continue;
                }

                int textLength  = 10 + (int)GetStringWidth(g2, bigFont, peak.Information);
                int totalLength = rt.GetTransformY(peak.Intensity) - textLength;

                if (totalLength < top)
                {
                    highestTextLength = textLength;
                    top         = totalLength;
                    highestPeak = peak;
                }
            }

            int peakIntensityLength = rec.Height - highestTextLength;
            int recHeight           = (int)(peakIntensityLength * maxIntensityPeak.Intensity / highestPeak.Intensity);

            return(new Rectangle(rec.Left, rec.Bottom - recHeight, rec.Width, recHeight));
        }
        public void DetectReporter(List <UsedChannel> list)
        {
            if (_rawPeaks == null)
            {
                throw new Exception("Assign RawPeaks first!");
            }

            this.Reporters = new Peak[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                var peak = _rawPeaks.FindMaxIntensityPeak(list[i].MinMz, list[i].MaxMz);
                if (peak == null)
                {
                    Reporters[i] = new Peak(list[i].Mz, IsobaricConsts.NULL_INTENSITY);
                }
                else
                {
                    Reporters[i] = new Peak(peak.Mz, peak.Intensity);
                }
            }
        }
        private int FindPeak <T>(List <T> peaks, int nextPeakIndex, Pair <double, double> nextMzRange, int charge) where T : IPeak
        {
            var candidates = new PeakList <T>();

            for (int i = nextPeakIndex; i < peaks.Count; i++)
            {
                if (peaks[i].Mz > nextMzRange.Second)
                {
                    break;
                }

                if (peaks[i].Mz < nextMzRange.First)
                {
                    continue;
                }

                //if peaks[i] has been assigned charge and the charge is not
                //equals the assumed charge, just ignore it.
                if (0 != peaks[i].Charge && charge != peaks[i].Charge)
                {
                    continue;
                }

                candidates.Add(peaks[i]);
            }

            if (candidates.Count > 0)
            {
                T peak = candidates.FindMaxIntensityPeak();
                return(peaks.IndexOf(peak));
            }
            else
            {
                return(-1);
            }
        }
        protected override void DoWritePeakList(IRawFile rawFile, PeakList <Peak> pkl, string rawFileName, List <string> result)
        {
            sw.Flush();
            scanIndeies.Add(new Pair <int, long>(pkl.ScanTimes[0].Scan, sw.BaseStream.Position));

            int scan          = pkl.ScanTimes[0].Scan;
            var retentionTime = pkl.ScanTimes[0].RetentionTime;

            var activationMethod = string.Empty;

            var intent = GetScanIntent(pkl.MsLevel);

            if (rawFile is RawFileImpl)
            {
                var impl = rawFile as RawFileImpl;

                var rcf = new RawScanFilter();
                rcf.Filter       = impl.GetFilterForScanNum(scan);
                activationMethod = rcf.ActivationMethod.ToUpper();

                /* scan header info begin */
                int    numPakets         = 0;
                double RT                = 0;
                double lowMass           = 0;
                double highMass          = 0;
                double TIC               = 0;
                double basePeakMass      = 0;
                double basePeakIntensity = 0;
                int    channel           = 0;
                int    uniformTime       = 0;
                double frequency         = 0;

                impl.GetScanHeaderInfoForScanNum(
                    scan,
                    ref numPakets,
                    ref RT,
                    ref lowMass,
                    ref highMass,
                    ref TIC,
                    ref basePeakMass,
                    ref basePeakIntensity,
                    ref channel,
                    ref uniformTime,
                    ref frequency);

                lowMass  = pkl.First().Mz;
                highMass = pkl.Last().Mz;

                sw.Write(MyConvert.Format(intent + "<scan num=\"{0}\"" + lf
                                          + intent + " msLevel=\"{1}\"" + lf
                                          + intent + " peaksCount=\"{2}\"" + lf
                                          + intent + " polarity=\"{3}\"" + lf
                                          + intent + " scanType=\"{4}\"" + lf
                                          + intent + " filterLine=\"{5}\"" + lf
                                          + intent + " retentionTime=\"PT{6:G6}S\"" + lf,
                                          scan,
                                          rcf.MsLevel,
                                          pkl.Count,
                                          rcf.Polarity,
                                          rcf.ScanType,
                                          rcf.Filter,
                                          retentionTime * 60));

                sw.Write(MyConvert.Format(intent + " lowMz=\"{0:G6}\"" + lf
                                          + intent + " highMz=\"{1:G6}\"" + lf
                                          + intent + " basePeakMz=\"{2:G6}\"" + lf
                                          + intent + " basePeakIntensity=\"{3:e5}\"" + lf
                                          + intent + " totIonCurrent=\"{4:e5}\" >" + lf,
                                          lowMass,
                                          highMass,
                                          basePeakMass,
                                          basePeakIntensity,
                                          TIC));

                if (rcf.MsLevel > 1)
                {
                    sw.Write(intent + " collisionEnergy=\"{0:0}\"" + lf, rcf.CollisionEnergy);
                }

                pkl.PrecursorIntensity = impl.GetPrecursorPeak(scan).Intensity;
            }
            else
            {
                sw.Write(MyConvert.Format(intent + "<scan num=\"{0}\"" + lf
                                          + intent + " msLevel=\"{1}\"" + lf
                                          + intent + " peaksCount=\"{2}\"" + lf
                                          + intent + " scanType=\"{3}\"" + lf
                                          + intent + " retentionTime=\"PT{4:G8}S\"" + lf,
                                          scan,
                                          pkl.MsLevel,
                                          pkl.Count,
                                          pkl.ScanMode,
                                          retentionTime * 60));

                var basePeak = pkl.FindMaxIntensityPeak();
                var TIC      = pkl.Sum(m => m.Intensity);

                sw.Write(MyConvert.Format(intent + " lowMz=\"{0:0}\"" + lf
                                          + intent + " highMz=\"{1:0}\"" + lf
                                          + intent + " basePeakMz=\"{2:G6}\"" + lf
                                          + intent + " basePeakIntensity=\"{3:e5}\"" + lf
                                          + intent + " totIonCurrent=\"{4:e5}\" >" + lf,
                                          pkl.First().Mz,
                                          pkl.Last().Mz,
                                          basePeak.Mz,
                                          basePeak.Intensity,
                                          TIC));
            }

            if (pkl.MsLevel > 1)
            {
                sw.Write(MyConvert.Format(intent + " <precursorMz precursorIntensity=\"{0:0.#####}\"", pkl.PrecursorIntensity));

                if (!string.IsNullOrEmpty(activationMethod))
                {
                    sw.Write(" activationMethod=\"{0}\"", activationMethod);
                }
                if (pkl.PrecursorCharge > 0)
                {
                    sw.Write(" precursorCharge=\"{0}\"", pkl.PrecursorCharge);
                }

                sw.Write(" >");
                sw.Write(MyConvert.Format("{0:0.######}</precursorMz>" + lf, pkl.PrecursorMZ));
            }
            /* scan header info end */

            /* peak list info begin */
            sw.WriteLine(intent + " <peaks precision=\"32\"");
            sw.WriteLine(intent + "  byteOrder=\"network\"");
            sw.WriteLine(intent + "  contentType=\"m/z-int\"");
            sw.WriteLine(intent + "  compressionType=\"none\"");
            sw.WriteLine(intent + "  compressedLen=\"0\" >" + MzxmlHelper.PeakListToBase64(pkl) + "</peaks>");
            /* peak list info end */
        }
Exemplo n.º 8
0
        public List <PrecursorItem> QueryPrecursorFromProductIon(QueryItem productIon, double ppmProductTolerance, double ppmPrecursorTolerance)
        {
            List <PrecursorItem> result = new List <PrecursorItem>();

            int firstScan = reader.GetFirstSpectrumNumber();
            int lastScan  = reader.GetLastSpectrumNumber();

            double mzTolerance = PrecursorUtils.ppm2mz(productIon.ProductIonMz, ppmProductTolerance);

            PeakList <Peak> lastFullScan = new PeakList <Peak>();

            Progress.SetRange(firstScan, lastScan);
            for (int scan = firstScan; scan <= lastScan; scan++)
            {
                Progress.SetPosition(scan);

                if (Progress.IsCancellationPending())
                {
                    throw new UserTerminatedException();
                }

                //ignore ms 1
                if (reader.GetMsLevel(scan) == 1)
                {
                    lastFullScan = ReadScan(scan);
                    continue;
                }

                //read all peaks
                PeakList <Peak> pkl = ReadScan(scan);

                //find product ions
                PeakList <Peak> productIons = pkl.FindPeak(productIon.ProductIonMz, mzTolerance);

                if (productIons.Count == 0)
                {
                    continue;
                }

                //get minimum product ion intensity
                double maxIntensity      = pkl.FindMaxIntensityPeak().Intensity;
                double relativeIntensity = productIons.FindMaxIntensityPeak().Intensity / maxIntensity;
                if (relativeIntensity < productIon.MinRelativeIntensity)
                {
                    continue;
                }

                Peak peak = reader.GetPrecursorPeak(scan);

                double precursorMzTolerance = PrecursorUtils.ppm2mz(peak.Mz, ppmPrecursorTolerance);

                var precursorPkl = lastFullScan.FindPeak(peak.Mz, precursorMzTolerance);

                bool isotopic = false;
                if (precursorPkl.Count == 0)
                {
                    isotopic     = true;
                    precursorPkl = lastFullScan.FindPeak(peak.Mz - 1.0, precursorMzTolerance);
                }

                if (precursorPkl.Count == 0)
                {
                    precursorPkl = lastFullScan.FindPeak(peak.Mz + 1.0, precursorMzTolerance);
                }

                var precursorInFullMs = precursorPkl.FindMaxIntensityPeak();

                var precursor = new PrecursorItem()
                {
                    Scan = scan,
                    ProductIonRelativeIntensity = relativeIntensity
                };

                if (isotopic && precursorInFullMs != null)
                {
                    precursor.PrecursorMZ = precursorInFullMs.Mz;
                    precursor.IsIsotopic  = true;
                }
                else
                {
                    precursor.PrecursorMZ = peak.Mz;
                    precursor.IsIsotopic  = false;
                }

                if (precursorInFullMs != null)
                {
                    precursor.PrecursorIntensity = precursorInFullMs.Intensity;
                }

                result.Add(precursor);
            }

            var precursorMzs = from item in result
                               group item by item.PrecursorMZ into mzGroup
                               let mzcount = mzGroup.Where(m => m.PrecursorIntensity > 0).Count()
                                             orderby mzcount descending
                                             select mzGroup.Key;

            foreach (var mz in precursorMzs)
            {
                double mzPrecursorTolerance = PrecursorUtils.ppm2mz(mz, ppmPrecursorTolerance);
                foreach (var item in result)
                {
                    if (!item.IsIsotopic)
                    {
                        continue;
                    }

                    if (Math.Abs(item.PrecursorMZ - mz) <= mzPrecursorTolerance)
                    {
                        item.PrecursorMZ = mz;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        public List <LabelFreeItem> QueryChromotograph(double precursorMz, double ppmTolerance)
        {
            var result = new List <LabelFreeItem>();

            int firstScan = reader.GetFirstSpectrumNumber();
            int lastScan  = reader.GetLastSpectrumNumber();

            double mzTolerance = PrecursorUtils.ppm2mz(precursorMz, ppmTolerance);

            Progress.SetRange(firstScan, lastScan);

            bool bAppend = false;

            for (int scan = firstScan; scan <= lastScan; scan++)
            {
                Progress.SetPosition(scan);

                if (Progress.IsCancellationPending())
                {
                    throw new UserTerminatedException();
                }

                //ignore ms 2
                if (reader.GetMsLevel(scan) != 1)
                {
                    continue;
                }

                //read all peaks
                PeakList <Peak> pkl = ReadScan(scan);

                //find product ions
                PeakList <Peak> precursorIons = pkl.FindPeak(precursorMz, mzTolerance);

                if (precursorIons.Count == 0)
                {
                    if (bAppend)
                    {
                        result.Add(new LabelFreeItem()
                        {
                            Scan          = scan,
                            RetentionTime = pkl.ScanTimes[0].RetentionTime,
                            Mz            = precursorMz,
                            Intensity     = 0.0
                        });
                    }
                }
                else
                {
                    bAppend = true;
                    var peak = precursorIons.FindMaxIntensityPeak();

                    result.Add(new LabelFreeItem()
                    {
                        Scan          = scan,
                        RetentionTime = pkl.ScanTimes[0].RetentionTime,
                        Mz            = peak.Mz,
                        Intensity     = peak.Intensity
                    });
                }
            }

            while (result.Count > 0 && result[result.Count - 1].Intensity == 0)
            {
                result.RemoveAt(result.Count - 1);
            }

            return(result);
        }