public void ChromPeakAnalyzerWorkflowTest()
        {
            //Reference JIRA: https://jira.pnnl.gov/jira/browse/OMCS-884

            string testFile      = UnitTesting2.FileRefs.RawDataMSFiles.OrbitrapStdFile1;
            string peaksTestFile = UnitTesting2.FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500;
            Run    run           = new RunFactory().CreateRun(testFile);
            TargetedWorkflowParameters parameters      = new BasicTargetedWorkflowParameters();
            ChromPeakIqTarget          testTarget      = new ChromPeakIqTarget();
            ITheorFeatureGenerator     TheorFeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);

            ChromPeak testPeak = new ChromPeak(5184, 840963, 50, 0);

            testTarget.SetWorkflow(new ChromPeakAnalyzerIqWorkflow(run, parameters));

            testTarget.Code                 = "NGIIMMENR";
            testTarget.EmpiricalFormula     = "C43H76N14O14S2";
            testTarget.MonoMassTheor        = 1076.510631;
            testTarget.ChromPeak            = testPeak;
            testTarget.ChargeState          = 1;
            testTarget.TheorIsotopicProfile = TheorFeatureGen.GenerateTheorProfile(testTarget.EmpiricalFormula, testTarget.ChargeState);

            testTarget.DoWorkflow();

            IqResult result = testTarget.GetResult();

            Console.WriteLine("Fit Score: " + result.FitScore + " Flagged: " + result.IsIsotopicProfileFlagged);
        }
Пример #2
0
        public void getPeakChromatogramTest1()
        {
            var run = RunUtilities.CreateAndLoadPeaks(FileRefs.RawDataMSFiles.OrbitrapStdFile1,
                                                      FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500);

            var targetMZ  = 759.4032;
            var startScan = 5500;
            var stopScan  = 6500;


            double toleranceInPPM = 20;

            var chromGen = new PeakChromatogramGenerator();

            var mt = TestUtilities.GetMassTagStandard(1);

            run.CurrentMassTag = mt;

            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);

            var peakChromGen = new PeakChromatogramGenerator(toleranceInPPM);

            peakChromGen.Execute(run.ResultCollection);

            run.XYData.Display();

            Assert.AreEqual(133, run.XYData.Xvalues.Length);
            Assert.AreEqual(5543, (int)run.XYData.Xvalues[35]);
            Assert.AreEqual(7319569, (int)run.XYData.Yvalues[35]);

            //make sure that the 0's are not trimmed off
            Assert.AreEqual(0, run.XYData.Yvalues[1]);
        }
        public void JoshGenerateN15LabelledTheorProfileTest2()
        {
            var mt = TestDataCreationUtilities.CreateN14N15TestMassTagList().First(p => p.ID == 23085470);

            mt.EmpiricalFormula = mt.GetEmpiricalFormulaFromTargetCode();

            Console.WriteLine("Total nitrogens = " + mt.GetAtomCountForElement("N"));


            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);

            TestUtilities.DisplayIsotopicProfileData(mt.IsotopicProfile);
            Console.WriteLine();

            var n15theorGenerator = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.N15, 0.005);

            n15theorGenerator.GenerateTheorFeature(mt);

            unlabelledTheorGenerator.GenerateTheorFeature(mt);

            n15theorGenerator.GenerateTheorFeature(mt);

            unlabelledTheorGenerator.GenerateTheorFeature(mt);

            TestUtilities.DisplayIsotopicProfileData(mt.IsotopicProfile);
            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(mt.IsotopicProfileLabelled);
        }
Пример #4
0
        public void Test1()
        {
            double featureFinderTol = 15;
            var    featureFinderRequiresMonoPeak = false;

            var n14n15Util = new N14N15TestingUtilities();
            //get MS
            var massSpectrum = n14n15Util.GetSpectrumAMTTag23140708_Z3_Sum3();  //this is the diff b/w previous test and this one


            var mt23140708 = n14n15Util.CreateMT23140708_Z3();


            var featureGen2 = new JoshTheorFeatureGenerator();

            featureGen2.GenerateTheorFeature(mt23140708);



            //get ms peaks
            var peakDet    = new DeconToolsPeakDetectorV2(1.3, 2, Globals.PeakFitType.QUADRATIC, false);
            var msPeakList = peakDet.FindPeaks(massSpectrum, 0, 0);

            var bff        = new BasicTFF(featureFinderTol, featureFinderRequiresMonoPeak);
            var n14Profile = bff.FindMSFeature(msPeakList, mt23140708.IsotopicProfile);

            var theorXYData = mt23140708.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(n14Profile.GetFWHM());


            var    theorMaxY = theorXYData.Yvalues.Max();
            double obsMaxY   = n14Profile.getMostIntensePeak().Height;


            for (var i = 0; i < theorXYData.Xvalues.Length; i++)
            {
                theorXYData.Yvalues[i] = theorXYData.Yvalues[i] * obsMaxY;
            }

            offsetDistribution(theorXYData, mt23140708.IsotopicProfile, n14Profile);


            var subtracted = XYDataUtilities.SubtractXYData(massSpectrum, theorXYData, n14Profile.MonoPeakMZ - 1,
                                                            n14Profile.MonoPeakMZ + 3, 0.01);



            var outputFileMS           = @"\\protoapps\UserData\Slysz\DeconTools_TestFiles\TextFile\massSpectrum1.txt";
            var outputFileMSSubtracted = @"\\protoapps\UserData\Slysz\DeconTools_TestFiles\TextFile\massSpectrum1_withDataSubtracted.txt";

            TestUtilities.WriteToFile(massSpectrum, outputFileMS);
            TestUtilities.WriteToFile(subtracted, outputFileMSSubtracted);



            // XYDataUtilities.NormalizeXYData()
        }
        public void GenerateIsotopicProfileTest1()
        {
            var peptideUtils = new PeptideUtils();


            var empiricalFormula = peptideUtils.GetEmpiricalFormulaForPeptideSequence("SAMPLERSAMPLER");


            var featureGenerator = new JoshTheorFeatureGenerator();
        }
        public void ChromCorrelatorTest1()
        {
            var rawFilename = @"D:\Data\O16O18\Vlad_Mouse\mhp_plat_test_1_14April13_Frodo_12-12-04.raw";
            var run         = new RunFactory().CreateRun(rawFilename);

            WorkflowExecutorBaseParameters executorBaseParameters = new BasicTargetedWorkflowExecutorParameters();
            var executor = new IqExecutor(executorBaseParameters, run);

            executor.LoadChromData(run);

            var workflowAssigner = new IqWorkflowAssigner();

            TargetedWorkflowParameters workflowParameters = new O16O18WorkflowParameters();
            IqWorkflow workflow = new O16O18IqWorkflow(run, workflowParameters);

            IqTarget iqTarget = new IqChargeStateTarget();

            iqTarget.EmpiricalFormula = "C58H100N18O20";
            iqTarget.Code             = "GAAQNIIPASTGAAK";
            iqTarget.ID          = 1093;
            iqTarget.ChargeState = 0;

            var iqTargetList = new List <IqTarget>();

            iqTargetList.Add(iqTarget);

            var utilities = new IqTargetUtilities();

            utilities.CreateChildTargets(iqTargetList);



            workflowAssigner.AssignWorkflowToParent(workflow, iqTargetList);
            workflowAssigner.AssignWorkflowToChildren(workflow, iqTargetList);

            var theorFeatureGenerator = new JoshTheorFeatureGenerator();

            foreach (var target in iqTarget.ChildTargets())
            {
                utilities.UpdateTargetMissingInfo(target);
                target.TheorIsotopicProfile = theorFeatureGenerator.GenerateTheorProfile(target.EmpiricalFormula, target.ChargeState);
            }



            foreach (var childTarget in iqTarget.ChildTargets())
            {
                var result     = childTarget.CreateResult();
                var correlator = new O16O18ChromCorrelator(7, 0.1, 20, Globals.ToleranceUnit.PPM);
                var corrData   = correlator.CorrelateData(run, result, 5700, 6500);

                var corrDataItem1 = corrData.CorrelationDataItems.First();
                Console.WriteLine("z= \t" + childTarget.ChargeState + "\tCorrelationData (slope,intercept,rsquared)= \t" + corrDataItem1);
            }
        }
        public void JoshGenerateTheorProfileTest1()
        {
            var mt = TestDataCreationUtilities.CreateN14N15TestMassTagList().First(p => p.ID == 23085473);

            var theorGenerator = new JoshTheorFeatureGenerator();

            theorGenerator.GenerateTheorFeature(mt);

            TestUtilities.DisplayIsotopicProfileData(mt.IsotopicProfile);

            //TODO: add an Assert, with a manually confirmed number.
        }
        public void ComparePeakFitterVsAreaFitter()
        {
            var massTagFile1 = Path.Combine(FileRefs.RawDataBasePath, "TargetedWorkflowStandards", "QCShew_peptidesWithObsCountGreaterThan1000.txt");

            //load target
            var masstagImporter = new MassTagFromTextFileImporter(massTagFile1);
            var targets         = masstagImporter.Import().TargetList;


            var run = new RunFactory().CreateRun(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var msgen        = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);
            var peakDetector = new DeconToolsPeakDetectorV2(1.3, 2, Globals.PeakFitType.QUADRATIC, true);



            var scanSet = new ScanSet(9575);

            run.CurrentScanSet = scanSet;

            msgen.Execute(run.ResultCollection);
            peakDetector.Execute(run.ResultCollection);

            var selectedTarget = targets.First(p => p.ID == 635428 && p.ChargeState == 3);

            var theorFeatureGen = new JoshTheorFeatureGenerator(Backend.Globals.LabellingType.NONE, 0.005);

            theorFeatureGen.GenerateTheorFeature(selectedTarget);


            var peakForFWHM = run.PeakList.First(p => p.XValue > 768.38 && p.XValue < 768.39);



            var theorXYdata =
                TheorXYDataCalculationUtilities.GetTheoreticalIsotopicProfileXYData(selectedTarget.IsotopicProfile,
                                                                                    peakForFWHM.Width);

            theorXYdata.NormalizeYData();

            var areaFitter   = new AreaFitter();
            var areaFitScore = areaFitter.GetFit(theorXYdata, run.XYData, 0.1);


            var peakLeastSquaresFitter = new PeakLeastSquaresFitter();
            var peakBasedFitScore      = peakLeastSquaresFitter.GetFit(new List <Peak>(selectedTarget.IsotopicProfile.Peaklist), run.PeakList, 0.1, 25);


            Console.WriteLine("fit score based on XYData = " + areaFitScore);
            Console.WriteLine("fit score based on Peaks= " + peakBasedFitScore);

            Assert.IsTrue(peakBasedFitScore < 0.1);
        }
Пример #9
0
        public void ChromPeakAnalyzerWorkflowTest()
        {
            //Reference JIRA: https://jira.pnnl.gov/jira/browse/OMCS-884

            var testFile      = UnitTesting2.FileRefs.RawDataMSFiles.OrbitrapStdFile1;
            var peaksTestFile = UnitTesting2.FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500;
            var run           = new RunFactory().CreateRun(testFile);
            TargetedWorkflowParameters parameters = new BasicTargetedWorkflowParameters();
            var testTarget = new ChromPeakIqTarget();
            ITheorFeatureGenerator TheorFeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);

            var testPeak = new ChromPeak(5184, 840963, 50, 0);

            var executorBaseParameters = new BasicTargetedWorkflowExecutorParameters();
            var executor = new TopDownMSAlignExecutor(executorBaseParameters, run);

            executor.ChromSourceDataFilePath = peaksTestFile;

            var workflow = new ChromPeakAnalyzerIqWorkflow(run, parameters);

            testTarget.SetWorkflow(workflow);

            testTarget.ID                   = 1;
            testTarget.Code                 = "NGIIMMENR";
            testTarget.EmpiricalFormula     = "C43H76N14O14S2";
            testTarget.MonoMassTheor        = 1076.510631;
            testTarget.ChromPeak            = testPeak;
            testTarget.ChargeState          = 1;
            testTarget.TheorIsotopicProfile = TheorFeatureGen.GenerateTheorProfile(testTarget.EmpiricalFormula, testTarget.ChargeState);

            var      testTargetList = new List <IqTarget>();
            IqTarget testParent     = new IqChargeStateTarget();

            testParent.AddTarget(testTarget);
            testTargetList.Add(testTarget);

            executor.Execute(testTargetList);

            var result = testTarget.GetResult();

            Assert.NotNull(result.LCScanSetSelected);
            Assert.AreNotEqual(1, result.FitScore);
            Assert.AreEqual(true, result.IsotopicProfileFound);
        }
Пример #10
0
        public void CorrelationTest2_UsingExecutorMethod()
        {
            var run = new RunFactory().CreateRun(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var peakImporter = new PeakImporterFromText(FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);

            var mt = TestUtilities.GetMassTagStandard(1);

            run.CurrentMassTag = mt;

            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);


            double chromToleranceInPPM = 10;
            var    startScan           = 5460;
            var    stopScan            = 5755;

            var smoother = new SavitzkyGolaySmoother(3, 2);

            var peakChromGen = new PeakChromatogramGenerator(chromToleranceInPPM);

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[0].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var result = run.ResultCollection.GetTargetedResult(mt);

            ChromatogramCorrelatorBase correlator = new ChromatogramCorrelator(3);
            var corrData = correlator.CorrelatePeaksWithinIsotopicProfile(run, mt.IsotopicProfile, startScan, stopScan);

            Debug.Assert(corrData.CorrelationDataItems != null, "corrData.CorrelationDataItems != null");
            Assert.AreEqual(0.98m, (decimal)Math.Round((double)corrData.CorrelationDataItems[1].CorrelationRSquaredVal, 2));

            foreach (var item in corrData.CorrelationDataItems)
            {
                Console.WriteLine(item.CorrelationRSquaredVal);
            }
        }
Пример #11
0
        protected override void DoPostInitialization()
        {
            base.DoPostInitialization();

            //we want the theorFeature generator to generate even very low peaks
            _theorFeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.00000001);

            //we want the MSFeature finder to dig way down low for any peaks
            _iterativeTFFParameters = new IterativeTFFParameters();
            _iterativeTFFParameters.ToleranceInPPM            = _workflowParameters.MSToleranceInPPM;
            _iterativeTFFParameters.PeakDetectorPeakBR        = 2.1;
            _iterativeTFFParameters.PeakBRStep                = 0.2;
            _iterativeTFFParameters.PeakDetectorMinimumPeakBR = 0.1;

            _msfeatureFinder = new SipperIterativeMSFeatureFinder(_iterativeTFFParameters);

            _quantifier = new SipperQuantifier();

            //always do ChromCorrelation whether you want it or not!
            _workflowParameters.ChromatogramCorrelationIsPerformed = true;
        }
Пример #12
0
        public static IqTarget GetIQTargetStandard(int standardNum)
        {
            //MassTagID	MonoisotopicMass	NET	NETStDev	Obs	minMSGF	mod_count	mod_description	pmt_quality_score	peptide	peptideex	Multiple_Proteins
            //86963986	1516.791851	0.227147	0.007416702	3	1	0		2.00000	AAKEGISCEIIDLR	M.AAKEGISCEIIDLR.T	0



            IqTarget target = new IqChargeStateTarget(null);

            target.ID               = 86963986;
            target.MonoMassTheor    = 1516.791851;
            target.EmpiricalFormula = "C64H112N18O22S";
            target.Code             = "AAKEGISCEIIDLR";
            target.ChargeState      = 2;
            target.ElutionTimeTheor = 0.227147;
            target.MZTheor          = target.MonoMassTheor / target.ChargeState + Globals.PROTON_MASS;


            var theorFeatureGenerator = new JoshTheorFeatureGenerator();

            target.TheorIsotopicProfile = theorFeatureGenerator.GenerateTheorProfile(target.EmpiricalFormula, target.ChargeState);

            return(target);
        }
Пример #13
0
        protected override void DoPostInitialization()
        {
            base.DoPostInitialization();
            ValidateParameters();

            theorFeatureGen    = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.NONE, 0.005);
            theorN15FeatureGen = new JoshTheorFeatureGenerator(DeconTools.Backend.Globals.LabellingType.N15, 0.005);

            chromGenN14 = new PeakChromatogramGenerator(_workflowParameters.ChromGenTolerance, _workflowParameters.ChromGeneratorMode);
            chromGenN14.TopNPeaksLowerCutOff = 0.333;

            chromGenN15 = new PeakChromatogramGenerator(_workflowParameters.ChromGenTolerance, DeconTools.Backend.Globals.ChromatogramGeneratorMode.MOST_ABUNDANT_PEAK, DeconTools.Backend.Globals.IsotopicProfileType.LABELLED);
            chromGenN15.TopNPeaksLowerCutOff = 0.333;

            var pointsToSmooth = (_workflowParameters.ChromSmootherNumPointsInSmooth + 1) / 2;

            chromSmoother     = new SavitzkyGolaySmoother(_workflowParameters.ChromSmootherNumPointsInSmooth, 2);
            chromPeakDetector = new ChromPeakDetector(_workflowParameters.ChromPeakDetectorPeakBR, _workflowParameters.ChromPeakDetectorSigNoise);

            var smartchrompeakSelectorParams = new SmartChromPeakSelectorParameters();

            smartchrompeakSelectorParams.MSFeatureFinderType          = DeconTools.Backend.Globals.TargetedFeatureFinderType.ITERATIVE;
            smartchrompeakSelectorParams.MSPeakDetectorPeakBR         = _workflowParameters.MSPeakDetectorPeakBR;
            smartchrompeakSelectorParams.MSPeakDetectorSigNoiseThresh = _workflowParameters.MSPeakDetectorSigNoise;
            smartchrompeakSelectorParams.MSToleranceInPPM             = _workflowParameters.MSToleranceInPPM;
            smartchrompeakSelectorParams.NETTolerance         = (float)_workflowParameters.ChromNETTolerance;
            smartchrompeakSelectorParams.NumScansToSum        = _workflowParameters.NumMSScansToSum;
            smartchrompeakSelectorParams.NumChromPeaksAllowed = 10;
            smartchrompeakSelectorParams.IterativeTffMinRelIntensityForPeakInclusion = 0.5;


            chromPeakSelectorN14 = new SmartChromPeakSelector(smartchrompeakSelectorParams);


            var chromPeakSelectorParameters = new ChromPeakSelectorParameters();

            chromPeakSelectorParameters.NumScansToSum    = _workflowParameters.NumMSScansToSum;
            chromPeakSelectorParameters.NETTolerance     = (float)_workflowParameters.ChromNETTolerance;
            chromPeakSelectorParameters.PeakSelectorMode = DeconTools.Backend.Globals.PeakSelectorMode.N15IntelligentMode;


            chromPeakSelectorN15 = new BasicChromPeakSelector(chromPeakSelectorParameters);
            chromPeakSelectorN15.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.LABELLED;

            msPeakDetector = new DeconToolsPeakDetectorV2(_workflowParameters.MSPeakDetectorPeakBR,
                                                          _workflowParameters.MSPeakDetectorSigNoise, DeconTools.Backend.Globals.PeakFitType.QUADRATIC, false);


            var iterativeTFFParameters = new IterativeTFFParameters();

            iterativeTFFParameters.ToleranceInPPM = _n14N15Workflow2Parameters.TargetedFeatureFinderToleranceInPPM;
            iterativeTFFParameters.MinimumRelIntensityForForPeakInclusion = 0.33;
            iterativeTFFParameters.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.UNLABELLED;
            unlabelledProfilefinder = new IterativeTFF(iterativeTFFParameters);

            iterativeTFFParameters = new IterativeTFFParameters();
            iterativeTFFParameters.ToleranceInPPM = _n14N15Workflow2Parameters.TargetedFeatureFinderToleranceInPPM;
            iterativeTFFParameters.MinimumRelIntensityForForPeakInclusion = 0.33;
            iterativeTFFParameters.IsotopicProfileType = DeconTools.Backend.Globals.IsotopicProfileType.LABELLED;
            labelledProfileFinder = new IterativeTFF(iterativeTFFParameters);

            quantifier = new N14N15QuantifierTask(_n14N15Workflow2Parameters.NumPeaksUsedInQuant, _workflowParameters.MSToleranceInPPM);

            fitScoreCalc = new IsotopicProfileFitScoreCalculator();

            var minRelativeIntensityForScore = 0.2;

            resultValidatorN14 = new ResultValidatorTask(minRelativeIntensityForScore, true);

            resultValidatorN15 = new LabelledIsotopicProfileScorer(minRelativeIntensityForScore);

            ChromatogramXYData = new XYData();
            MassSpectrumXYData = new XYData();
            ChromPeaksDetected = new List <ChromPeak>();
        }
        public void TestScoring()
        {
            string formula = "C9H13ClN6";
             string fileLocation = Cae;
             MolecularTarget target = new MolecularTarget(formula, IonizationMethod.Protonated, "CAE");

             Console.WriteLine("CompositionWithoutAdduct: " + target.CompositionWithoutAdduct);
             Console.WriteLine("Monoisotopic ViperCompatibleMass: " + target.MonoisotopicMass);

             CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(driftTubeLength);

             var smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);

             CrossSectionWorkfow workflow = new CrossSectionWorkfow(fileLocation, "output", parameters);

             Console.WriteLine("Ionization method: " + target.Adduct);
             Console.WriteLine("Targeting centerMz: " + target.MassWithAdduct);

             // Generate Theoretical Isotopic Profile
             List<Peak> theoreticalIsotopicProfilePeakList = null;
             if (target.CompositionWithAdduct != null)
             {
                 string empiricalFormula = target.CompositionWithAdduct.ToPlainString();
                 var theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
                 IsotopicProfile theoreticalIsotopicProfile = theoreticalFeatureGenerator.GenerateTheorProfile(empiricalFormula, 1);
                 theoreticalIsotopicProfilePeakList = theoreticalIsotopicProfile.Peaklist.Cast<Peak>().ToList();
             }

             // Generate VoltageSeparatedAccumulatedXICs
             var uimfReader = new DataReader(fileLocation);
             Console.WriteLine("Input file: {0}", fileLocation);
             VoltageSeparatedAccumulatedXiCs accumulatedXiCs = new VoltageSeparatedAccumulatedXiCs(uimfReader, target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm, driftTubeLength);

             Console.WriteLine();

             // For each voltage, find 2D XIC features
             foreach (VoltageGroup voltageGroup in accumulatedXiCs.Keys)
             {
                 Console.WriteLine("Voltage group: {0} V, Frame {1}-{2}, {3:F2}K, {4:F2}Torr",
                     voltageGroup.MeanVoltageInVolts,
                     voltageGroup.FirstFrameNumber,
                     voltageGroup.LastFrameNumber,
                     voltageGroup.MeanTemperatureInKelvin,
                     voltageGroup.MeanPressureInTorr);

                 List<IntensityPoint> intensityPoints = accumulatedXiCs[voltageGroup].IntensityPoints;
                 List<FeatureBlob> featureBlobs = PeakFinding.FindPeakUsingWatershed(intensityPoints, smoother, parameters.FeatureFilterLevel);
                 List<StandardImsPeak> standardPeaks = featureBlobs.Select(featureBlob => new StandardImsPeak(featureBlob, uimfReader, voltageGroup,  target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm)).ToList();

                 // feature scorings and Target selection.
                 double globalMaxIntensity = IMSUtil.MaxIntensityAfterFrameAccumulation(voltageGroup, uimfReader);

                 // Check each XIC Peak found
                 foreach (var featurePeak in standardPeaks)
                 {
                     // Evaluate feature scores.
                    double intensityScore = FeatureScoreUtilities.IntensityScore(featurePeak, globalMaxIntensity);

                    double isotopicScoreAngle = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Angle,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistance = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistance,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScorePerson = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.PearsonCorrelation,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreBhattacharyya = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Bhattacharyya,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistanceAlternative = FeatureScoreUtilities.IsotopicProfileScore(
                         featurePeak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistanceAlternative,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double peakShapeScore = FeatureScoreUtilities.PeakShapeScore(featurePeak, workflow.uimfReader, workflow.Parameters.MzWindowHalfWidthInPpm, workflow.Parameters.DriftTimeToleranceInMs, voltageGroup, globalMaxIntensity, workflow.NumberOfScans);

                     // Report all features.
                     Console.WriteLine(" feature found at scan number {0}", featurePeak.PeakApex.DriftTimeCenterInScanNumber);
                     Console.WriteLine("     IntensityScore: {0}", intensityScore);
                     Console.WriteLine("     peakShapeScore: {0}", peakShapeScore);
                     Console.WriteLine("     isotopicScore - Angle:    {0}", isotopicScoreAngle);
                     Console.WriteLine("     isotopicScore - Distance: {0}", isotopicScoreDistance);
                     Console.WriteLine("     isotopicScore - Distance2:{0}", isotopicScoreDistanceAlternative);
                     Console.WriteLine("     isotopicScore - Pearson:  {0}", isotopicScorePerson);
                     Console.WriteLine("     isotopicScore - Bhattacharyya: {0}", isotopicScoreBhattacharyya);

                     Console.WriteLine();
                 }

                 Console.WriteLine();
             }

             workflow.Dispose();
        }
        public void CalculateLabelingDistributionTest2()
        {
            //mass_tag_id	monoisotopic_mass	NET	obs	mod_count	mod_description	pmt	peptide	peptideex
            //355176429	1538.8166126	0.42422	1	0		2.00000	LFLASACLYGAALAGV	R.LFLASACLYGAALAGV.C


            //------------------------load theor data ------------------------------------

            var peptideUtils = new PeptideUtils();

            var peptide = new PeptideTarget();

            peptide.Code             = "LFLASACLYGAALAGV";
            peptide.EmpiricalFormula = new PeptideUtils().GetEmpiricalFormulaForPeptideSequence(peptide.Code);

            var theorFeatureGenerator = new JoshTheorFeatureGenerator();

            theorFeatureGenerator.GenerateTheorFeature(peptide);
            var theorProfile     = peptide.IsotopicProfile;
            var theorIntensities = theorProfile.Peaklist.Select(p => (double)p.Height).ToList();

            Console.WriteLine("Total carbons = " + peptideUtils.GetNumAtomsForElement("C", peptide.EmpiricalFormula));


            var obsIntensities = new List <double>(new[]
            {
                1, 0.8335001, 0.4029815, 0.1846439, 0.1116047, 0.09458135, 0.07157851, 0.04972008,
                0.03036686, 0.01545749, 0.008299164, 0.004003931, 0.001711554, 0.000766305,
                0.000484514
            });


            var relexCorrectedIntensities = new List <double>(new[]
            {
                1, 0.84416, 0.4174013, 0.1843375, 0.1073706, 0.09557419, 0.07190877, 0.04823519,
                0.02991197, 0.01456759, 0.008299164, 0.004003931, 0.001711554, 0.000766305,
                0.000484514
            });


            /*
             *
             * Data for observed profile:
             * LCMSFeature 8517 from Yellow_C13_070_23Mar10_Griffin_10-01-28
             *              *
             * peak	mz	relIntens	width	sn
             *  0	770.418569278349	1	0.008119391	285.256
             *  1	770.919748892834	0.8335001	0.008161238	884.9909
             *  2	771.421020812818	0.4029815	0.008248929	566.6187
             *  3	771.922575912402	0.1846439	0.008058954	703.6938
             *  4	772.424544684666	0.1116047	0.007997629	358.0133
             *  5	772.926348484216	0.09458135	0.008128829	677.3434
             *  6	773.428080290323	0.07157851	0.008151106	100
             *  7	773.929769365137	0.04972008	0.008104968	100
             *  8	774.431542463583	0.03036686	0.007982519	100
             *  9	774.933237566856	0.01545749	0.008024476	100
             *  10	775.434950373045	0.008299164	0.008166174	740.9502
             *  11	775.936532837365	0.004003931	0.007899459	100
             *  12	776.438361528879	0.001711554	0.00877683	44.79652
             *  13	776.940072709136	0.0007663054	0.007601836	17.12788
             *  14	777.441663634739	0.0004845143	0.007320933	100
             *
             */


            var labelDistCalc = new LabelingDistributionCalculator();

            double[] solvedXVals;
            double[] solvedYvals;


            var d = 0.1;

            labelDistCalc.CalculateLabelingDistribution(theorIntensities, obsIntensities, d, d, out solvedXVals, out solvedYvals);


            var xydata = new XYData();

            xydata.Xvalues = solvedXVals;
            xydata.Yvalues = solvedYvals;

            Console.WriteLine();
            Console.WriteLine("threshold= " + d);
            xydata.Display();



            labelDistCalc.CalculateLabelingDistribution(theorIntensities, relexCorrectedIntensities, d, d, out solvedXVals, out solvedYvals);

            xydata.Xvalues = solvedXVals;
            xydata.Yvalues = solvedYvals;

            Console.WriteLine();
            Console.WriteLine("Relex-corrected isotopic profile= " + d);
            xydata.Display();


            double fractionUnlabelled, fractionLabelled, averageLabelsIncorporated;

            labelDistCalc.OutputLabelingInfo(solvedYvals.ToList(), out fractionUnlabelled, out fractionLabelled,
                                             out averageLabelsIncorporated);

            Console.WriteLine();
            Console.WriteLine("fractionUnlabelled= " + fractionUnlabelled);
            Console.WriteLine("fractionLabelled= " + fractionLabelled);
            Console.WriteLine("averageAmountLabelIncorp= " + averageLabelsIncorporated);



            //for (double d = 0; d < 2.1; d+=0.1)
            //{
            //    labelDistCalc.CalculateLabelingDistribution(theorIntensities, obsIntensities, d, d, out solvedXVals, out solvedYvals);


            //    XYData xydata = new XYData();
            //    xydata.Xvalues = solvedXVals;
            //    xydata.Yvalues = solvedYvals;

            //    Console.WriteLine();
            //    Console.WriteLine("threshold= " + d);
            //    xydata.Display();
            //}
        }
Пример #16
0
        public void CorrelationTest1()
        {
            //TODO: test something

            var run = new RunFactory().CreateRun(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var peakImporter = new PeakImporterFromText(FileRefs.PeakDataFiles.OrbitrapPeakFile_scans5500_6500);

            peakImporter.ImportPeaks(run.ResultCollection.MSPeakResultList);

            var mt = TestUtilities.GetMassTagStandard(1);

            run.CurrentMassTag = mt;

            var unlabelledTheorGenerator = new JoshTheorFeatureGenerator();

            unlabelledTheorGenerator.GenerateTheorFeature(mt);


            double chromToleranceInPPM = 10;
            var    startScan           = 5460;
            var    stopScan            = 5755;

            var smoother = new SavitzkyGolaySmoother(3, 2);

            var peakChromGen = new PeakChromatogramGenerator(chromToleranceInPPM);

            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[0].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata1 = run.XYData.TrimData(startScan, stopScan);


            run.XYData = peakChromGen.GenerateChromatogram(run, startScan, stopScan, mt.IsotopicProfile.Peaklist[3].XValue, chromToleranceInPPM);
            run.XYData = smoother.Smooth(run.XYData);

            var chromdata2 = run.XYData.TrimData(startScan, stopScan);

            //chromdata1.Display();
            //Console.WriteLine();
            //chromdata2.Display();

            ChromatogramCorrelatorBase correlator = new ChromatogramCorrelator(3);
            double slope       = 0;
            double intercept   = 0;
            double rsquaredVal = 0;

            correlator.GetElutionCorrelationData(chromdata1, chromdata2, out slope, out intercept, out rsquaredVal);

            Console.WriteLine(mt);

            Console.WriteLine("slope = \t" + slope);
            Console.WriteLine("intercept = \t" + intercept);
            Console.WriteLine("rsquared = \t" + rsquaredVal);


            for (var i = 0; i < chromdata1.Xvalues.Length; i++)
            {
                Console.WriteLine(chromdata1.Xvalues[i].ToString("0") + "\t" + chromdata1.Yvalues[i].ToString("0") + "\t" + chromdata2.Yvalues[i]);
            }
        }
        public void test01_mt230140708_z3()
        {
            double featureFinderTol = 15;
            var    featureFinderRequiresMonoPeak = false;
            var    numPeaksUsedInQuant           = 3;

            var n14n15Util = new N14N15TestingUtilities();
            //get MS
            var massSpectrum = n14n15Util.GetSpectrumAMTTag23140708_Z3_Sum3();  //this is the diff b/w previous test and this one


            var smoother = new DeconTools.Backend.ProcessingTasks.Smoothers.SavitzkyGolaySmoother(3, 2);

            massSpectrum = smoother.Smooth(massSpectrum);


            //get target MT
            var mt23140708 = n14n15Util.CreateMT23140708_Z3();


            //get ms peaks
            var peakDet    = new DeconToolsPeakDetectorV2(1.3, 2, Globals.PeakFitType.QUADRATIC, false);
            var msPeakList = peakDet.FindPeaks(massSpectrum, 0, 0);

            //TestUtilities.DisplayPeaks(msPeakList);

            var featureGen = new TomTheorFeatureGenerator();

            featureGen.GenerateTheorFeature(mt23140708);

            TestUtilities.DisplayIsotopicProfileData(mt23140708.IsotopicProfile);

            var featureGen2 = new JoshTheorFeatureGenerator();

            featureGen2.GenerateTheorFeature(mt23140708);

            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(mt23140708.IsotopicProfile);

            var gen = new N15IsotopeProfileGenerator();

            var theorN15Profile = gen.GetN15IsotopicProfile(mt23140708, 0.005);



            var bff        = new BasicTFF(featureFinderTol, featureFinderRequiresMonoPeak);
            var n14Profile = bff.FindMSFeature(msPeakList, mt23140708.IsotopicProfile);


            var n15Profile = bff.FindMSFeature(msPeakList, theorN15Profile);

            Console.WriteLine(mt23140708.GetEmpiricalFormulaFromTargetCode());


            TestUtilities.DisplayIsotopicProfileData(mt23140708.IsotopicProfile);

            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(theorN15Profile);

            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(n14Profile);

            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(n15Profile);


            var    quant = new BasicN14N15Quantifier(featureFinderTol);
            double ratioContribIso1;
            double ratioContribIso2;
            double ratio;

            quant.GetRatioBasedOnTopPeaks(n14Profile, n15Profile, mt23140708.IsotopicProfile, theorN15Profile, peakDet.BackgroundIntensity,
                                          numPeaksUsedInQuant, out ratio, out ratioContribIso1, out ratioContribIso2);

            Console.WriteLine("--------------------------------");
            Console.WriteLine("Background intensity = " + peakDet.BackgroundIntensity);

            Console.WriteLine("--------------------------------");
            Console.WriteLine("Ratio = " + ratio);
            Console.WriteLine("Ratio contrib Iso1 = " + ratioContribIso1);
            Console.WriteLine("Ratio contrib Iso2 = " + ratioContribIso2);
            Console.WriteLine("--------------------------------");

            Assert.AreEqual(1.458267m, (decimal)Math.Round(ratio, 6));      //see 'N14N15Quantification_manualValidation_of_algorithm.xls' for manual validation
        }
        public void TestFormulaPerturbance()
        {
            List<Tuple<string, string>> formulas = new List<Tuple<string, string>>();

             // truth
             formulas.Add(new Tuple<string, string>("True formula", "C12H10O4S"));
             formulas.Add(new Tuple<string, string>("1 extra H", "C12H11O4S"));
             formulas.Add(new Tuple<string, string>("2 extra H", "C12H12O4S"));
             formulas.Add(new Tuple<string, string>("3 extra H", "C12H13O4S"));
             formulas.Add(new Tuple<string, string>("3 extra H", "C12H14O4S"));
             formulas.Add(new Tuple<string, string>("4 extra H", "C12H15O4S"));
             formulas.Add(new Tuple<string, string>("5 extra H", "C12H16O4S"));
             formulas.Add(new Tuple<string, string>("1 less H", "C12H9O4S"));
             formulas.Add(new Tuple<string, string>("2 less H", "C12H8O4S"));
             formulas.Add(new Tuple<string, string>("3 less H", "C12H7O4S"));
             formulas.Add(new Tuple<string, string>("4 less H", "C12H6O4S"));
             Console.WriteLine("[Intensity], [Distance1], [Distance2], [Angle], [Pearson], [Bucha]");

             string fileLocation = BPSNegative;
             CrossSectionSearchParameters parameters = new CrossSectionSearchParameters(driftTubeLength);
             CrossSectionWorkfow workflow = new CrossSectionWorkfow(fileLocation, "output", parameters);

             foreach (var form in formulas)
             {
                 bool found = false;

                 MolecularTarget target = new MolecularTarget(form.Item2, new IonizationAdduct(IonizationMethod.Deprotonated), form.Item1);
                 Console.Write(form.Item1 + ": ");
                 var smoother = new SavitzkyGolaySmoother(parameters.NumPointForSmoothing, 2);

                 // Generate Theoretical Isotopic Profile
                 List<Peak> theoreticalIsotopicProfilePeakList = null;
                 if (target.CompositionWithAdduct != null)
                 {
                     string empiricalFormula = target.CompositionWithAdduct.ToPlainString();
                     var theoreticalFeatureGenerator = new JoshTheorFeatureGenerator();
                     IsotopicProfile theoreticalIsotopicProfile = theoreticalFeatureGenerator.GenerateTheorProfile(empiricalFormula, 1);
                     theoreticalIsotopicProfilePeakList = theoreticalIsotopicProfile.Peaklist.Cast<Peak>().ToList();
                 }

                 // Generate VoltageSeparatedAccumulatedXICs
                 var uimfReader = new DataReader(fileLocation);
                 VoltageSeparatedAccumulatedXiCs accumulatedXiCs = new VoltageSeparatedAccumulatedXiCs(uimfReader, target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm, parameters.DriftTubeLengthInCm);

                 var voltageGroup = accumulatedXiCs.Keys.First();

                 // Find peaks using multidimensional peak finder.
                 List<IntensityPoint> intensityPoints = accumulatedXiCs[voltageGroup].IntensityPoints;
                 List<FeatureBlob> featureBlobs = PeakFinding.FindPeakUsingWatershed(intensityPoints, smoother, parameters.FeatureFilterLevel);
                 List<StandardImsPeak> standardPeaks = featureBlobs.Select(featureBlob => new StandardImsPeak(featureBlob, uimfReader, voltageGroup,  target.MassWithAdduct, parameters.MzWindowHalfWidthInPpm)).ToList();

                 // feature scorings and Target selection.
                 double globalMaxIntensity = IMSUtil.MaxIntensityAfterFrameAccumulation(voltageGroup, uimfReader);

                 // Check each XIC Peak found
                 foreach (var peak in standardPeaks)
                 {
                     // Evaluate feature scores.
                     double intensityScore = FeatureScoreUtilities.IntensityScore(peak, globalMaxIntensity);

                     double isotopicScoreAngle = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Angle,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistance = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistance,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScorePerson = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.PearsonCorrelation,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreBhattacharyya = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.Bhattacharyya,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double isotopicScoreDistanceAlternative = FeatureScoreUtilities.IsotopicProfileScore(
                         peak,
                         workflow.uimfReader,
                         target,
                         theoreticalIsotopicProfilePeakList,
                         voltageGroup,
                         IsotopicScoreMethod.EuclideanDistanceAlternative,
                         globalMaxIntensity,
                         workflow.NumberOfScans);

                     double peakShapeScore = FeatureScoreUtilities.PeakShapeScore(peak, workflow.uimfReader, workflow.Parameters.MzWindowHalfWidthInPpm, workflow.Parameters.DriftTimeToleranceInMs, voltageGroup, globalMaxIntensity, workflow.NumberOfScans);

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", intensityScore);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreDistance);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreDistanceAlternative);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreAngle);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScorePerson);
                         found = true;
                     }

                     // Report all features.
                     if (peak.PeakApex.DriftTimeCenterInScanNumber == 115)
                     {
                         Console.Write("{0:F4} ", isotopicScoreBhattacharyya);
                         found = true;
                     }
                 }

                 if (!found)
                 {
                     Console.Write("No features");
                 }

                 Console.WriteLine();
             }

             // Manually dispose so it doesn't interfere with other tests.
             workflow.Dispose();
        }
        /// <summary>
        /// The run libray match workflow.
        /// </summary>
        /// <param name="target">
        /// The Target.
        /// </param>
        /// <returns>
        /// The <see cref="LibraryMatchResult"/>.
        /// </returns>
        private LibraryMatchResult RunLibrayMatchWorkflow(DriftTimeTarget target)
        {
            Trace.WriteLine("    Target: " + target.CorrespondingChemical);
            Trace.WriteLine("    Target Info: " + target.TargetDescriptor);

            // Generate Theoretical Isotopic Profile
            List<Peak> theoreticalIsotopicProfilePeakList = null;
            string empiricalFormula = target.CompositionWithAdduct.ToPlainString();
            ITheorFeatureGenerator featureGenerator = new JoshTheorFeatureGenerator();
            IsotopicProfile theoreticalIsotopicProfile = featureGenerator.GenerateTheorProfile(empiricalFormula, 1);
            theoreticalIsotopicProfilePeakList = theoreticalIsotopicProfile.Peaklist.Cast<Peak>().ToList();

            // Voltage grouping
            VoltageSeparatedAccumulatedXiCs accumulatedXiCs = new VoltageSeparatedAccumulatedXiCs(this.uimfReader, target.MassWithAdduct, this.Parameters.InitialSearchMassToleranceInPpm, target.NormalizedDriftTimeInMs, this.Parameters.DriftTimeToleranceInMs, this.Parameters.DriftTubeLengthInCm);

            foreach (VoltageGroup voltageGroup in accumulatedXiCs.Keys)
            {
                // TODO Verify the temperature, pressure and drift tube voltage of the voltage group
                // Because we don't record TVP info in the AMT library. we can't verify it yet, so stick with last voltage group.
                if (IMSUtil.IsLastVoltageGroup(voltageGroup, this.NumberOfFrames))
                {
                    double globalMaxIntensity = IMSUtil.MaxIntensityAfterFrameAccumulation(voltageGroup, this.uimfReader);

                    Trace.WriteLine(string.Format("    Temperature/Pressure/Voltage Adjusted Drift time: {0:F4} ms", IMSUtil.DeNormalizeDriftTime(target.NormalizedDriftTimeInMs, voltageGroup)));

                    // Find peaks using multidimensional peak finder.
                    List<IntensityPoint> intensityPoints = accumulatedXiCs[voltageGroup].IntensityPoints;
                    List<FeatureBlob> featureBlobs = PeakFinding.FindPeakUsingWatershed(intensityPoints, this.smoother, this.Parameters.FeatureFilterLevel);
                    List<StandardImsPeak> standardPeaks = featureBlobs.Select(featureBlob => new StandardImsPeak(featureBlob, this.uimfReader, voltageGroup, target.MassWithAdduct, this.Parameters.InitialSearchMassToleranceInPpm)).ToList();

                    // Score features
                    IDictionary<StandardImsPeak, PeakScores> scoresTable = new Dictionary<StandardImsPeak, PeakScores>();
                    Trace.WriteLine(string.Format("    Voltage Group: {0:F4} V, [{1}-{2}]", voltageGroup.MeanVoltageInVolts, voltageGroup.FirstFrameNumber, voltageGroup.LastFrameNumber));

                    foreach (StandardImsPeak peak in standardPeaks)
                    {
                        PeakScores currentStatistics = FeatureScoreUtilities.ScoreFeature(
                            peak,
                            globalMaxIntensity,
                            this.uimfReader,
                            this.Parameters.InitialSearchMassToleranceInPpm,
                            this.Parameters.DriftTimeToleranceInMs,
                            voltageGroup,
                            this.NumberOfScans,
                            target,
                            IsotopicScoreMethod.Angle,
                            theoreticalIsotopicProfilePeakList);
                        scoresTable.Add(peak, currentStatistics);
                    }

                    // filter out features with Ims scans at 1% left or right.
                    Predicate<StandardImsPeak> scanPredicate = blob => FeatureFilters.FilterExtremeDriftTime(blob, (int)this.NumberOfScans);
                    Predicate<StandardImsPeak> shapeThreshold = blob => FeatureFilters.FilterBadPeakShape(blob, scoresTable[blob].PeakShapeScore, this.Parameters.PeakShapeThreshold);
                    Predicate<StandardImsPeak> isotopeThreshold = blob => FeatureFilters.FilterBadIsotopicProfile(blob, scoresTable[blob].IsotopicScore, this.Parameters.IsotopicThreshold);
                    Predicate<StandardImsPeak> massDistanceThreshold = blob => FeatureFilters.FilterHighMzDistance(blob, target, this.Parameters.MatchingMassToleranceInPpm);

                    // Print out candidate features that pass the intensity threshold.
                    foreach (StandardImsPeak peak in standardPeaks)
                    {
                        DriftTimeFeatureDistance distance = new DriftTimeFeatureDistance(target, peak, voltageGroup);

                        bool badScanRange = scanPredicate(peak);
                        bool badPeakShape = shapeThreshold(peak);
                        bool lowIsotopicAffinity = isotopeThreshold(peak);
                        bool lowMzAffinity = massDistanceThreshold(peak);

                        PeakScores currentStatistics = scoresTable[peak];
                        Trace.WriteLine(string.Empty);
                        Trace.WriteLine(string.Format("        Candidate feature found at drift time {0:F2} ms (scan number {1})",
                            peak.PeakApex.DriftTimeCenterInMs,
                            peak.PeakApex.DriftTimeCenterInScanNumber));
                        Trace.WriteLine(
                            string.Format(
                                "            M/Z: {0:F2} Dalton", peak.PeakApex.MzCenterInDalton));
                        Trace.WriteLine(
                            string.Format(
                                "            Drift time: {0:F2} ms (scan number {1})",
                                peak.PeakApex.DriftTimeCenterInMs,
                                peak.PeakApex.DriftTimeCenterInScanNumber));
                        Trace.WriteLine(
                            string.Format("            MzInDalton difference: {0:F2} ppm", distance.MassDifferenceInPpm));

                        Trace.WriteLine(
                            string.Format("            Drift time difference: {0:F4} ms", distance.DriftTimeDifferenceInMs));

                        Trace.WriteLine(string.Format("            Intensity Score: {0:F4}", currentStatistics.IntensityScore));
                        Trace.WriteLine(string.Format("            Peak Shape Score: {0:F4}", currentStatistics.PeakShapeScore));
                        Trace.WriteLine(string.Format("            Isotopic Score:  {0:F4}", currentStatistics.IsotopicScore));
                        Trace.WriteLine(string.Format("            AveragedPeakIntensities:  {0:F4}", peak.SummedIntensities));

                        string rejectionReason = badScanRange ? "        [Bad scan range] " : "        ";
                        rejectionReason += badPeakShape ? "[Bad Peak Shape] " : string.Empty;
                        rejectionReason += lowMzAffinity ? "[Inaccurate Mass] " : string.Empty;
                        rejectionReason += lowIsotopicAffinity ? "[Different Isotopic Profile] " : string.Empty;

                        if (badScanRange || lowIsotopicAffinity || badPeakShape)
                        {
                            Trace.WriteLine(rejectionReason);
                        }
                        else
                        {
                            Trace.WriteLine("        [Pass]");
                        }
                    }

                    standardPeaks.RemoveAll(scanPredicate);

                    standardPeaks.RemoveAll(massDistanceThreshold);

                    standardPeaks.RemoveAll(shapeThreshold);

                    standardPeaks.RemoveAll(isotopeThreshold);

                    if (standardPeaks.Count == 0)
                    {
                        Trace.WriteLine(string.Format("    [No Match]"));
                        Trace.WriteLine(string.Empty);
                        return new LibraryMatchResult(null, AnalysisStatus.Negative, null);
                    }

                    StandardImsPeak closestPeak = standardPeaks.First();
                    DriftTimeFeatureDistance shortestDistance = new DriftTimeFeatureDistance(target, standardPeaks.First(), voltageGroup);
                    foreach (var peak in standardPeaks)
                    {
                        DriftTimeFeatureDistance distance = new DriftTimeFeatureDistance(target, peak, voltageGroup);
                        if (distance.CompareTo(shortestDistance) < 0)
                        {
                            closestPeak = peak;
                        }
                    }

                    Trace.WriteLine(string.Format("    [Match]"));
                    Trace.WriteLine(string.Empty);
                    return new LibraryMatchResult(closestPeak, AnalysisStatus.Positive, shortestDistance);
                }
            }

            throw new Exception("No voltage groups in the Dataset match temerature, pressure, or drift tube voltage setting from the library. Matching failed.");
        }