Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Parser.Default.ParseArguments <Options>(args).WithParsed(options =>
                {
                    if (options.Verbose)
                    {
                        SetVerboseLogging();
                    }
                    bool combine             = options.Combine;
                    string dateTime          = DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss");
                    List <string> inputFiles = new List <string>();

                    if (options.LoadFromDirectory != null && options.LoadFromDirectory == true)//multiple files
                    {
                        var directoryPath = Path.GetDirectoryName(options.InputFile);
                        DirectoryInfo di  = new DirectoryInfo(directoryPath);
                        Logger.Info("Attempting to load files with the extension .mzml in the following directory: {0}", directoryPath);
                        foreach (var file in di.GetFiles("*.mzml", SearchOption.TopDirectoryOnly))
                        {
                            inputFiles.Add(file.FullName);
                        }

                        if (inputFiles.Count == 0)
                        {
                            Logger.Error("Unable to locate any MZML files in {0} directory", directoryPath);
                            throw new FileNotFoundException();
                        }
                    }
                    else //single file
                    {
                        inputFiles.Add(options.InputFile);
                    }

                    foreach (string inputFilePath in inputFiles)
                    {
                        bool lastFile = false;//saving whether its the last file or not, so if we need to combine all the files in the end, we know when the end is.
                        string fileSpecificDirectory = DirectoryCreator.CreateOutputDirectory(inputFilePath, dateTime);
                        if (inputFilePath == inputFiles.Last())
                        {
                            lastFile = true;
                        }
                        Logger.Info("Loading file: {0}", inputFilePath);
                        Stopwatch sw = new Stopwatch();
                        sw.Start();

                        int division;
                        if (options.Division < 100 && options.Division > 0)
                        {
                            division = options.Division;
                        }
                        else
                        {
                            Logger.Error("Number of divisions must be within the range 1 - 100. You have input: {0}", options.Division);
                            throw new ArgumentOutOfRangeException();
                        }
                        bool irt = !String.IsNullOrEmpty(options.IRTFile);

                        MzmlParser.MzmlReader mzmlParser = new MzmlParser.MzmlReader
                        {
                            ParseBinaryData = options.ParseBinaryData ?? true,
                            Threading       = options.Threading ?? true,
                            MaxQueueSize    = options.MaxQueueSize,
                            MaxThreads      = options.MaxThreads
                        };

                        CheckFileIsReadableOrComplain(inputFilePath);

                        AnalysisSettings analysisSettings = new AnalysisSettings()
                        {
                            MassTolerance      = options.MassTolerance,
                            RtTolerance        = options.RtTolerance,
                            IrtMinIntensity    = options.IrtMinIntensity,
                            IrtMinPeptides     = options.IrtMinTransitions,
                            IrtMassTolerance   = options.IrtMassTolerance,
                            CacheSpectraToDisk = options.Cache,
                            MinimumIntensity   = options.MinimumIntensity,
                            RunEndTime         = options.RunEndTime
                        };

                        if (!String.IsNullOrEmpty(options.IRTFile))
                        {
                            irt = true;
                            if (options.IRTFile.ToLower().EndsWith("traml", StringComparison.InvariantCultureIgnoreCase))
                            {
                                TraMLReader traMLReader     = new TraMLReader();
                                analysisSettings.IrtLibrary = traMLReader.LoadLibrary(options.IRTFile);
                            }
                            else if (options.IRTFile.ToLower().EndsWith("tsv", StringComparison.InvariantCultureIgnoreCase) || options.IRTFile.ToLower().EndsWith("csv", StringComparison.InvariantCultureIgnoreCase))
                            {
                                SVReader svReader           = new SVReader();
                                analysisSettings.IrtLibrary = svReader.LoadLibrary(options.IRTFile);
                            }
                        }
                        MzmlParser.Run run            = mzmlParser.LoadMzml(inputFilePath, analysisSettings);
                        AnalysisSettingsFileWriter Aw = new AnalysisSettingsFileWriter();
                        if (inputFiles.Count() > 1 && lastFile)//multiple files and this is the last
                        {
                            Aw.WriteASFile(run, dateTime, inputFiles);
                        }
                        else //only one file
                        {
                            Aw.WriteASFile(run, dateTime, inputFilePath);
                        }

                        Logger.Info("Generating metrics...", Convert.ToInt32(sw.Elapsed.TotalSeconds));
                        var swameMetrics = new SwaMe.MetricGenerator().GenerateMetrics(run, division, inputFilePath, irt, combine, lastFile, dateTime);
                        var progMetrics  = new Prognosticator.MetricGenerator().GenerateMetrics(run);

                        var metrics       = swameMetrics.Union(progMetrics).ToDictionary(k => k.Key, v => v.Value);
                        string[] mzQCName = { dateTime, Path.GetFileNameWithoutExtension(inputFilePath), "mzQC.json" };
                        Directory.SetCurrentDirectory(fileSpecificDirectory);
                        new MzqcGenerator.MzqcWriter().BuildMzqcAndWrite(string.Join("_", mzQCName), run, metrics, inputFilePath);
                        Logger.Info("Generated metrics in {0} seconds", Convert.ToInt32(sw.Elapsed.TotalSeconds));

                        if (analysisSettings.CacheSpectraToDisk)
                        {
                            Logger.Info("Deleting temp files...");
                            mzmlParser.DeleteTempFiles(run);
                        }
                        Logger.Info("Done!");
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error("An unexpected error occured:");
                Logger.Error(ex.Message);
                Logger.Error(ex.StackTrace);
                LogManager.Shutdown();
                Environment.Exit(1);
            }
            LogManager.Shutdown();
            Environment.Exit(0);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                Parser.Default.ParseArguments <Options>(args).WithParsed(options =>
                {
                    // An inputfile of "-" on the command line denotes stdin, for which we use null internally.
                    if ("-".Equals(options.InputFile, StringComparison.Ordinal))
                    {
                        options.InputFile = null;
                    }
                    // An outputfile of "-" on the command line denotes stdout, for which we use null internally.
                    if ("-".Equals(options.OutputFile, StringComparison.Ordinal))
                    {
                        options.OutputFile = null;
                    }

                    if (options.Verbose)
                    {
                        SetVerboseLogging();
                    }

                    if (null == options.InputFile)
                    {
                        Logger.Info("Loading file: {0}", options.InputFile);
                    }
                    else
                    {
                        Logger.Info("Reading mzML from standard input");
                    }

                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    int division;
                    if (options.Division < 100 && options.Division > 0)
                    {
                        division = options.Division;
                    }
                    else
                    {
                        Logger.Error("Number of divisions must be within the range 1 - 100. You have input: {0}", options.Division);
                        throw new ArgumentOutOfRangeException();
                    }
                    bool irt = !string.IsNullOrEmpty(options.IRTFile);

                    // stdin (denoted by null) is always considered readable; anything else needs a check (#99)
                    if (null != options.InputFile)
                    {
                        CheckFileIsReadableOrComplain(options.InputFile);
                    }

                    AnalysisSettings analysisSettings = new AnalysisSettings()
                    {
                        MassTolerance      = options.MassTolerance,
                        RtTolerance        = options.RtTolerance,
                        IrtMinIntensity    = options.IrtMinIntensity,
                        IrtMinPeptides     = options.IrtMinTransitions,
                        IrtMassTolerance   = options.IrtMassTolerance,
                        CacheSpectraToDisk = options.Cache,
                        MinimumIntensity   = options.MinimumIntensity,
                        TempFolder         = Path.Combine(options.TempFolder, Guid.NewGuid().ToString())
                    };

                    if (analysisSettings.CacheSpectraToDisk && !Directory.Exists(analysisSettings.TempFolder))
                    {
                        Directory.CreateDirectory(analysisSettings.TempFolder);
                    }

                    using Pipeliner pipeliner = new Pipeliner()
                          {
                              Threading    = options.Threading ?? true,
                              MaxQueueSize = options.MaxQueueSize,
                              MaxThreads   = options.MaxThreads
                          };

                    if (!string.IsNullOrEmpty(options.IRTFile))
                    {
                        irt = true;
                        if (options.IRTFile.ToLower().EndsWith("traml", StringComparison.InvariantCultureIgnoreCase))
                        {
                            TraMLReader traMLReader     = new TraMLReader();
                            analysisSettings.IrtLibrary = traMLReader.LoadLibrary(options.IRTFile);
                        }
                        else if (options.IRTFile.ToLower().EndsWith("tsv", StringComparison.InvariantCultureIgnoreCase) || options.IRTFile.ToLower().EndsWith("csv", StringComparison.InvariantCultureIgnoreCase))
                        {
                            SVReader svReader           = new SVReader();
                            analysisSettings.IrtLibrary = svReader.LoadLibrary(options.IRTFile);
                        }
                    }
                    using Run <Scan> run = pipeliner.LoadMzml(options.InputFile, analysisSettings);

                    Logger.Info("Generating metrics...", Convert.ToInt32(sw.Elapsed.TotalSeconds));
                    var swameMetrics = new SwaMe.MetricGenerator().GenerateMetrics(run, division, irt);
                    var progMetrics  = new Prognosticator.MetricGenerator().GenerateMetrics(run);

                    var metrics = swameMetrics.Union(progMetrics).ToDictionary(k => k.Key, v => v.Value);


                    new MzqcGenerator.MzqcWriter().BuildMzqcAndWrite(options.OutputFile, run, metrics, options.InputFile, analysisSettings);
                    Logger.Info("Generated metrics in {0} seconds", Convert.ToInt32(sw.Elapsed.TotalSeconds));

                    if (analysisSettings.CacheSpectraToDisk)
                    {
                        Logger.Trace("Deleting temp files...");
                        Directory.Delete(analysisSettings.TempFolder);
                    }
                    Logger.Trace("Done!");
                });
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, "An unexpected error occured");
                Logger.Fatal(ex.Message);
                Logger.Fatal(ex.StackTrace);
                LogManager.Shutdown();
                Environment.Exit(1);
            }
            LogManager.Shutdown();
            Environment.Exit(0);
        }
Ejemplo n.º 3
0
        private void AnalyseSample()
        {
            string        dateTime   = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
            List <string> inputFiles = new List <string>();
            Logger        logger     = LogManager.GetCurrentClassLogger();
            bool          lastFile   = false;//saving whether its the last file or not, so if we need to combine all the files in the end, we know when the end is.


            logger.Info("Loading file: {0}", inputFilePath);
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int division;

            if (rtDivisionUpDown.Value < 100 && rtDivisionUpDown.Value > 0)
            {
                division = decimal.ToInt32(rtDivisionUpDown.Value);
            }
            else
            {
                logger.Error("Number of divisions must be within the range 1 - 100. You have input: {0}", rtDivisionUpDown.Value);
                throw new ArgumentOutOfRangeException();
            }
            bool irt = !string.IsNullOrEmpty(irtFilePath);

            Pipeliner pipeliner = new Pipeliner()
            {
                Threading         = true,
                MaxQueueSize      = decimal.ToInt32(MaxQueueUpDown.Value),
                MaxThreads        = decimal.ToInt32(MaxThreadsUpDown.Value),
                CancellationToken = _cts.Token
            };

            CheckFileIsReadableOrComplain(inputFilePath);

            AnalysisSettings analysisSettings = new AnalysisSettings()
            {
                MassTolerance      = decimal.ToDouble(BasePeakMassToleranceUpDown.Value),
                RtTolerance        = decimal.ToDouble(BasePeakRtToleranceUpDown.Value),
                IrtMinIntensity    = decimal.ToDouble(MinIrtIntensityUpDown.Value),
                IrtMinPeptides     = decimal.ToInt32(irtPeptidesUpDown.Value),
                IrtMassTolerance   = decimal.ToDouble(irtToleranceUpDown.Value),
                CacheSpectraToDisk = CacheToDiskCheckBox.Checked,
                MinimumIntensity   = decimal.ToInt32(MinIrtIntensityUpDown.Value),
                TempFolder         = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString())
            };

            if (analysisSettings.CacheSpectraToDisk && !Directory.Exists(analysisSettings.TempFolder))
            {
                Directory.CreateDirectory(analysisSettings.TempFolder);
            }

            if (!string.IsNullOrEmpty(irtFilePath))
            {
                irt = true;
                if (irtFilePath.ToLower().EndsWith("traml", StringComparison.InvariantCultureIgnoreCase))
                {
                    TraMLReader traMLReader = new TraMLReader();
                    analysisSettings.IrtLibrary = traMLReader.LoadLibrary(irtFilePath);
                }
                else if (irtFilePath.ToLower().EndsWith("tsv", StringComparison.InvariantCultureIgnoreCase) || irtFilePath.ToLower().EndsWith("csv", StringComparison.InvariantCultureIgnoreCase))
                {
                    SVReader svReader = new SVReader();
                    analysisSettings.IrtLibrary = svReader.LoadLibrary(irtFilePath);
                }
            }
            using (Run <Scan> run = pipeliner.LoadMzml(inputFilePath, analysisSettings))
            {
                AnalysisSettingsFileWriter Aw = new AnalysisSettingsFileWriter();
                if (inputFiles.Count() > 1 && lastFile)//multiple files and this is the last
                {
                    Aw.WriteASFile(run, dateTime, inputFiles);
                }
                else //only one file
                {
                    Aw.WriteASFile(run, dateTime, inputFilePath);
                }

                logger.Info("Generating metrics...", Convert.ToInt32(sw.Elapsed.TotalSeconds));
                var swameMetrics = new SwaMe.MetricGenerator().GenerateMetrics(run, division, irt);
                var progMetrics  = new Prognosticator.MetricGenerator().GenerateMetrics(run);

                var metrics = swameMetrics.Union(progMetrics).ToDictionary(k => k.Key, v => v.Value);


                new MzqcGenerator.MzqcWriter().BuildMzqcAndWrite("", run, metrics, inputFilePath, analysisSettings);
                logger.Info("Generated metrics in {0} seconds", Convert.ToInt32(sw.Elapsed.TotalSeconds));
            }
            if (analysisSettings.CacheSpectraToDisk)
            {
                Directory.Delete(analysisSettings.TempFolder);
            }
            logger.Trace("Done!");
            LogManager.Shutdown();
        }