コード例 #1
0
ファイル: Program.cs プロジェクト: wolski/RawTools
        static int DoStuff(ArgumentParser.ParseOptions opts)
        {
            List <string> files = new List <string>();

            if (opts.InputFiles.Count() > 0) // did the user give us a list of files?
            {
                List <string> problems = new List <string>();
                files = opts.InputFiles.ToList();

                // check if the list provided contains only .raw files
                foreach (string file in files)
                {
                    if (!file.EndsWith(".raw", StringComparison.OrdinalIgnoreCase))
                    {
                        problems.Add(file);
                    }
                }

                if (problems.Count() == 1)
                {
                    Console.WriteLine("\nERROR: {0} does not appear to be a .raw file. Invoke '>RawTools --help' if you need help.", problems.ElementAt(0));
                    Log.Error("Invalid file provided: {0}", problems.ElementAt(0));

                    return(1);
                }

                if (problems.Count() > 1)
                {
                    Console.WriteLine("\nERROR: The following {0} files do not appear to be .raw files. Invoke '>RawTools --help' if you need help." +
                                      "\n\n{1}", problems.Count(), String.Join("\n", problems));
                    Log.Error("Invalid files provided: {0}", String.Join(" ", problems));
                    return(1);
                }

                Log.Information("Files to be processed, provided as list: {0}", String.Join(" ", files));
            }

            else // did the user give us a directory?
            {
                if (Directory.Exists(opts.InputDirectory))
                {
                    files = Directory.GetFiles(opts.InputDirectory, "*.*", SearchOption.TopDirectoryOnly)
                            .Where(s => s.EndsWith(".raw", StringComparison.OrdinalIgnoreCase)).ToList();
                }
                else
                {
                    Console.WriteLine("ERROR: The provided directory does not appear to be valid.");
                    Log.Error("Invalid directory provided: {0}", opts.InputDirectory);
                    return(1);
                }

                Log.Information("Files to be processed, provided as directory: {0}", String.Join(" ", files));
            }

            if (opts.Quant)
            {
                List <string> possible = new List <string>()
                {
                    "TMT0", "TMT2", "TMT6", "TMT10", "TMT11", "iTRAQ4", "iTRAQ8"
                };
                if (!possible.Contains(opts.LabelingReagents))
                {
                    Console.WriteLine("ERROR: For quantification, the labeling reagent must be one of {TMT0, TMT2, TMT6, TMT10, TMT11, iTRAQ4, iTRAQ8}");
                    Log.Error("Invalid labeling reagent provided: {0}", opts.LabelingReagents);
                    return(1);
                }
            }

            if (opts.Chromatogram != null)
            {
                List <string> possible = new List <string>()
                {
                    "1T", "2T", "3T", "1B", "2B", "3B", "1TB", "2TB", "3TB", "1TB", "2TB", "3TB"
                };
                if (!possible.Contains(opts.Chromatogram))
                {
                    Console.WriteLine("ERROR: Incorrect format for --chro. See help.");
                    Log.Error("Invalid chromatogram argument provided: {Chro}", opts.Chromatogram);
                    return(1);
                }
            }

            System.Diagnostics.Stopwatch singleFileTime = new System.Diagnostics.Stopwatch();
            System.Diagnostics.Stopwatch totalTime      = new System.Diagnostics.Stopwatch();
            totalTime.Start();

            foreach (string file in files)
            {
                singleFileTime.Start();

                Console.WriteLine("\nProcessing: {0}\n", file);

                using (IRawDataPlus rawFile = RawFileReaderFactory.ReadFile(fileName: file))
                {
                    rawFile.SelectInstrument(Device.MS, 1);

                    Log.Information("Now processing: {File} --- Instrument: {Instrument}", Path.GetFileName(file), rawFile.GetInstrumentData().Name);

                    RawDataCollection   rawData   = new RawDataCollection(rawFile: rawFile);
                    QuantDataCollection quantData = new QuantDataCollection();

                    bool isBoxCar = rawData.isBoxCar;

                    if (rawData.isBoxCar)
                    {
                        Console.WriteLine("\nRaw file appears to be a boxcar-type experiment. Precursor peak analysis won't be performed!\n");
                    }

                    if (opts.ParseData | opts.Metrics | opts.Quant)
                    {
                        rawData.ExtractAll(rawFile);

                        if (!isBoxCar)
                        {
                            rawData.CalcPeakRetTimesAndInts(rawFile: rawFile);
                        }
                    }

                    if (opts.Quant)
                    {
                        rawData.quantData.Quantify(rawData: rawData, rawFile: rawFile, labelingReagent: opts.LabelingReagents);
                    }

                    if (opts.UnlabeledQuant & !isBoxCar)
                    {
                        rawData.QuantifyPrecursorPeaks(rawFile);
                    }

                    if (opts.Metrics)
                    {
                        rawData.metaData.AggregateMetaData(rawData, rawFile);
                    }

                    if (opts.ParseData | opts.Quant)
                    {
                        if (opts.Quant)
                        {
                            Parse.WriteMatrix(rawData: rawData, rawFile: rawFile, metaData: rawData.metaData, quantData: rawData.quantData, outputDirectory: opts.OutputDirectory);
                        }
                        else
                        {
                            Parse.WriteMatrix(rawData: rawData, rawFile: rawFile, metaData: rawData.metaData, outputDirectory: opts.OutputDirectory);
                        }
                    }

                    if (opts.WriteMGF)
                    {
                        MGF.WriteMGF(rawData: rawData, rawFile: rawFile, outputDirectory: opts.OutputDirectory, cutoff: opts.MassCutOff,
                                     intensityCutoff: opts.IntensityCutoff);
                    }

                    if (opts.Metrics)
                    {
                        MetricsData metricsData = new MetricsData();

                        if (opts.Quant)
                        {
                            metricsData.GetMetricsData(metaData: rawData.metaData, rawData: rawData, rawFile: rawFile, quantData: rawData.quantData);
                        }
                        else
                        {
                            metricsData.GetMetricsData(metaData: rawData.metaData, rawData: rawData, rawFile: rawFile);
                        }

                        metricsData.GetMetricsData(metaData: rawData.metaData, rawData: rawData, rawFile: rawFile);
                        Metrics.WriteMatrix(rawData, metricsData, opts.OutputDirectory);
                    }

                    if (opts.Chromatogram != null)
                    {
                        int order = Convert.ToInt32((opts.Chromatogram.ElementAt(0).ToString()));

                        if (order > (int)rawData.methodData.AnalysisOrder)
                        {
                            Log.Error("Specified MS order ({Order}) for chromatogram is higher than experiment order ({ExpOrder})",
                                      (MSOrderType)order, rawData.methodData.AnalysisOrder);
                            Console.WriteLine("Specified MS order ({0}) for chromatogram is higher than experiment order ({1}). Chromatogram(s) won't be written.",
                                              (MSOrderType)order, rawData.methodData.AnalysisOrder);
                        }
                        else
                        {
                            rawData.WriteChromatogram(rawFile, (MSOrderType)order, opts.Chromatogram.Contains("T"), opts.Chromatogram.Contains("B"), opts.OutputDirectory);
                        }
                    }
                }

                singleFileTime.Stop();
                Console.WriteLine("\nElapsed time: {0} s", Math.Round(Convert.ToDouble(singleFileTime.ElapsedMilliseconds) / 1000.0, 2));
                singleFileTime.Reset();
            }
            totalTime.Stop();
            Console.WriteLine("\nTime to process all {0} files: {1}", files.Count(), totalTime.Elapsed);

            return(0);
        }
コード例 #2
0
ファイル: QC.cs プロジェクト: wolski/RawTools
        public static QcDataContainer ProcessQcData(this QcDataCollection Data, RawDataCollection rawData, IRawDataPlus rawFile, string qcDirectory, string fastaDB = null)
        {
            DateTime dateAcquired = rawFile.CreationDate;
            //RawDataCollection rawData = new RawDataCollection(rawFile);

            MetricsData metricsData = new MetricsData();

            metricsData.GetMetricsData(metaData: rawData.metaData, rawData: rawData, rawFile: rawFile);

            QcDataContainer qcData = new QcDataContainer(rawData.rawFileName, dateAcquired);

            qcData.Instrument        = rawData.instrument;
            qcData.ExperimentMsOrder = rawData.methodData.AnalysisOrder;
            qcData.Ms1Analyzer       = rawData.methodData.MassAnalyzers[MSOrderType.Ms].ToString();
            qcData.Ms2Analyzer       = rawData.methodData.MassAnalyzers[MSOrderType.Ms2].ToString();

            if (qcData.ExperimentMsOrder == MSOrderType.Ms3)
            {
                qcData.Ms3Analyzer = rawData.methodData.MassAnalyzers[MSOrderType.Ms3].ToString();
            }
            else
            {
                qcData.Ms3Analyzer = "None";
            }

            qcData.TotalScans  = metricsData.TotalScans;
            qcData.NumMs1Scans = metricsData.MS1Scans;
            qcData.NumMs2Scans = metricsData.MS2Scans;
            qcData.NumMs3Scans = metricsData.MS3Scans;

            qcData.Ms1ScanRate = metricsData.MS1ScanRate;
            qcData.Ms2ScanRate = metricsData.MS2ScanRate;

            qcData.MeanDutyCycle = metricsData.MeanDutyCycle;

            qcData.MeanTopN = metricsData.MeanTopN;

            qcData.MedianPrecursorIntensity       = metricsData.MedianPrecursorIntensity;
            qcData.MedianSummedMs2Intensity       = metricsData.MedianSummedMS2Intensity;
            qcData.MedianMs1IsolationInterference = metricsData.MedianMs1IsolationInterference;
            qcData.MedianMs2FractionConsumingTop80PercentTotalIntensity = metricsData.MedianMs2FractionConsumingTop80PercentTotalIntensity;

            qcData.NumEsiStabilityFlags = NumberOfEsiFlags(rawData);

            qcData.QuantMeta = metricsData.QuantMeta;

            qcData.GradientTime       = metricsData.Gradient;
            qcData.ColumnPeakCapacity = metricsData.PeakCapacity;
            qcData.ChromIntMetrics(rawData, metricsData);

            if (!rawData.isBoxCar)
            {
                qcData.PeakShape.Asymmetry.P10 = rawData.peakData.PeakShapeMedians.Asymmetry.P10;
                qcData.PeakShape.Asymmetry.P50 = rawData.peakData.PeakShapeMedians.Asymmetry.P50;

                qcData.PeakShape.Width.P10 = rawData.peakData.PeakShapeMedians.Width.P10;
                qcData.PeakShape.Width.P50 = rawData.peakData.PeakShapeMedians.Width.P50;
            }



            // add the signal-to-noise distribution to the QC data. These are presented as "median of the ith percentile", so for example we take all the 10th percentile values of
            // the S2N and put them in a list, then report the median of that list

            qcData.MedianSummedMs1Intensity = (from x in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms] select rawData.centroidStreams[x].Intensities.Sum()).ToArray().Percentile(50);

            // add the fill-time distribution to the QC data. This is more straightforward. Just put all the fill times in an array and use it to instantiate a new distribution.
            qcData.Ms1FillTime = new Distribution((from x in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms] select rawData.trailerExtras[x].InjectionTime).ToArray());
            qcData.Ms2FillTime = new Distribution((from x in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms2] select rawData.trailerExtras[x].InjectionTime).ToArray());
            qcData.Ms3FillTime = new Distribution((from x in rawData.scanIndex.ScanEnumerators[MSOrderType.Ms3] select rawData.trailerExtras[x].InjectionTime).ToArray());

            //Data.QcData.Add(dateAcquired, newData);
            //Data.ProcessedRawFiles.Add(Path.GetFileName(rawData.rawFileName));

            return(qcData);
        }