예제 #1
0
        private static int Run(CommandLineSettings settings)
        {
            int errorCode = 0;

            if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
            {
                Console.WriteLine("Welcome to MetaMorpheus");
            }

            if (settings.CustomDataDirectory != null)
            {
                GlobalVariables.UserSpecifiedDataDir = settings.CustomDataDirectory;
            }

            GlobalVariables.SetUpGlobalVariables();

            if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
            {
                Console.WriteLine(GlobalVariables.MetaMorpheusVersion);
            }

            try
            {
                settings.ValidateCommandLineSettings();
                CommandLineSettings = settings;
            }
            catch (Exception e)
            {
                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine("MetaMorpheus encountered the following error:" + Environment.NewLine + e.Message);
                }
                errorCode = 2;

                return(errorCode);
            }

            if (settings.GenerateDefaultTomls)
            {
                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine("Generating default tomls at location: " + settings.OutputFolder);
                }
                CommandLineSettings.GenerateDefaultTaskTomls(settings.OutputFolder);

                return(errorCode);
            }

            // set up microvignette
            if (settings.RunMicroVignette)
            {
                // set up the spectra file
                settings.Spectra.Clear();
                settings.Spectra.Add(Path.Combine(GlobalVariables.DataDir, @"Data", "SmallCalibratible_Yeast.mzML"));

                // set up the database
                settings.Databases.Clear();
                settings.Databases.Add(Path.Combine(GlobalVariables.DataDir, @"Data", "SmallYeast.fasta"));

                // set up the tasks (calibration, GPTMD, search)
                settings.Tasks.Clear();
                CommandLineSettings.GenerateDefaultTaskTomls(settings.OutputFolder);
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "CalibrationTask.toml"));
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "GptmdTask.toml"));
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "SearchTask.toml"));
            }

            MetaMorpheusEngine.WarnHandler                 += WarnHandler;
            MetaMorpheusEngine.OutProgressHandler          += MyEngine_outProgressHandler;
            MetaMorpheusEngine.StartingSingleEngineHander  += MyEngine_startingSingleEngineHander;
            MetaMorpheusEngine.FinishedSingleEngineHandler += MyEngine_finishedSingleEngineHandler;

            MetaMorpheusTask.WarnHandler += WarnHandler;
            MetaMorpheusTask.LogHandler  += LogHandler;
            MetaMorpheusTask.StartingSingleTaskHander   += MyTaskEngine_startingSingleTaskHander;
            MetaMorpheusTask.FinishedSingleTaskHandler  += MyTaskEngine_finishedSingleTaskHandler;
            MetaMorpheusTask.FinishedWritingFileHandler += MyTaskEngine_finishedWritingFileHandler;

            bool containsRawFiles = settings.Spectra.Select(v => Path.GetExtension(v).ToLowerInvariant()).Any(v => v == ".raw");

            if (containsRawFiles && !GlobalVariables.GlobalSettings.UserHasAgreedToThermoRawFileReaderLicence)
            {
                // write the Thermo RawFileReader licence agreement
                Console.WriteLine(ThermoRawFileReaderLicence.ThermoLicenceText);
                Console.WriteLine("\nIn order to search Thermo .raw files, you must agree to the above terms. Do you agree to the above terms? y/n\n");
                string res = Console.ReadLine().ToLowerInvariant();
                if (res == "y")
                {
                    var newGlobalSettings = new GlobalSettings
                    {
                        UserHasAgreedToThermoRawFileReaderLicence = true,
                        WriteExcelCompatibleTSVs = GlobalVariables.GlobalSettings.WriteExcelCompatibleTSVs
                    };

                    Toml.WriteFile <GlobalSettings>(newGlobalSettings, Path.Combine(GlobalVariables.DataDir, @"settings.toml"));
                    GlobalVariables.GlobalSettings = newGlobalSettings;
                }
                else
                {
                    Console.WriteLine("Thermo licence has been declined. Exiting MetaMorpheus. You can still search .mzML and .mgf files without agreeing to the Thermo licence.");
                    errorCode = 3;
                    return(errorCode);
                }
            }

            foreach (var db in settings.Databases)
            {
                if (!Path.GetExtension(db).Equals(".fasta"))
                {
                    GlobalVariables.AddMods(UsefulProteomicsDatabases.ProteinDbLoader.GetPtmListFromProteinXml(db).OfType <Modification>(), true);

                    // print any error messages reading the mods to the console
                    foreach (var error in GlobalVariables.ErrorsReadingMods)
                    {
                        if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                        {
                            Console.WriteLine(error);
                        }
                    }

                    GlobalVariables.ErrorsReadingMods.Clear();
                }
            }

            List <(string, MetaMorpheusTask)> taskList = new List <(string, MetaMorpheusTask)>();

            var tasks = settings.Tasks.ToList();

            for (int i = 0; i < tasks.Count; i++)
            {
                var filePath = tasks[i];

                var toml = Toml.ReadFile(filePath, MetaMorpheusTask.tomlConfig);

                switch (toml.Get <string>("TaskType"))
                {
                case "Search":
                    var searchTask = Toml.ReadFile <SearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "SearchTask", searchTask));
                    break;

                case "Calibrate":
                    var calibrationTask = Toml.ReadFile <CalibrationTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "CalibrationTask", calibrationTask));
                    break;

                case "Gptmd":
                    var GptmdTask = Toml.ReadFile <GptmdTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "GptmdTask", GptmdTask));
                    break;

                case "XLSearch":
                    var XlTask = Toml.ReadFile <XLSearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "XLSearchTask", XlTask));
                    break;

                case "GlycoSearch":
                    var GlycoTask = Toml.ReadFile <GlycoSearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "GlycoSearchTask", GlycoTask));
                    break;

                default:
                    if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                    {
                        Console.WriteLine(toml.Get <string>("TaskType") + " is not a known task type! Skipping.");
                    }
                    break;
                }
            }

            List <string>    startingRawFilenameList   = settings.Spectra.Select(b => Path.GetFullPath(b)).ToList();
            List <DbForTask> startingXmlDbFilenameList = settings.Databases.Select(b => new DbForTask(Path.GetFullPath(b), IsContaminant(b))).ToList();

            // check that experimental design is defined if normalization is enabled
            var searchTasks = taskList
                              .Where(p => p.Item2.TaskType == MyTask.Search)
                              .Select(p => (SearchTask)p.Item2);

            string pathToExperDesign = Directory.GetParent(startingRawFilenameList.First()).FullName;

            pathToExperDesign = Path.Combine(pathToExperDesign, GlobalVariables.ExperimentalDesignFileName);

            if (!File.Exists(pathToExperDesign))
            {
                if (searchTasks.Any(p => p.SearchParameters.Normalize))
                {
                    if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                    {
                        Console.WriteLine("Experimental design file was missing! This must be defined to do normalization. Download a template from https://github.com/smith-chem-wisc/MetaMorpheus/wiki/Experimental-Design");
                    }
                    return(5);
                }
            }
            else
            {
                ExperimentalDesign.ReadExperimentalDesign(pathToExperDesign, startingRawFilenameList, out var errors);

                if (errors.Any())
                {
                    if (searchTasks.Any(p => p.SearchParameters.Normalize))
                    {
                        if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                        {
                            foreach (var error in errors)
                            {
                                Console.WriteLine(error);
                            }
                        }
                        return(5);
                    }
                    else
                    {
                        if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                        {
                            Console.WriteLine("An experimental design file was found, but an error " +
                                              "occurred reading it. Do you wish to continue with an empty experimental design? (This will delete your experimental design file) y/n" +
                                              "\nThe error was: " + errors.First());

                            var result = Console.ReadLine();

                            if (result.ToLowerInvariant() == "y" || result.ToLowerInvariant() == "yes")
                            {
                                File.Delete(pathToExperDesign);
                            }
                            else
                            {
                                return(5);
                            }
                        }
                        else
                        {
                            // just continue on if verbosity is on "none"
                            File.Delete(pathToExperDesign);
                        }
                    }
                }
                else
                {
                    if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                    {
                        Console.WriteLine("Read ExperimentalDesign.tsv successfully");
                    }
                }
            }

            EverythingRunnerEngine a = new EverythingRunnerEngine(taskList, startingRawFilenameList, startingXmlDbFilenameList, settings.OutputFolder);

            try
            {
                a.Run();
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                var message = "Run failed, Exception: " + e.Message;

                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine(message);
                }
                errorCode = 4;
            }

            return(errorCode);
        }
예제 #2
0
        private static int Run(CommandLineSettings settings)
        {
            if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
            {
                Console.WriteLine("Welcome to MetaMorpheus");
                Console.WriteLine(GlobalVariables.MetaMorpheusVersion);
            }

            int errorCode = 0;

            try
            {
                settings.ValidateCommandLineSettings();
                CommandLineSettings = settings;
            }
            catch (Exception e)
            {
                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine("MetaMorpheus encountered the following error:" + Environment.NewLine + e.Message);
                }
                errorCode = 2;

                return(errorCode);
            }

            if (settings.GenerateDefaultTomls)
            {
                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine("Generating default tomls at location: " + settings.OutputFolder);
                }
                CommandLineSettings.GenerateDefaultTaskTomls(settings.OutputFolder);

                return(errorCode);
            }

            // set up microvignette
            if (settings.RunMicroVignette)
            {
                // set up the spectra file
                settings.Spectra.Clear();
                settings.Spectra.Add(Path.Combine(GlobalVariables.DataDir, @"Data", "SmallCalibratible_Yeast.mzML"));

                // set up the database
                settings.Databases.Clear();
                settings.Databases.Add(Path.Combine(GlobalVariables.DataDir, @"Data", "SmallYeast.fasta"));

                // set up the tasks (calibration, GPTMD, search)
                settings.Tasks.Clear();
                CommandLineSettings.GenerateDefaultTaskTomls(settings.OutputFolder);
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "CalibrationTask.toml"));
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "GptmdTask.toml"));
                settings.Tasks.Add(Path.Combine(settings.OutputFolder, "SearchTask.toml"));
            }

            MetaMorpheusEngine.WarnHandler                 += WarnHandler;
            MetaMorpheusEngine.OutProgressHandler          += MyEngine_outProgressHandler;
            MetaMorpheusEngine.StartingSingleEngineHander  += MyEngine_startingSingleEngineHander;
            MetaMorpheusEngine.FinishedSingleEngineHandler += MyEngine_finishedSingleEngineHandler;

            MetaMorpheusTask.WarnHandler += WarnHandler;
            MetaMorpheusTask.LogHandler  += LogHandler;
            MetaMorpheusTask.StartingSingleTaskHander   += MyTaskEngine_startingSingleTaskHander;
            MetaMorpheusTask.FinishedSingleTaskHandler  += MyTaskEngine_finishedSingleTaskHandler;
            MetaMorpheusTask.FinishedWritingFileHandler += MyTaskEngine_finishedWritingFileHandler;

            bool containsRawFiles = settings.Spectra.Select(v => Path.GetExtension(v).ToLowerInvariant()).Any(v => v == ".raw");

            if (containsRawFiles && !GlobalVariables.GlobalSettings.UserHasAgreedToThermoRawFileReaderLicence)
            {
                // write the Thermo RawFileReader licence agreement
                Console.WriteLine(ThermoRawFileReader.ThermoRawFileReaderLicence.ThermoLicenceText);
                Console.WriteLine("\nIn order to search Thermo .raw files, you must agree to the above terms. Do you agree to the above terms? y/n\n");
                string res = Console.ReadLine().ToLowerInvariant();
                if (res == "y")
                {
                    var newGlobalSettings = new GlobalSettings
                    {
                        UserHasAgreedToThermoRawFileReaderLicence = true,
                        WriteExcelCompatibleTSVs = GlobalVariables.GlobalSettings.WriteExcelCompatibleTSVs
                    };

                    Toml.WriteFile <GlobalSettings>(newGlobalSettings, Path.Combine(GlobalVariables.DataDir, @"settings.toml"));
                    GlobalVariables.GlobalSettings = newGlobalSettings;
                }
                else
                {
                    Console.WriteLine("Thermo licence has been declined. Exiting MetaMorpheus. You can still search .mzML and .mgf files without agreeing to the Thermo licence.");
                    errorCode = 3;
                    return(errorCode);
                }
            }

            foreach (var db in settings.Databases)
            {
                if (!Path.GetExtension(db).Equals(".fasta"))
                {
                    GlobalVariables.AddMods(UsefulProteomicsDatabases.ProteinDbLoader.GetPtmListFromProteinXml(db).OfType <Modification>(), true);

                    // print any error messages reading the mods to the console
                    foreach (var error in GlobalVariables.ErrorsReadingMods)
                    {
                        if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                        {
                            Console.WriteLine(error);
                        }
                    }

                    GlobalVariables.ErrorsReadingMods.Clear();
                }
            }

            List <(string, MetaMorpheusTask)> taskList = new List <(string, MetaMorpheusTask)>();

            var tasks = settings.Tasks.ToList();

            for (int i = 0; i < tasks.Count; i++)
            {
                var filePath = tasks[i];

                var toml = Toml.ReadFile(filePath, MetaMorpheusTask.tomlConfig);

                switch (toml.Get <string>("TaskType"))
                {
                case "Search":
                    var searchTask = Toml.ReadFile <SearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "SearchTask", searchTask));
                    break;

                case "Calibrate":
                    var calibrationTask = Toml.ReadFile <CalibrationTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "CalibrationTask", calibrationTask));
                    break;

                case "Gptmd":
                    var GptmdTask = Toml.ReadFile <GptmdTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "GptmdTask", GptmdTask));
                    break;

                case "XLSearch":
                    var XlTask = Toml.ReadFile <XLSearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "XLSearchTask", XlTask));
                    break;

                case "GlycoSearch":
                    var GlycoTask = Toml.ReadFile <GlycoSearchTask>(filePath, MetaMorpheusTask.tomlConfig);
                    taskList.Add(("Task" + (i + 1) + "GlycoSearchTask", GlycoTask));
                    break;

                default:
                    if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                    {
                        Console.WriteLine(toml.Get <string>("TaskType") + " is not a known task type! Skipping.");
                    }
                    break;
                }
            }

            List <string>    startingRawFilenameList   = settings.Spectra.Select(b => Path.GetFullPath(b)).ToList();
            List <DbForTask> startingXmlDbFilenameList = settings.Databases.Select(b => new DbForTask(Path.GetFullPath(b), IsContaminant(b))).ToList();

            EverythingRunnerEngine a = new EverythingRunnerEngine(taskList, startingRawFilenameList, startingXmlDbFilenameList, settings.OutputFolder);

            try
            {
                a.Run();
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }

                var message = "Run failed, Exception: " + e.Message;

                if (settings.Verbosity == CommandLineSettings.VerbosityType.minimal || settings.Verbosity == CommandLineSettings.VerbosityType.normal)
                {
                    Console.WriteLine(message);
                }
                errorCode = 4;
            }

            return(errorCode);
        }