/// <summary>
        /// process result files collected and generate the CCS/mz DB.
        /// </summary>
        /// <param name="analysisDirectory">
        /// The analysis directory.
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public void ProcessResultFiles(string analysisDirectory, AnalysisLibrary lib)
        {
            long count = 0;
            long totalTasks = this.Tasks.Count();

            foreach (ImsInformedProcess task in this.Tasks)
            {
                // Deserialize the results and dispatch them into lookup tables.
                try
                {
                    IList<CrossSectionWorkflowResult> results = task.DeserializeResultBinFile();

                    AsyncHelpers.RunSync(() => lib.InsertResult(results));
                    count++;
                    Console.WriteLine("Number of results processed: {0}/{1}", count, totalTasks);
                    Console.SetCursorPosition(0, Console.CursorTop - 1);
                    // Dispose the task as it is no longer used.
                    task.Dispose();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Result processing for {0} failed", task.DataSetName);
                    Console.WriteLine("Exception: {0}", e.Message);
                    Console.WriteLine(string.Empty);
                }
            }

            this.empty = false;
        }
示例#2
0
        public async static void AnalysisDBTest()
        {
            var snapshot1 = new ArrivalTimeSnapShot();
            snapshot1.DriftTubeVoltageInVolt = 1000;
            snapshot1.MeasuredArrivalTimeInMs = 22;
            snapshot1.PressureInTorr = 4;
            snapshot1.TemperatureInKelvin = 10;
            var iso1 = new IdentifiedIsomerInfo(2 ,222, 0.9, 10.5, 115, 123, new List<ArrivalTimeSnapShot>(){snapshot1}, 100, AnalysisStatus.Positive, new PeakScores(1.0, 0.8, 0.7), new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), 0.1, 0);
            var idens = new List<IdentifiedIsomerInfo>() {iso1};
            
            PeakScores scores = new PeakScores(0, 0.5, 1);
            CrossSectionWorkflowResult result1 = new CrossSectionWorkflowResult("ABC_Dataset_01", new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.2), scores, 0.5, OutputFileDir, "123");
            CrossSectionWorkflowResult result2 = new CrossSectionWorkflowResult("ABC_Dataset_02", new MolecularTarget("C2H4O16P2", IonizationMethod.Protonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result3 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C2H4O16P2", IonizationMethod.Deprotonated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result4 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C2H4O16P2", IonizationMethod.Sodiumated, "testamin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result5 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C10H40", IonizationMethod.Protonated, "googlin"), AnalysisStatus.Positive, new AssociationHypothesisInfo(0.1, 0.4), idens, scores, 0.8, OutputFileDir, "123");
            CrossSectionWorkflowResult result6 = new CrossSectionWorkflowResult("ABC_Dataset_03", new MolecularTarget("C10H40", IonizationMethod.Protonated, "googlin"), AnalysisStatus.Negative, null, idens, scores, 0.8, OutputFileDir, "123");

            string fileName = @"output\test.sqlite";
            AnalysisLibrary lib = new AnalysisLibrary(fileName);
            await lib.CreateTables();
            await lib.InsertResult(result1);
            await lib.InsertResult(result2);
            await lib.InsertResult(result3);
            await lib.InsertResult(result4);
            await lib.InsertResult(result5);
            await lib.InsertResult(result6);
        }
示例#3
0
        public static void Main(string[] args)
        {
            try
            {
                // Check if PIXIE.exe is present.
                string exe = "PIXIE.exe";
                if (!File.Exists(exe))
                {
                    throw new FileNotFoundException("PIXIE.exe not found in directory " + Directory.GetCurrentDirectory() + "Please double check installation");
                }

                var options = new Options();
                if (Parser.Default.ParseArguments(args, options))
                {
                    string searchSpecPath = options.SearchSpecFile;

                    // Check if searchSpec file exisits.
                    if (!File.Exists(searchSpecPath))
                    {
                        throw new FileNotFoundException("Search spec file: " + searchSpecPath + " not found");
                    }

                     if (!Directory.Exists(options.InputPath))
                     {
                         throw new FileNotFoundException("Input path does not exist", options.InputPath);
                     }

                    if (!string.IsNullOrEmpty(options.OutputPath))
                    {
                        if (!Directory.Exists(options.OutputPath))
                        {
                            Directory.CreateDirectory(options.OutputPath);
                        }
                    }

                    int maxNumberOfProcesses = options.NumberOfProcesses;
                    bool reanalyze = options.Reanalyze;
                    string workspaceDir = string.IsNullOrEmpty(options.OutputPath) ? options.InputPath : options.OutputPath;

                    // Process the search spec file
                    try
                    {
                        TextSearchSpecProcessor processor = new TextSearchSpecProcessor(exe, searchSpecPath, options.InputPath, options.OutputPath, options.ShowWindow, options.IgnoreMissingFiles);

                        // Run the program in a single process.
                        int numberOfCommands = processor.TaskList.Count;
                        int count = 0;
                        int index = 0;
                        HashSet<ImsInformedProcess> runningTasks = new HashSet<ImsInformedProcess>();

                        List<ImsInformedProcess> failedAnalyses = new List<ImsInformedProcess>();

                        AnalysisLibrary lib = new AnalysisLibrary(Path.Combine(options.OutputPath, "analysesDB.sqlite"));
                        AsyncHelpers.RunSync(() => lib.CreateTables());

                        while (count < numberOfCommands)
                        {
                            if (runningTasks.Count < maxNumberOfProcesses)
                            {
                                // Find the next non-conflicting task that is not done yet and resource-free and is not running.
                                bool done = processor.TaskList[index].Done;
                                bool running = runningTasks.Contains(processor.TaskList[index]);
                                bool resourceFree = processor.TaskList[index].AreResourcesFree(runningTasks);

                                while (done || running || !resourceFree)
                                {
                                    if (index + 1 == numberOfCommands)
                                    {
                                        ImsInformedProcess doneProcess = WaitUntilAtLeastOneTaskDone(runningTasks);
                                        ProcessFinishedTask(doneProcess, failedAnalyses);
                                        index = 0;
                                    }
                                    else
                                    {
                                        index++;
                                    }

                                    done = processor.TaskList[index].Done;
                                    running = runningTasks.Contains(processor.TaskList[index]);
                                    resourceFree = processor.TaskList[index].AreResourcesFree(runningTasks);
                                }

                                runningTasks.Add(processor.TaskList[index]);

                                if (!File.Exists(processor.TaskList[index].ResultBinFile) || reanalyze)
                                {
                                    string outputDir = Path.GetDirectoryName(processor.TaskList[index].ResultBinFile);
                                    if (outputDir != null && Directory.Exists(outputDir))
                                    {
                                        DirectoryInfo di = new DirectoryInfo(outputDir);
                                        FileInfo[] files = di.GetFiles("*.png")
                                                             .Where(p => p.Extension == ".png").ToArray();
                                        foreach (FileInfo file in files)
                                        {
                                                file.Attributes = FileAttributes.Normal;
                                                File.Delete(file.FullName);
                                        }
                                    }

                                    processor.TaskList[index].Start();
                                    Console.WriteLine("Initiating Analysis Job [ID = {0}] out of {1} jobs.", processor.TaskList[index].JobID, numberOfCommands);
                                    Console.WriteLine("Dataset Name: " + processor.TaskList[index].DataSetName);
                                    Console.WriteLine("Running " + processor.TaskList[index].StartInfo.FileName + " " + processor.TaskList[index].StartInfo.Arguments);
                                    Console.WriteLine(" ");
                                }
                                else
                                {
                                    // skip the given analysis job
                                    processor.TaskList[index].Done = true;
                                    ProcessFinishedTask(processor.TaskList[index], failedAnalyses);
                                }

                                count++;
                            }
                            else if (runningTasks.Count == maxNumberOfProcesses)
                            {
                                ImsInformedProcess doneProcess = WaitUntilAtLeastOneTaskDone(runningTasks);
                                ProcessFinishedTask(doneProcess, failedAnalyses);
                            }
                        }

                        // Wait until runningTasks is empty
                        foreach (var item in runningTasks)
                        {
                            if (!item.Done)
                            {
                                item.WaitForExit();
                                item.Done = true;
                                if (item.ExitCode == 0)
                                {
                                    Console.WriteLine("Analysis completed succeessfully for (ID =" + item.JobID + ") " + item.DataSetName);
                                }
                                else
                                {
                                    Console.WriteLine("Analysis failed for (ID =" + item.JobID + ") " + item.DataSetName + ". Check the error file for details.");
                                    failedAnalyses.Add(item);
                                }
                            }
                            else
                            {
                                ProcessFinishedTask(item, failedAnalyses);
                                Console.WriteLine("Analysis was completed before and Reanalyze setting is on, skipping analysis for (ID =" + item.JobID + ") " + item.DataSetName);
                            }

                            Console.WriteLine(" ");
                        }

                        // Collect result from result files
                        Console.WriteLine("Aggregating Analyses Results...");
                        IEnumerable<ImsInformedProcess> sortedTasks = processor.TaskList;

                        ResultAggregator resultAggregator = new ResultAggregator(sortedTasks);
                        resultAggregator.ProcessResultFiles(workspaceDir, lib);
                        Console.WriteLine("Aggregating Analyses Done");
                        Console.WriteLine();

                        // Print analysis result to console and summary file.
                        string summaryFilePath = Path.Combine(workspaceDir, "analysis_summary.txt");

                        // Setup result file.
                        Trace.Listeners.Clear();
                        ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(false);
                        consoleTraceListener.TraceOutputOptions = TraceOptions.DateTime;
                    }
                    catch (AggregateException e)
                    {
                        foreach (Exception exception in e.InnerExceptions)
                        {
                            if (exception.Data.Contains("lineNumber"))
                            {
                                Console.Write("Line {0}: ", exception.Data["lineNumber"]);
                            }

                            Console.WriteLine(exception.Message);
                            Console.WriteLine(string.Empty);
                        }

                        Console.WriteLine(e.Message);
                        Console.WriteLine();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(String.Empty);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }