Ejemplo n.º 1
0
        public void DetectPeaksTest1()
        {
            var    peakBR        = 1.3;
            double sigNoise      = 2;
            var    isThresholded = true;
            var    peakfitType   = DeconTools.Backend.Globals.PeakFitType.QUADRATIC;

            var testFile = FileRefs.RawDataMSFiles.OrbitrapStdFile1;

            Run run = new XCaliburRun2(testFile);

            var msgen = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);

            run.CurrentScanSet = new ScanSet(6005);

            msgen.Execute(run.ResultCollection);

            var peakDet = new DeconToolsPeakDetectorV2(peakBR, sigNoise, peakfitType, isThresholded);

            peakDet.PeaksAreStored = true;

            var peakList = peakDet.FindPeaks(run.XYData, 0, 50000);

            TestUtilities.DisplayPeaks(peakList);
        }
Ejemplo n.º 2
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()
        }
Ejemplo n.º 3
0
        public void n14N15LabelledData_TFFTest1()
        {
            double featureFinderTol = 15;
            var    featureFinderRequiresMonoPeak = false;

            var n14n15Util = new N14N15TestingUtilities();
            //get sample MS from Test Data
            var massSpectrum = n14n15Util.GetSpectrumAMTTag23140708_Z3_Sum3();  //this is the diff b/w previous test and this one
            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);

            //generate theor unlabelled profile
            var unlabelledfeatureGen = new TomTheorFeatureGenerator();

            unlabelledfeatureGen.GenerateTheorFeature(mt23140708);

            //generate theor N15-labelled profile
            var n15featureGen = new TomTheorFeatureGenerator(Globals.LabellingType.N15, 0.005);

            n15featureGen.GenerateTheorFeature(mt23140708);


            //find features in experimental data, using the theoretical profiles
            var msfeatureFinder = new BasicTFF();

            msfeatureFinder.ToleranceInPPM       = featureFinderTol;
            msfeatureFinder.NeedMonoIsotopicPeak = featureFinderRequiresMonoPeak;

            var n14profile = msfeatureFinder.FindMSFeature(msPeakList, mt23140708.IsotopicProfile);
            var n15profile = msfeatureFinder.FindMSFeature(msPeakList, mt23140708.IsotopicProfileLabelled);

            Console.WriteLine(mt23140708.GetEmpiricalFormulaFromTargetCode());


            TestUtilities.DisplayIsotopicProfileData(mt23140708.IsotopicProfile);

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

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

            Console.WriteLine();
            TestUtilities.DisplayIsotopicProfileData(n15profile);
        }
        public void OldPeakDetectorTest1()
        {
            Run run = new XCaliburRun2(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var scan = new ScanSet(6005);


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

            peakDetector.IsDataThresholded = true;

            run.CurrentScanSet = scan;

            msgen.Execute(run.ResultCollection);

            var peaks = peakDetector.FindPeaks(run.XYData, 481.1, 481.4);

            TestUtilities.DisplayPeaks(peaks);
        }
        public void CalcOfFwhmByOldPeakdetector_Test1()
        {
            Run run = new XCaliburRun2(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var scan = new ScanSet(6005);

            var msgen        = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);
            var peakDetector = new DeconToolsPeakDetectorV2();

            peakDetector.PeakToBackgroundRatio  = 1.3;
            peakDetector.SignalToNoiseThreshold = 2;
            peakDetector.PeakFitType            = Globals.PeakFitType.QUADRATIC;
            peakDetector.IsDataThresholded      = true;


            var oldPeakDetector = new DeconToolsPeakDetectorV2(1.3, 2, DeconTools.Backend.Globals.PeakFitType.QUADRATIC, true);

            peakDetector.IsDataThresholded = true;

            run.CurrentScanSet = scan;

            msgen.Execute(run.ResultCollection);

            var mzStart = 692.8;

            var mzStop = 693.2;


            var peaks = peakDetector.FindPeaks(run.XYData.Xvalues, run.XYData.Yvalues, mzStart, mzStop);

            var oldPeaks = oldPeakDetector.FindPeaks(run.XYData, mzStart, mzStop);


            TestUtilities.DisplayPeaks(peaks);

            TestUtilities.DisplayPeaks(oldPeaks);
        }
        public void NewPeakDetectorTest2()
        {
            Run run = new XCaliburRun2(FileRefs.RawDataMSFiles.OrbitrapStdFile1);

            var scan = new ScanSet(6005);

            var msgen        = MSGeneratorFactory.CreateMSGenerator(run.MSFileType);
            var peakDetector = new DeconToolsPeakDetectorV2();

            peakDetector.PeakToBackgroundRatio  = 1.3;
            peakDetector.SignalToNoiseThreshold = 2;
            peakDetector.PeakFitType            = Globals.PeakFitType.QUADRATIC;
            peakDetector.IsDataThresholded      = true;

            run.CurrentScanSet = scan;
            msgen.Execute(run.ResultCollection);

            var peaks         = peakDetector.FindPeaks(run.XYData.Xvalues, run.XYData.Yvalues, 400, 1000);
            var expectedPeaks = new List <Peak>();

            // 3 most abundant peaks
            expectedPeaks.Add(new Peak(481.274, 13084440F, 0.0079F));
            expectedPeaks.Add(new Peak(639.822, 9063344F, 0.0119F));
            expectedPeaks.Add(new Peak(579.63, 7917913F, 0.0104F));

            // 3 medium abundance peaks
            expectedPeaks.Add(new Peak(907.961, 416092.1F, 0.0187F));
            expectedPeaks.Add(new Peak(607.305, 415606.4F, 0.0114F));
            expectedPeaks.Add(new Peak(515.945, 415311F, 0.0086F));

            // 3 least abundant peaks
            expectedPeaks.Add(new Peak(861.366, 199058.3F, 0.0192F));
            expectedPeaks.Add(new Peak(479.754, 198565.2F, 0.0071F));
            expectedPeaks.Add(new Peak(935.447, 198530.2F, 0.0206F));

            var sb = new StringBuilder();

            sb.Append("Looking for " + expectedPeaks.Count + " expected peaks" + Environment.NewLine);
            sb.Append("Index\tXVal    \tYVal    \tWidth" + Environment.NewLine);

            // Look for each expected peak in the actual peaks
            foreach (var expectedPeak in (from peak in expectedPeaks orderby peak.XValue select peak))
            {
                var found = false;
                foreach (var peak in peaks)
                {
                    if (Math.Abs(expectedPeak.XValue - peak.XValue) < 0.01)
                    {
                        var widthIsDifferent = Math.Abs(expectedPeak.Width - peak.Width) > 0.001;

                        sb.Append(peak.DataIndex + "\t" + peak.XValue.ToString("0.000").PadRight(8) + "\t" + peak.Height.ToString("0").PadRight(8) + "\t" + peak.Width.ToString("0.0000") + Environment.NewLine);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    sb.Append("Expected peak not found: ");
                    sb.Append(expectedPeak.DataIndex + "\t" + expectedPeak.XValue + "\t" + expectedPeak.Height + "\t" + expectedPeak.Width.ToString("0.0000"));
                }

                Assert.IsTrue(found);
            }

            Console.WriteLine(sb.ToString());

            // Console.WriteLine("Full peak list");
            // TestUtilities.DisplayPeaks(peaks);
        }
        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
        }