public PeakList <Peak> GetPeakList(int scan)
        {
            if (cachePeaks.ContainsKey(scan))
            {
                return(cachePeaks[scan]);
            }

            return(rawFile.GetPeakList(scan));
        }
        public static PeakList <Peak> GetPeakInIsolationWindow(this IRawFile2 RawReader, int scan, double defaultIsolationWidth)
        {
            PeakList <Peak> result = new PeakList <Peak>();

            var precursor = RawReader.GetPrecursorPeakWithMasterScan(scan);

            if (precursor.MasterScan == 0)
            {
                return(result);
            }

            if (0 == precursor.IsolationWidth || precursor.IsolationWidth > 5.0)
            {
                precursor.IsolationWidth = defaultIsolationWidth;
            }

            var isolationWidth = precursor.IsolationWidth /= 2;

            var minMz = precursor.IsolationMass - isolationWidth;
            var maxMz = precursor.IsolationMass + isolationWidth;

            result           = RawReader.GetPeakList(precursor.MasterScan, minMz, maxMz);
            result.Precursor = precursor;

            return(result);
        }
Ejemplo n.º 3
0
        protected void AppendScan(IRawFile2 rawReader, List <IsobaricScan> result, int scan, string mode, double isolationWidth)
        {
            IsobaricScan item = new IsobaricScan();

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

            if (pkl.Count < MinPeakCount)
            {
                return;
            }

            var recordScan = GetIdentificationScan(scan);

            item.ScanMode = mode;
            item.RawPeaks = pkl;
            item.PeakInIsolationWindow = rawReader.GetPeakInIsolationWindow(scan, isolationWidth);
            item.Scan = rawReader.GetScanTime(recordScan);

            result.Add(item);
        }
        protected List <PeakList <Peak> > ReadTandemMassFromRaw(FileInfo rawFilename, List <int> ignoreScans)
        {
            string experimental = FileUtils.ChangeExtension(rawFilename.Name, "");

            var result = new List <PeakList <Peak> >();

            bool bReadAgain = false;

            rawReader.Open(rawFilename.FullName);
            try
            {
                int firstSpectrumNumber = rawReader.GetFirstSpectrumNumber();
                int lastSpectrumNumber  = rawReader.GetLastSpectrumNumber();

                Progress.SetRange(firstSpectrumNumber, lastSpectrumNumber);
                Progress.Begin();
                try
                {
                    for (int scan = firstSpectrumNumber; scan <= lastSpectrumNumber; scan++)
                    {
                        if (Progress.IsCancellationPending())
                        {
                            throw new UserTerminatedException();
                        }

                        if (ignoreScans.Contains(scan))
                        {
                            continue;
                        }

                        Progress.SetPosition(scan);

                        int msLevel = rawReader.GetMsLevel(scan);

                        if (msLevel > 1)
                        {
                            PeakList <Peak> pkl;
                            try
                            {
                                pkl = rawReader.GetPeakList(scan);
                            }
                            catch (RawReadException ex)
                            {
                                ignoreScans.Add(ex.Scan);
                                File.WriteAllLines(GetIgnoreScanFile(rawFilename), (from i in ignoreScans
                                                                                    let s = i.ToString()
                                                                                            select s).ToArray());
                                bReadAgain = true;
                                break;
                            }
                            pkl.Precursor    = rawReader.GetPrecursorPeakWithMasterScan(scan);
                            pkl.MsLevel      = msLevel;
                            pkl.Experimental = experimental;
                            pkl.ScanTimes.Add(new ScanTime(scan, rawReader.ScanToRetentionTime(scan)));
                            pkl.ScanMode = rawReader.GetScanMode(scan);

                            if (pkl.PrecursorCharge == 0)
                            {
                                pkl.PrecursorCharge = PrecursorUtils.GuessPrecursorCharge(pkl, pkl.PrecursorMZ);
                            }

                            PeakList <Peak> pklProcessed = this.pklProcessor.Process(pkl);
                            if (null != pklProcessed && pklProcessed.Count > 0)
                            {
                                result.Add(pklProcessed);
                            }
                        }
                    }
                }
                finally
                {
                    Progress.End();
                }
            }
            finally
            {
                rawReader.Close();
            }

            if (bReadAgain)
            {
                return(ReadTandemMassFromRaw(rawFilename, ignoreScans));
            }
            else
            {
                return(result);
            }
        }
        private int DoWritePeakList(IRawFile2 rawReader, int scan, string fileName, List <string> returnFiles, string experimental, int lastSpectrumNumber, List <int> ignoreScans, ref bool bReadAgain)
        {
            var result = scan + 1;

            if (ignoreScans.Contains(scan))
            {
                return(result);
            }

            SetPosition(scan);

            int msLevel = rawReader.GetMsLevel(scan);

            if (!DoAcceptMsLevel(msLevel))
            {
                return(result);
            }

            //Console.WriteLine("Reading scan {0}", scan);

            PeakList <Peak> pkl;

            try
            {
                pkl = rawReader.GetPeakList(scan);
            }
            catch (RawReadException ex)
            {
                ignoreScans.Add(ex.Scan);
                File.WriteAllLines(GetIgnoreScanFile(fileName), (from i in ignoreScans
                                                                 let s = i.ToString()
                                                                         select s).ToArray());
                bReadAgain = true;
                return(result);
            }

            pkl.MsLevel      = msLevel;
            pkl.Experimental = experimental;
            pkl.ScanTimes.Add(new ScanTime(scan, rawReader.ScanToRetentionTime(scan)));

            pkl.ScanMode = rawReader.GetScanMode(scan);

            PeakList <Peak> pklProcessed;

            if (msLevel > 1)
            {
                pkl.Precursor = new PrecursorPeak(rawReader.GetPrecursorPeak(scan));

                if (pkl.PrecursorCharge == 0)
                {
                    pkl.PrecursorCharge = PrecursorUtils.GuessPrecursorCharge(pkl, pkl.PrecursorMZ);
                }

                if (options.ExtractRawMS3 && pkl.MsLevel == 3)
                {
                    pklProcessed = pkl;
                }
                else
                {
                    pklProcessed = this.PeakListProcessor.Process(pkl);
                }
            }
            else
            {
                pklProcessed = pkl;
            }

            if (null != pklProcessed && pklProcessed.Count > 0)
            {
                DoWritePeakList(rawReader, pklProcessed, fileName, returnFiles);

                if (!options.MzXmlNestedScan)
                {
                    var intent = GetScanIntent(pkl.MsLevel);
                    sw.WriteLine(intent + "</scan>");
                }

                while (result < lastSpectrumNumber && rawReader.GetMsLevel(result) > msLevel)
                {
                    result = DoWritePeakList(rawReader, result, fileName, returnFiles, experimental, lastSpectrumNumber, ignoreScans, ref bReadAgain);
                    if (bReadAgain)
                    {
                        return(result);
                    }
                }

                if (options.MzXmlNestedScan)
                {
                    var intent = GetScanIntent(pkl.MsLevel);
                    sw.WriteLine(intent + "</scan>");
                }
            }

            return(result);
        }