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);
        }
Exemple #2
0
        private O18QuanEnvelope GetCorrespondingEnvelope(IRawFile rawFile, double theoreticalMz, int charge, double mzTolerance, int scan)
        {
            PeakList <Peak> pkl = rawFile.GetPeakList(scan);

            if (pkl.ScanTimes.Count == 0)
            {
                pkl.ScanTimes.Add(new ScanTime(scan, rawFile.ScanToRetentionTime(scan)));
            }

            PeakList <Peak> O16 = pkl.FindEnvelopeDirectly(theoreticalMz, charge, mzTolerance, 4, () => new Peak());

            PeakList <Peak> O181 = pkl.FindEnvelopeDirectly(theoreticalMz + chargeGapMap1[charge], charge, mzTolerance, 2, () => new Peak());

            for (int i = 2; i < 4; i++)
            {
                if (O16[i].Intensity < O181[i - 2].Intensity)
                {
                    O16[i].Mz        = O181[i - 2].Mz;
                    O16[i].Intensity = O181[i - 2].Intensity;
                }
            }

            PeakList <Peak> O182 = pkl.FindEnvelopeDirectly(theoreticalMz + chargeGapMap2[charge], charge, mzTolerance, 2, () => new Peak());

            O16.AddRange(O182);

            return(new O18QuanEnvelope(O16));
        }
        public void TestGetPeakList()
        {
            PeakList <Peak> pkl = reader.GetPeakList(1);

            Assert.AreEqual(397, pkl.Count);
            Assert.AreEqual(301.1257, pkl[0].Mz, 0.0001);
        }
Exemple #4
0
        private Spectrum.PeakList <Spectrum.Peak> GetPeakList(int scan)
        {
            var s1    = reader.GetPeakList(scan);
            var s1max = s1.Max(l => l.Intensity);

            s1.ForEach(m => m.Intensity = m.Intensity * 100.0 / s1max);
            return(s1);
        }
Exemple #5
0
        private PeakList <Peak> ReadScan(int scan)
        {
            if (pklMap.ContainsKey(scan))
            {
                return(pklMap[scan]);
            }

            PeakList <Peak> pkl = reader.GetPeakList(scan);

            pkl.ScanTimes.Clear();
            pkl.ScanTimes.Add(new ScanTime(scan, reader.ScanToRetentionTime(scan)));
            pklMap[scan] = pkl;
            return(pkl);
        }
Exemple #6
0
        public static List <PeakList <Peak> > GetMS1List(this IRawFile reader)
        {
            var result = new List <PeakList <Peak> >();
            var first  = reader.GetFirstSpectrumNumber();
            var last   = reader.GetLastSpectrumNumber();

            for (int i = first; i <= last; i++)
            {
                var mslevel = reader.GetMsLevel(i);
                if (mslevel == 1)
                {
                    var pkl = reader.GetPeakList(i);
                    result.Add(pkl);
                }
            }
            return(result);
        }
Exemple #7
0
        protected void DoGetOffsets(List <OffsetEntry> result, IRawFile reader, string msg)
        {
            var firstScan = reader.GetFirstSpectrumNumber();
            var lastScan  = reader.GetLastSpectrumNumber();

            SetMessage(msg);
            SetRange(firstScan, lastScan);

            for (int scan = firstScan; scan <= lastScan; scan++)
            {
                if (reader.GetMsLevel(scan) == 1)
                {
                    SetPosition(scan);

                    if (IsLoopStopped)
                    {
                        return;
                    }

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

                    var pkl = reader.GetPeakList(scan);
                    var rt  = reader.ScanToRetentionTime(scan);

                    var offsetValues = GetOffsetsFromPeakList(pkl);

                    if (offsetValues.Count > 0)
                    {
                        var weightedPPM = GetWeightedPPM(offsetValues);
                        result.Add(new OffsetEntry(scan, rt, weightedPPM, offsetValues.Count));
                    }
                    else
                    {
                        result.Add(new OffsetEntry(scan, rt, 0, 0));
                    }
                }
            }
            CalculateOffset(result, m => m.InitValue);
        }
        private bool AddPeaks(IRawFile rawReader, int scan, SimplePeakChro chro, bool bIdentified)
        {
            var pkl = rawReader.GetPeakList(scan, chro.Mz - chro.MzTolerance, chro.Mz + chro.MzTolerance);

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

            var p = (from o in pkl
                     where (o.Charge == chro.Charge) || (o.Charge == 0)
                     orderby o.Intensity descending
                     select o).FirstOrDefault();

            if (null == p)
            {
                return(false);
            }

            var iit = rawReader.GetIonInjectionTime(scan);

            if (iit <= 0)
            {
                iit = 1.0;
            }

            chro.Peaks.Add(new ScanPeak()
            {
                Mz               = p.Mz,
                Intensity        = p.Intensity,
                Charge           = p.Charge,
                Scan             = scan,
                RetentionTime    = rawReader.ScanToRetentionTime(scan),
                IonInjectionTime = iit,
                Identified       = bIdentified
            });

            return(true);
        }
Exemple #9
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));
        }
        public FileData3 ReadFromFile(string fileName)
        {
            FileData3 result = new FileData3();

            result.FileName = new FileInfo(fileName).Name;

            rawFile.Open(fileName);
            try
            {
                for (int scan = rawFile.GetFirstSpectrumNumber(); scan <= rawFile.GetLastSpectrumNumber(); scan++)
                {
                    PeakList <Peak> pkl = rawFile.GetPeakList(scan, minPeakMz - 1, maxPeakMz + 1);

                    result.AddPeaks(minPeakMz, maxPeakMz, scan, pkl);
                }
            }
            finally
            {
                rawFile.Close();
            }

            return(result);
        }
        public override IEnumerable <string> Process(string fileName)
        {
            string resultFile = new FileInfo(targetDir + "\\" + FileUtils.ChangeExtension(new FileInfo(fileName).Name, ".txt")).FullName;

            reader.Open(fileName);
            try
            {
                using (StreamWriter sw = new StreamWriter(resultFile))
                {
                    sw.NewLine = "\n";
                    sw.WriteLine();
                    sw.WriteLine("FUNCTION 1");

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

                    for (int i = firstScan; i <= lastScan; i++)
                    {
                        var pkl = reader.GetPeakList(i);
                        sw.WriteLine("");
                        sw.WriteLine("Scan\t\t{0}", i);
                        sw.WriteLine("Retention Time\t{0:0.000}", reader.ScanToRetentionTime(i));
                        sw.WriteLine("");
                        foreach (var peak in pkl)
                        {
                            sw.WriteLine("{0:0.0000}\t{1:0}", peak.Mz, peak.Intensity);
                        }
                    }
                }
            }
            finally
            {
                reader.Close();
            }
            return(new string[] { resultFile });
        }
        public void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            var summary = e.Item as SilacQuantificationSummaryItem;

            if (summary == null)
            {
                throw new ArgumentNullException("UpdateQuantificationItemEventArgs.Item cannot be null");
            }

            ZedGraphicExtension.ClearData(zgcGraph, false);
            try
            {
                var envelope = summary.ObservedEnvelopes.Find(m => m.IsSelected);
                if (envelope == null)
                {
                    return;
                }

                double minMz = envelope.Light[0].Mz - 1.0;
                double maxMz = envelope.Heavy[envelope.Heavy.Count - 1].Mz + 1.0;

                zgcGraph.GraphPane.XAxis.Scale.Min = minMz;
                zgcGraph.GraphPane.XAxis.Scale.Max = maxMz;

                var pplLight = new PointPairList();
                envelope.Light.ForEach(p => pplLight.Add(p.Mz, p.Intensity));

                var pplHeavy = new PointPairList();
                envelope.Heavy.ForEach(p => pplHeavy.Add(p.Mz, p.Intensity));

                if (summary.SampleIsLight)
                {
                    ZedGraphicExtension.AddIndividualLine(zgcGraph, "Sample", pplLight, SilacQuantificationConstants.SAMPLE_COLOR, false);
                    ZedGraphicExtension.AddIndividualLine(zgcGraph, "Reference", pplHeavy, SilacQuantificationConstants.REFERENCE_COLOR, false);
                }
                else
                {
                    ZedGraphicExtension.AddIndividualLine(zgcGraph, "Sample", pplHeavy, SilacQuantificationConstants.SAMPLE_COLOR, false);
                    ZedGraphicExtension.AddIndividualLine(zgcGraph, "Reference", pplLight, SilacQuantificationConstants.REFERENCE_COLOR, false);
                }

                // Shift the text items up by 5 user scale units above the bars
                const float shift = 5;

                var ppl = new PointPairList();
                ppl.AddRange(pplLight);
                ppl.AddRange(pplHeavy);
                for (int i = 0; i < ppl.Count; i++)
                {
                    // format the label string to have 1 decimal place
                    string lab = ppl[i].X.ToString("0.00");
                    // create the text item (assumes the x axis is ordinal or text)
                    // for negative bars, the label appears just above the zero value
                    var text = new TextObj(lab, ppl[i].X, ppl[i].Y + shift);
                    // tell Zedgraph to use user scale units for locating the TextItem
                    text.Location.CoordinateFrame = CoordType.AxisXYScale;
                    // AlignH the left-center of the text to the specified point
                    text.Location.AlignH           = AlignH.Left;
                    text.Location.AlignV           = AlignV.Center;
                    text.FontSpec.Border.IsVisible = false;
                    text.FontSpec.Fill.IsVisible   = false;
                    // rotate the text 90 degrees
                    text.FontSpec.Angle = 90;
                    // add the TextItem to the list
                    zgcGraph.GraphPane.GraphObjList.Add(text);
                }

                if (File.Exists(summary.RawFilename))
                {
                    if (rawFile == null)
                    {
                        rawFile = new RawFileImpl(summary.RawFilename);
                    }
                    else if (!rawFile.FileName.Equals(summary.RawFilename))
                    {
                        rawFile.Open(summary.RawFilename);
                    }

                    PeakList <Peak> pkl    = rawFile.GetPeakList(envelope.Light.ScanTimes[0].Scan);
                    var             pplRaw = new PointPairList();
                    pplRaw.Add(minMz, 0.0);
                    for (int i = 0; i < pkl.Count; i++)
                    {
                        if (pkl[i].Mz < minMz)
                        {
                            continue;
                        }
                        else if (pkl[i].Mz > maxMz)
                        {
                            break;
                        }
                        pplRaw.Add(pkl[i].Mz, -pkl[i].Intensity);
                    }
                    pplRaw.Add(maxMz, 0.0);

                    ZedGraphicExtension.AddIndividualLine(zgcGraph, "PeakList From RawFile", pplRaw, SilacQuantificationConstants.IDENTIFIED_COLOR, true);
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(zgcGraph);
            }
        }
Exemple #13
0
        private List <SrmScan> GetMRMScans(string directory)
        {
            var fileName = GetPeakFileName(directory);

            if (File.Exists(fileName))
            {
                SetProgressMessage("Reading scan from " + fileName + " ...");
                return(new SrmScanFileFormat().ReadFromFile(fileName));
            }
            else
            {
                List <PeakList <Peak> > pkls = new List <PeakList <Peak> >();

                SetProgressMessage("Reading scan from " + directory + " ...");
                IRawFile reader = RawFileFactory.GetRawFileReader(directory);
                try
                {
                    var firstCount = reader.GetFirstSpectrumNumber();
                    var lastCount  = reader.GetLastSpectrumNumber();

                    Progress.SetRange(firstCount, lastCount);
                    Progress.SetPosition(firstCount);
                    for (int i = firstCount; i <= lastCount; i++)
                    {
                        if (reader.GetMsLevel(i) != 2)
                        {
                            continue;
                        }

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

                        Progress.Increment(1);

                        var pkl       = reader.GetPeakList(i);
                        var precursor = reader.GetPrecursorPeak(i);
                        if (precursor != null)
                        {
                            pkl.PrecursorMZ     = precursor.Mz;
                            pkl.PrecursorCharge = precursor.Charge;
                        }
                        pkl.ScanTimes.Add(new ScanTime(i, reader.ScanToRetentionTime(i)));

                        pkls.Add(pkl);
                    }

                    List <SrmScan> result = new List <SrmScan>();

                    pkls.ForEach(m => m.ForEach(n => result.Add(new SrmScan(m.PrecursorMZ, n.Mz, m.ScanTimes[0].RetentionTime, n.Intensity, true))));

                    new SrmScanFileFormat().WriteToFile(fileName, result);

                    SetProgressMessage("finished.");

                    return(result);
                }
                finally
                {
                    reader.Close();
                }
            }
        }
        public override IEnumerable <string> Process(string targetDir)
        {
            foreach (var raw in rawFiles)
            {
                List <RetentionTimePeak> waitingPeaks = new List <RetentionTimePeak>();
                foreach (var peak in targetPeaks)
                {
                    string file = GetTargetFile(targetDir, raw, peak);
                    if (force || !File.Exists(file))
                    {
                        waitingPeaks.Add(peak);
                    }
                }

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

                rawReader.Open(raw);
                try
                {
                    int firstScan = rawReader.GetFirstSpectrumNumber();
                    int lastScan  = rawReader.GetLastSpectrumNumber();

                    waitingPeaks.ForEach(m => m.Chromotographs.Clear());

                    for (int scan = firstScan; scan <= lastScan; scan++)
                    {
                        if (rawReader.GetMsLevel(scan) != 1)
                        {
                            continue;
                        }

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

                        PeakList <Peak> pkl = rawReader.GetPeakList(scan);

                        double rt = rawReader.ScanToRetentionTime(scan);
                        var    st = new ScanTime(scan, rt);

                        foreach (var peak in waitingPeaks)
                        {
                            var env = pkl.FindEnvelopeDirectly(peak.PeakEnvelope, peak.MzTolerance, () => new Peak());
                            env.ScanTimes.Add(st);
                            peak.Chromotographs.Add(env);
                        }
                    }

                    waitingPeaks.ForEach(m => m.TrimPeaks());
                }
                finally
                {
                    rawReader.Close();
                }

                foreach (var peak in waitingPeaks)
                {
                    string file = GetTargetFile(targetDir, raw, peak);
                    new RetentionTimePeakXmlFormat().WriteToFile(file, peak);
                }
            }

            return(new string[] { targetDir });
        }
Exemple #15
0
        public override IEnumerable <string> Process(string rawFilename)
        {
            string ms1Filename      = GetResultFilename(rawFilename);
            string ms1IndexFilename = ms1Filename + ".index";

            rawFile.Open(rawFilename);
            try
            {
                int firstScan = rawFile.GetFirstSpectrumNumber();
                int lastScan  = rawFile.GetLastSpectrumNumber();

                int firstFullScan = 0;
                for (firstFullScan = firstScan; firstFullScan < lastScan; firstFullScan++)
                {
                    if (rawFile.GetMsLevel(firstFullScan) == 1)
                    {
                        break;
                    }
                }

                if (firstFullScan >= lastScan)
                {
                    return(new List <string>());
                }

                Progress.SetRange(firstScan, lastScan);

                using (var sw = new StreamWriter(ms1Filename))
                {
                    //write header
                    sw.Write("H\tCreationDate\t{0:m/dd/yyyy HH:mm:ss}\n", DateTime.Now);
                    sw.Write("H\tExtractor\t{0}\n", GetProgramName());
                    sw.Write("H\tExtractorVersion\t{0}\n", GetProgramVersion());
                    sw.Write("H\tComments\t{0} written by Quanhu Sheng, 2008-2009\n", GetProgramName());
                    sw.Write("H\tExtractorOptions\tMS1\n");
                    sw.Write("H\tAcquisitionMethod\tData-Dependent\n");
                    sw.Write("H\tDataType\tCentriod\n");
                    sw.Write("H\tScanType\tMS1\n");
                    sw.Write("H\tFirstScan\t{0}\n", firstScan);
                    sw.Write("H\tLastScan\t{0}\n", lastScan);

                    using (var swIndex = new StreamWriter(ms1IndexFilename))
                    {
                        for (int scan = firstScan; scan <= lastScan; scan++)
                        {
                            if (Progress.IsCancellationPending())
                            {
                                throw new UserTerminatedException();
                            }

                            Progress.SetPosition(scan);

                            if (rawFile.GetMsLevel(scan) == 1)
                            {
                                sw.Flush();

                                swIndex.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", rawFile.ScanToRetentionTime(scan));

                                PeakList <Peak> pkl = rawFile.GetPeakList(scan);
                                foreach (Peak p in pkl)
                                {
                                    sw.Write("{0:0.0000} {1:0.0} {2}\n", p.Mz, p.Intensity, p.Charge);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                rawFile.Close();
            }

            Progress.End();

            return(new[] { ms1Filename });
        }
Exemple #16
0
        public override IEnumerable <string> Process(string targetDir)
        {
            foreach (var raw in rawFiles)
            {
                List <SimplePeakChro> waitingPeaks = new List <SimplePeakChro>();
                foreach (var peak in targetPeaks)
                {
                    string file = GetTargetFile(targetDir, raw, peak);
                    if (force || !File.Exists(file))
                    {
                        waitingPeaks.Add(peak);
                    }
                    else
                    {
                        var p = new SimplePeakChroXmlFormat().ReadFromFile(file);
                        peak.MaxRetentionTime = p.MaxRetentionTime;
                        peak.Peaks            = p.Peaks;
                    }
                }

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

                rawReader.Open(raw);
                try
                {
                    int firstScan = rawReader.GetFirstSpectrumNumber();
                    int lastScan  = rawReader.GetLastSpectrumNumber();

                    var lastRt = rawReader.ScanToRetentionTime(lastScan);

                    waitingPeaks.ForEach(m =>
                    {
                        m.Peaks.Clear();
                        m.MaxRetentionTime = lastRt;
                    });

                    Progress.SetMessage("Processing chromotograph extracting...");
                    Progress.SetRange(firstScan, lastScan);
                    for (int scan = firstScan; scan <= lastScan; scan++)
                    {
                        if (rawReader.GetMsLevel(scan) != 1)
                        {
                            continue;
                        }
                        Progress.SetPosition(scan);

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

                        PeakList <Peak> pkl = rawReader.GetPeakList(scan);
                        double          rt  = rawReader.ScanToRetentionTime(scan);

                        foreach (var peak in waitingPeaks)
                        {
                            var env = pkl.FindPeak(peak.Mz, peak.MzTolerance);

                            Peak findPeak = new Peak(peak.Mz, 0.0, 0);
                            if (env.Count > 0)
                            {
                                if (env.Count == 1)
                                {
                                    findPeak = env[0];
                                }
                                else
                                {
                                    var charge = env.FindCharge(peak.Charge);
                                    if (charge.Count > 0)
                                    {
                                        if (charge.Count == 1)
                                        {
                                            findPeak = charge[0];
                                        }
                                        else
                                        {
                                            findPeak = charge.FindMaxIntensityPeak();
                                        }
                                    }
                                    else
                                    {
                                        findPeak = env.FindMaxIntensityPeak();
                                    }
                                }
                            }

                            peak.Peaks.Add(new ScanPeak()
                            {
                                Mz            = findPeak.Mz,
                                Intensity     = findPeak.Intensity,
                                Scan          = scan,
                                RetentionTime = rt,
                                Charge        = findPeak.Charge,
                                PPMDistance   = PrecursorUtils.mz2ppm(peak.Mz, findPeak.Mz - peak.Mz)
                            });
                        }
                    }

                    waitingPeaks.ForEach(m => m.TrimPeaks(minRetentionTime));
                }
                finally
                {
                    rawReader.Close();
                }

                Progress.SetMessage("Saving ... ");
                foreach (var peak in waitingPeaks)
                {
                    string file = GetTargetFile(targetDir, raw, peak);
                    new SimplePeakChroXmlFormat().WriteToFile(file, peak);
                }
                Progress.SetMessage("Finished.");
                Progress.End();
            }

            return(new string[] { targetDir });
        }
        public override void Update(object sender, UpdateQuantificationItemEventArgs e)
        {
            var summary = e.Item as O18QuantificationSummaryItem;

            if (summary == null)
            {
                throw new ArgumentNullException("UpdateQuantificationItemEventArgs.Item cannot be null");
            }

            panel.InitGraphPane(this.title, "m/z", "Intensity", true, 0.0);

            ZedGraphicExtension.ClearData(zgcGraph, false);
            try
            {
                var envelope = summary.ObservedEnvelopes.Find(m => m.IsSelected);
                if (envelope == null)
                {
                    return;
                }

                panel.InitGraphPane(this.title + ", Scan=" + envelope.Scan.ToString(), "m/z", "Intensity", true, 0.0);

                double minMz = envelope[0].Mz - 1.0;
                double maxMz = envelope[envelope.Count - 1].Mz + 1.0;

                zgcGraph.GraphPane.XAxis.Scale.Min = minMz;
                zgcGraph.GraphPane.XAxis.Scale.Max = maxMz;

                var ppl = new PointPairList();
                envelope.ForEach(p => { if (p.Intensity > 0)
                                        {
                                            ppl.Add(p.Mz, p.Intensity);
                                        }
                                 });
                panel.AddIndividualLine("Isotopic Envelope", ppl, Color.Red);
                panel.AddTextUp(ppl, 5, (m => m.X.ToString("0.0000")));

                var halfMax = (from env in envelope
                               select env.Intensity).Max() / 2;
                ppl.Clear();
                envelope.ForEach(p => { if (p.Intensity == 0)
                                        {
                                            ppl.Add(p.Mz, halfMax);
                                        }
                                 });
                panel.AddIndividualLine("", ppl, defaultColor: Color.Red, dStyle: DashStyle.Dash);
                panel.AddTextUp(ppl, 5, (m => m.X.ToString("0.0000")));

                if (File.Exists(summary.RawFilename))
                {
                    if (rawFile == null)
                    {
                        rawFile = RawFileFactory.GetRawFileReader(summary.RawFilename);
                    }
                    else if (!rawFile.FileName.Equals(summary.RawFilename))
                    {
                        rawFile.Close();
                        rawFile = RawFileFactory.GetRawFileReader(summary.RawFilename);
                    }

                    PeakList <Peak> pkl    = rawFile.GetPeakList(envelope.ScanTimes[0].Scan);
                    var             pplRaw = new PointPairList();
                    for (int i = 0; i < pkl.Count; i++)
                    {
                        if (pkl[i].Mz < minMz)
                        {
                            continue;
                        }
                        else if (pkl[i].Mz > maxMz)
                        {
                            break;
                        }
                        pplRaw.Add(pkl[i].Mz, -pkl[i].Intensity);
                    }

                    panel.AddIndividualLine("PeakList From RawFile", pplRaw, Color.Blue);
                    panel.AddTextDown(pplRaw, 5, (m => m.X.ToString("0.0000")));

                    /*
                     * foreach (var p in ppl)
                     * {
                     * if (p.Y == 0)
                     * {
                     *  double ppm = double.MaxValue;
                     *  double ppmAbs = Math.Abs(ppm);
                     *  foreach (var pp in pplRaw)
                     *  {
                     *    double ppmCur = PrecursorUtils.mz2ppm(pp.X, pp.X - p.X);
                     *    double ppmCurAbs = Math.Abs(ppmCur);
                     *    if (Math.Abs(ppmCur) < ppmAbs)
                     *    {
                     *      ppm = ppmCur;
                     *      ppmAbs = ppmCurAbs;
                     *    }
                     *
                     *    if (pp.X > p.X)
                     *    {
                     *      break;
                     *    }
                     *  }
                     *
                     *  p.Z = ppm;
                     * }
                     * }
                     */
                }
            }
            finally
            {
                ZedGraphicExtension.UpdateGraph(zgcGraph);
            }
        }