RunCrossSectionWorkFlow() public method

The run molecule informed work flow.
public RunCrossSectionWorkFlow ( IImsTarget target, bool detailedVerbose = true ) : CrossSectionWorkflowResult
target IImsTarget /// The Target. ///
detailedVerbose bool ///
return CrossSectionWorkflowResult
        public void TestTargetDetectionWithIsomersHard()
        {
            // BHC
            string formula3 = "C13H18ClNO";
            MolecularTarget sample3 = new MolecularTarget(formula3, IonizationMethod.Protonated, "BHC");
            string fileLocation3 = BHC;

            CrossSectionSearchParameters parameters3 = new CrossSectionSearchParameters(testDriftTubeLength);

            CrossSectionWorkfow workfow3 = new CrossSectionWorkfow(fileLocation3, "output", parameters3);
            CrossSectionWorkflowResult results3 = workfow3.RunCrossSectionWorkFlow(sample3, true);
            Assert.AreEqual(2, results3.IdentifiedIsomers.Count());
            workfow3.Dispose();
        }
        public int TestTargetDetectionWithIsomersClean(string formula, IonizationMethod method, string descriptor, string fileLocation)
        {
            MolecularTarget sample1 = new MolecularTarget(formula, method, descriptor);

            CrossSectionSearchParameters parameters1 = new CrossSectionSearchParameters(CrossSectionSearchParameters.DefaultDriftTimeToleranceInMs, CrossSectionSearchParameters.DefaultMzWindowHalfWidthInPpm,
                CrossSectionSearchParameters.DefaultNumPointForSmoothing, CrossSectionSearchParameters.DefaultFeatureFilterLevel, CrossSectionSearchParameters.DefaultAbsoluteIntensityThreshold, CrossSectionSearchParameters.DefaultPeakShapeThreshold, CrossSectionSearchParameters.DefaultIsotopicThreshold, CrossSectionSearchParameters.DefaultMaxOutliers, CrossSectionSearchParameters.DefaultPeakDetectorSelection, FitlineEnum.OrdinaryLeastSquares, CrossSectionSearchParameters.DefaultMinR2, CrossSectionSearchParameters.DefaultRelativeIntensityPercentageThreshold, "png", CrossSectionSearchParameters.DefaultInsufficientFramesFraction, testDriftTubeLength, true);

            CrossSectionWorkfow workfow1 = new CrossSectionWorkfow(fileLocation, "output", parameters1);
            CrossSectionWorkflowResult results1 = workfow1.RunCrossSectionWorkFlow(sample1, true);
            int count = results1.IdentifiedIsomers.Count();
            workfow1.Dispose();
            return count;
        }
        public void TestSingleMoleculeWithFormula()
        {
            // Nicotine
            // string formula = "C10H14N2";
            // ImsTarget sample = new ImsTarget(1, Adduct.Protonated, formula);
            // Console.WriteLine("MZ:   " +  221.0594);
            // string fileLocation = AcetamipridFile;

            // Acetamiprid
            // string formula = "C10H11ClN4";
            // ImsTarget sample = new ImsTarget(1, Adduct.Deprotonated, formula);
            // string fileLocation = AcetamipridFile;

            // F1E
            // string formula = "C15H21Cl2FN2O3";
            // MolecularTarget sample = new MolecularTarget(formula, IonizationMethod.Protonated);
            // string fileLocation = F1E;

            // BPS Negative
            // string formula = "C12H10O4S";
            // MolecularTarget sample = new MolecularTarget(formula, IonizationMethod.prot);
            // string fileLocation = BPSNegative;

            // BPS Positive
            string formula = "C12H10O4S";
            MolecularTarget sample = new MolecularTarget(formula, IonizationMethod.Protonated, "BPS");
            string fileLocation = BPSPostive;

            CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(testDriftTubeLength);

            CrossSectionWorkfow workfow = new CrossSectionWorkfow(fileLocation, "output", parameters);
            CrossSectionWorkflowResult result = workfow.RunCrossSectionWorkFlow(sample, true);
            Assert.AreEqual(1, result.IdentifiedIsomers.Count());
            Assert.LessOrEqual(Math.Abs(result.IdentifiedIsomers.First().CrossSectionalArea - 166.3012), 0.5);
            workfow.Dispose();
        }
        public void TestSingleMoleculeMzOnly()
        {
            // Good BPS data
            double mz = 251.037804609;
            string uimfFile = BPSPostive;

            // Acetaminophen
            // double mz = 150.0555008;
            // string uimfFile = Acetaminophen;

            // Nicotinefnic
            // double mz = 161.10787;
            // string uimfFile = NicoFile;

            // Nico M+H
            // double mz = 161.10787;
            // string uimfFile = NicoFile;

            MolecularTarget target = new MolecularTarget(mz, IonizationMethod.Protonated, "Nicotine");

            CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(testDriftTubeLength);

            CrossSectionWorkfow workflow = new CrossSectionWorkfow(uimfFile, "output",  parameters);
            workflow.RunCrossSectionWorkFlow(target);
            workflow.Dispose();
        }
        public void TestMixedSampleCrossSectionExtraction()
        {
            string fileLocation = @"\\proto-2\UnitTest_Files\IMSInformedTestFiles\datasets\mix\Mix1_8Oct13_Columbia_DI.uimf";
            IonizationMethod method = IonizationMethod.Sodiumated;

            IList<IImsTarget> targetList = new List<IImsTarget>();
            targetList.Add(new PeptideTarget(12, "DGWHSWPIAHQWPQGPSAVDAAFSWEEK", 1.0));
            targetList.Add(new MolecularTarget("C3H7O7P", method, "chemical A"));
            targetList.Add(new MolecularTarget("C3H7O7P", method, "chemical B(A's isomer)"));
            targetList.Add(new MolecularTarget("C6H14O12P2", method, "chemical C"));
            targetList.Add(new MolecularTarget("C4H6O5", method, "chemical D"));
            targetList.Add(new MolecularTarget("C3H4O3", method, "chemical E"));
            targetList.Add(new MolecularTarget("C5H11O8P", method, "chemical F"));
            targetList.Add(new MolecularTarget("C6H8O7", method, "chemical G"));
            targetList.Add(new MolecularTarget("C4H6O4", method, "chemical H"));
            targetList.Add(new MolecularTarget("C3H5O6P", method, "chemical I"));
            targetList.Add(new MolecularTarget("C7H15O10P", method, "chemical J"));
            targetList.Add(new MolecularTarget(120.5, method, "MzInDalton specified chemical L"));

            Console.WriteLine("TargetList: ");

            CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(testDriftTubeLength);

            CrossSectionWorkfow informedWorkflow = new CrossSectionWorkfow(fileLocation, "output", parameters);
            IEnumerable<CrossSectionWorkflowResult> resultMap = informedWorkflow.RunCrossSectionWorkFlow(targetList, false);
            informedWorkflow.Dispose();
        }
Esempio n. 6
0
        /// <summary>
        /// The execute finder.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private static int ExecuteFinder(FinderOptions options)
        {
            try
            {
                string uimfFile = options.InputPath; // get the UIMF file
                string datasetName = Path.GetFileNameWithoutExtension(uimfFile);
                string resultName = datasetName + "_"  + "Result.bin";
                string resultPath = Path.Combine(options.OutputPath, resultName);
                string outputDirectory = options.OutputPath;
                IList<string> targetList = options.TargetList;
                bool verbose = options.DetailedVerbose;

                if (outputDirectory == string.Empty)
                {
                    outputDirectory = Directory.GetCurrentDirectory();
                } 
                
                if (!outputDirectory.EndsWith("\\"))
                {
                    outputDirectory += "\\";
                }

                if (!Directory.Exists(outputDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(outputDirectory);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Failed to create directory.");
                        throw;
                    }
                }

                // Delete the result file if it already exists
                if (File.Exists(resultPath))
                {
                    File.Delete(resultPath);
                }

                // Load parameters
                double Mz;

                CrossSectionSearchParameters searchParameters = new CrossSectionSearchParameters(
                    options.DriftTimeToleranceInMs,
                    options.PrePpm,
                    options.NumberOfPointsForSmoothing,
                    options.FeatureFilterLevel,
                    options.IntensityThreshold,
                    options.PeakShapeScoreThreshold,
                    options.IsotopicScoreThreshold,
                    options.MaxOutliers,
                    CrossSectionSearchParameters.DefaultPeakDetectorSelection, // No longer an option
                    options.RobustRegression ? FitlineEnum.IterativelyBiSquareReweightedLeastSquares : FitlineEnum.OrdinaryLeastSquares,
                    options.MinR2,
                    options.RelativeIntensityPercentageThreshold,
                    options.GraphicsFormat,
                    options.InsufficientFramesFraction,
                    options.DriftTubeLength,
                    options.UseAverageTemperature);

                IFormatter formatter = new BinaryFormatter();

                // If target cannot be constructed. Create a result.
                IList<IImsTarget> targets = new List<IImsTarget>(); 
                IImsTarget currentTarget = null;
                IList<CrossSectionWorkflowResult> errorTargets = new List<CrossSectionWorkflowResult>();
                foreach (string item in targetList)
                {
                    foreach (string ionization in options.IonizationList)
                    {
                        try
                        {
                            // get the ionization method.
                            IonizationMethod method = IonizationMethodUtilities.ParseIonizationMethod(ionization.Trim());

                            Tuple<string, string> target = ParseTargetToken(item, datasetName);
                            string formula = target.Item2;
                            string sampleClass = target.Item1;

                            bool isDouble = Double.TryParse(formula, out Mz);
                            if (!isDouble)
                            {
                                Regex rgx = new Regex("[^a-zA-Z0-9 -]");
                                formula = rgx.Replace(formula, "");
                            }

                            if (!isDouble)
                            {
                                currentTarget = new MolecularTarget(formula, method, sampleClass);
                                targets.Add(currentTarget);
                            }

                            else 
                            {
                                currentTarget = new MolecularTarget(Mz, method, sampleClass);
                                targets.Add(currentTarget);
                            }
                        }
                        catch (Exception e)
                        {
                            // In case of error creating targets, create the target error result
                            CrossSectionWorkflowResult informedResult = CrossSectionWorkflowResult.CreateErrorResult(currentTarget, datasetName, uimfFile, resultPath, "");
                            
                            using (Stream stream = new FileStream("serialized_result.bin", FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                formatter.Serialize(stream, informedResult);
                            }

                            throw e;
                        }
                    }
                } 
                        
                // Preprocessing
                Console.WriteLine("Start Preprocessing:");
                BincCentricIndexing.IndexUimfFile(uimfFile);

                // Run algorithms in IMSInformed
                CrossSectionWorkfow workflow = new CrossSectionWorkfow(uimfFile, outputDirectory, searchParameters);
                IList<CrossSectionWorkflowResult> results = workflow.RunCrossSectionWorkFlow(targets, verbose);
                workflow.Dispose();

                // Merge the target error result dictionary and other results
                foreach (var pair in errorTargets)
                {
                    results.Add(pair);
                }

                // Serialize the result
                string binPath = Path.Combine(outputDirectory, resultName);

                using (Stream stream = new FileStream(binPath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                        formatter.Serialize(stream, results);
                }
                
                if (options.PauseWhenDone)
                {
                    PauseProgram();
                }

                // Define success
                foreach (CrossSectionWorkflowResult result in results)
                {
                    if (!(result.AnalysisStatus == AnalysisStatus.Positive || result.AnalysisStatus == AnalysisStatus.Negative || result.AnalysisStatus == AnalysisStatus.NotSufficientPoints | result.AnalysisStatus == AnalysisStatus.Rejected))
                    {
                        return 1;
                    }
                }

                return 0;
            }
            catch (Exception e)
            {
                string uimfFile = options.InputPath; // get the UIMF file
                string datasetName = Path.GetFileNameWithoutExtension(uimfFile);
                string resultName = datasetName + "_Result.txt";
                string resultPath = Path.Combine(options.OutputPath, resultName);
                string outputDirectory = options.OutputPath;

                if (outputDirectory == string.Empty)
                {
                    outputDirectory = Directory.GetCurrentDirectory();
                } 
                
                if (!outputDirectory.EndsWith("\\"))
                {
                    outputDirectory += "\\";
                }

                if (!Directory.Exists(outputDirectory))
                {
                    try
                    {
                        Directory.CreateDirectory(outputDirectory);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Failed to create directory.");
                        throw;
                    }
                }

                // Delete the result file if it already exists
                if (File.Exists(resultPath))
                {
                    File.Delete(resultPath);
                }

                Console.WriteLine(e.Message);
                using (StreamWriter errorFile = File.CreateText(resultPath))
                {
                    errorFile.Write(e.Message);
                    errorFile.Write(e.StackTrace);
                }

                if (options.PauseWhenDone)
                {
                    PauseProgram();
                }

                return 1;
            }
        }