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);
            }
        }
Ejemplo n.º 2
0
        private SilacPeakListPair GetLightHeavyPeakList(IRawFile rawFile, SilacCompoundInfo sci, int maxIndex, double mzTolerance, int scan, bool force = false)
        {
            PeakList <Peak> pkl = rawFile.GetPeakList(scan);

            if (pkl.Count == 0)
            {
                return(null);
            }

            var scantime = new ScanTime(scan, rawFile.ScanToRetentionTime(scan));

            PeakList <Peak> light = pkl.FindEnvelopeDirectly(sci.Light.Profile, option.ProfileLength, mzTolerance, () => new Peak());

            //如果电荷不对,则认为该scan无效。
            if (!CheckPeakListCharge(light, maxIndex, sci.Light.Charge) && !force)
            {
                return(null);
            }

            PeakList <Peak> heavy = pkl.FindEnvelopeDirectly(sci.Heavy.Profile, option.ProfileLength, mzTolerance, () => new Peak());

            //如果电荷不对,则认为该scan无效。
            if (!CheckPeakListCharge(heavy, maxIndex, sci.Heavy.Charge) && !force)
            {
                return(null);
            }

            //如果轻或者重的总强度为0,则认为该scan无效。
            if ((0 == light.Sum(m => m.Intensity) || 0 == heavy.Sum(m => m.Intensity)) && !force)
            {
                return(null);
            }

            light.ScanTimes.Add(scantime);
            heavy.ScanTimes.Add(scantime);

            return(new SilacPeakListPair(light, heavy));
        }
        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 */
        }