Exemple #1
0
 public MultipleRaw2OneMgfProcessor(IRawFile2 rawFile, IPeakListWriter <Peak> writer, double retentionTimeTolerance,
                                    double ppmPrecursorTolerance, double ppmPeakTolerance,
                                    IProcessor <PeakList <Peak> > pklProcessor, FileInfo saveToMergedFile)
     : base(rawFile, writer, retentionTimeTolerance, ppmPrecursorTolerance, ppmPeakTolerance, pklProcessor)
 {
     this.saveToMergedFile = saveToMergedFile;
 }
        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);
        }
 public Raw2MgfProcessor(IRawFile2 rawReader, IPeakListWriter <Peak> writer, double retentionTimeTolerance, double ppmPrecursorTolerance,
                         double ppmPeakTolerance, IProcessor <PeakList <Peak> > pklProcessor, DirectoryInfo saveToDir, bool groupByScanMode)
     : base(rawReader, writer, retentionTimeTolerance, ppmPrecursorTolerance, ppmPeakTolerance, pklProcessor)
 {
     this.saveToDir       = saveToDir;
     this.groupByScanMode = groupByScanMode;
     this.DeduceIonCount  = 6;
 }
        /// <summary>
        /// ParallelMS3: MS1->MS2->MS2->MS3->MS3->MS1->...
        /// Otherwise:   MS1->MS2->MS3->MS2->MS3->MS1->...
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="isParallelMS3">True:MS1->MS2->MS2->MS3->MS3->MS1</param>
        /// <returns></returns>
        public static IRawFile2 GetRawFileReader(string fileName, bool isParallelMS3 = false)
        {
            IRawFile2 result = DoGetRawFileReader(fileName, isParallelMS3);

            result.Open(fileName);

            return(result);
        }
        protected override void DoAfterFileOpen(IRawFile2 rawReader)
        {
            base.DoAfterFileOpen(rawReader);

            Progress.SetMessage("Reading scan relationship ...");

            list = GetScanLevelBuilder().GetScanLevels(rawReader);

            scanMap = list.ToDictionary(m => m.Scan);
        }
        protected override void DoInitialize(IRawFile2 rawReader, string fileName)
        {
            this.swMap       = new Dictionary <string, StreamWriter>();
            this.outputFiles = new List <string>();

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

            Progress.SetRange(firstScan, lastScan);
        }
 public AbstractRawConverterProcessor(IRawFile2 rawReader, IPeakListWriter <Peak> writer, double retentionTimeTolerance,
                                      double ppmPrecursorTolerance, double ppmPeakTolerance,
                                      IProcessor <PeakList <Peak> > pklProcessor)
 {
     this.rawReader = rawReader;
     this.writer    = writer;
     this.retentionTimeTolerance = retentionTimeTolerance;
     this.ppmPrecursorTolerance  = ppmPrecursorTolerance;
     this.ppmPeakTolerance       = ppmPeakTolerance;
     this.pklProcessor           = pklProcessor;
 }
Exemple #8
0
 public MultipleRaw2MgfProcessor(IRawFile2 rawFile, IPeakListWriter <Peak> writer, double retentionTimeTolerance,
                                 double ppmPrecursorTolerance, double ppmPeakTolerance,
                                 IProcessor <PeakList <Peak> > pklProcessor, IEnumerable <string> rawFiles, bool groupByMode)
 {
     this.rawFile = rawFile;
     this.writer  = writer;
     this.retentionTimeTolerance = retentionTimeTolerance;
     this.ppmPrecursorTolerance  = ppmPrecursorTolerance;
     this.ppmPeakTolerance       = ppmPeakTolerance;
     this.pklProcessor           = pklProcessor;
     this.rawFiles    = rawFiles.ToList();
     this.groupByMode = groupByMode;
 }
        private List <int> GetOutputScans(IRawFile2 rawFile)
        {
            var result    = new List <int>();
            int firstScan = rawFile.GetFirstSpectrumNumber();
            int lastScan  = rawFile.GetLastSpectrumNumber();

            for (int scan = firstScan; scan <= lastScan; scan++)
            {
                int msLevel = rawFile.GetMsLevel(scan);
                result.Add(scan);
            }
            return(result);
        }
Exemple #10
0
        /// <summary>
        /// Get corresponding isolation scan
        /// </summary>
        /// <param name="scan"></param>
        /// <returns></returns>
        protected virtual int GetIsolationScan(IRawFile2 rawReader, int scan)
        {
            var mslevel     = rawReader.GetMsLevel(scan);
            var targetlevel = mslevel - 1;

            scan--;
            while (scan >= FirstScan)
            {
                if (targetlevel == rawReader.GetMsLevel(scan))
                {
                    return(scan);
                }
            }
            return(scan);
        }
 public MultipleRaw2OneMgfThreadProcessor(DirectoryInfo rawDir, FileInfo saveToFile,
                                          IRawFile2 rawFile, IPeakListWriter <Peak> writer,
                                          double retentionTimeTolerance, double ppmPrecursorTolerance,
                                          double ppmPeakTolerance, IProcessor <PeakList <Peak> > pklProcessor,
                                          IProgressCallback eachProcessorProgress)
 {
     this.rawDir                 = rawDir;
     this.saveToFile             = saveToFile;
     this.rawFile                = rawFile;
     this.writer                 = writer;
     this.retentionTimeTolerance = retentionTimeTolerance;
     this.ppmPrecursorTolerance  = ppmPrecursorTolerance;
     this.ppmPeakTolerance       = ppmPeakTolerance;
     this.pklProcessor           = pklProcessor;
     this.eachProcessorProgress  = eachProcessorProgress;
 }
        public override IEnumerable <string> Process(string rawFilename)
        {
            if (null == rawReader)
            {
                rawReader = RawFileFactory.GetRawFileReader(rawFilename);
            }

            var rawFile = new FileInfo(rawFilename);

            if (!rawFile.Exists)
            {
                throw new ArgumentException("Raw file not exists : " + rawFilename);
            }

            Progress.SetMessage("Reading peak list from " + rawFilename + " ...");
            List <PeakList <Peak> > pklList = ReadTandemMassFromRaw(rawFile);

            List <PeakList <Peak> > mergedPklList;

            bool mergeScans = this.retentionTimeTolerance > 0;

            if (mergeScans)
            {
                Progress.SetMessage("Merging peak list, total " + pklList.Count + " ...");
                mergedPklList = MergePeakList(pklList);

                Progress.SetMessage("Merging peak list finished, " + mergedPklList.Count + " kept.");
            }
            else
            {
                mergedPklList = pklList;
            }

            var result = new HashSet <string>();

            if (mergedPklList.Count > 0)
            {
                result.Union(WritePeakLists(rawFile, mergedPklList));
            }

            Progress.SetMessage("Succeed!");

            return(new List <string>(result));
        }
Exemple #13
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 override int GetIsolationScan(IRawFile2 rawReader, int scan)
 {
     return(this.GetIdentificationScan(scan));
 }
Exemple #15
0
 protected virtual void DoAfterFileOpen(IRawFile2 rawReader)
 {
 }
Exemple #16
0
 protected void AppendScan(IRawFile2 rawReader, List <IsobaricScan> result, int scan, string mode)
 {
     AppendScan(rawReader, result, scan, mode, defaultIsolationWidth);
 }
 public CacheRawFile(IRawFile2 rawFile)
 {
     this.rawFile = rawFile;
 }
 public CacheRawFile(string fileName)
 {
     this.rawFile = RawFileFactory.GetRawFileReader(fileName);
 }
        public static double GetPrecursorPercentageInIsolationWindow(this IRawFile2 RawReader, int scan, double ppmTolerance)
        {
            var parentPkl = RawReader.GetPeakInIsolationWindow(scan);

            return(parentPkl.GetPrecursorPercentage(ppmTolerance));
        }
 public static PeakList <Peak> GetPeakInIsolationWindow(this IRawFile2 RawReader, int scan)
 {
     return(GetPeakInIsolationWindow(RawReader, scan, DefaultIsolationWidth));
 }
        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);
        }
 protected abstract void DoInitialize(IRawFile2 rawReader, string fileName);
        protected override void DoInitialize(IRawFile2 rawFile, string rawFileName)
        {
            var resultFile = GetResultFile(rawFile, rawFileName);

            var scans = GetOutputScans(rawFile);

            this.scanIndeies = new List <Pair <int, long> >();

            var utf8WithoutBom = new System.Text.UTF8Encoding(false);

            this.sw         = new StreamWriter(resultFile, false, utf8WithoutBom);
            this.sw.NewLine = "\n";

            /*
             * xml header and namespace info
             */
            sw.WriteLine(@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>");
            sw.WriteLine(@"<mzXML xmlns=""http://sashimi.sourceforge.net/schema_revision/mzXML_3.1""");
            sw.WriteLine(@" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""");
            sw.WriteLine(@" xsi:schemaLocation=""http://sashimi.sourceforge.net/schema_revision/mzXML_3.1 http://sashimi.sourceforge.net/schema_revision/mzXML_3.1/mzXML_idx_3.1.xsd"" >");

            int    firstScan = rawFile.GetFirstSpectrumNumber();
            int    lastScan  = rawFile.GetLastSpectrumNumber();
            double startTime = rawFile.ScanToRetentionTime(firstScan) * 60;
            double endTime   = rawFile.ScanToRetentionTime(lastScan) * 60;

            /*
             * begin msRun
             */
            sw.WriteLine(MyConvert.Format(@" <msRun scanCount=""{0}"" startTime=""PT{1:G6}S"" endTime=""PT{2:G6}S"" >", scans.Count, startTime, endTime));

            string sha1;

            try
            {
                sha1 = HashUtils.GetSHA1Hash(rawFileName).ToLower();
            }
            catch (Exception ex)
            {
                throw new Exception("Exception when calculating sha1 value of file " + rawFileName, ex);
            }

            /*
             * parent (raw input) file
             */
            //sw.WriteLine(@"  <parentFile fileName=""file://DATA-PC/L/5168TP_mouse_phos_TMT/raw/6.raw"" fileType=""RAWData"" fileSha1=""f6db29dd3e26dec7eb16422138f0b2b06f02ba06"" />");
            sw.WriteLine(@"  <parentFile fileName=""file://{0}"" fileType=""RAWData"" fileSha1=""{1}""/>", rawFileName.Replace("\\", "/"), sha1);

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

                /*
                 * mass spec instrument section
                 */
                // get the instrument model
                string instModel = impl.GetInstModel();

                // get acquisition software version
                string instSoftVersion = impl.GetInstSoftwareVersion();

                sw.WriteLine(@"  <msInstrument>");
                sw.WriteLine(@"   <msManufacturer category=""msManufacturer"" value=""Thermo Finnigan"" />");
                sw.WriteLine(@"   <msModel category=""msModel"" value=""{0}"" />", instModel);
                sw.WriteLine(@"   <msIonisation category=""msIonisation"" value=""NSI"" />");
                sw.WriteLine(@"   <msMassAnalyzer category=""msMassAnalyzer"" value=""unknown"" />");
                sw.WriteLine(@"   <msDetector category=""msDetector"" value=""unknown"" />");
                sw.WriteLine(@"   <software type=""acquisition"" name=""Xcalibur"" version=""{0}"" />", instSoftVersion);
                sw.WriteLine(@"  </msInstrument>");
            }

            /*
             * data processing info
             */
            sw.WriteLine(@"  <dataProcessing>");
            sw.WriteLine(@"   <software type=""conversion"" name=""{0}"" version=""{1}"" />", this.DataProcessingSoftware, this.DataProcessingSoftwareVersion);
            foreach (string dataProcessingOperationName in this.dataProcessingOperations.Keys)
            {
                sw.WriteLine(MyConvert.Format(@"    <processingOperation name=""{0}"" value=""{1}""/>", dataProcessingOperationName, this.dataProcessingOperations[dataProcessingOperationName]));
            }
            sw.WriteLine("  </dataProcessing>");
        }
 protected override void DoInitialize(IRawFile2 rawReader, string rawFileName)
 {
     this.swMap       = new Dictionary <string, StreamWriter>();
     this.outputFiles = new List <string>();
 }