예제 #1
0
        public void effectOfFWHMOnFitTest()
        {
            Run run = new XCaliburRun2(xcaliburTestfile);

            var results = new ResultCollection(run);

            run.CurrentScanSet = new ScanSet(6005);

            var  isTicRequested = false;
            Task msGen          = new GenericMSGenerator(1154, 1160, isTicRequested);

            msGen.Execute(results);

            Task peakDetector = new DeconToolsPeakDetectorV2(0.5, 3, Globals.PeakFitType.QUADRATIC, false);

            peakDetector.Execute(results);


            Task decon = new HornDeconvolutor();

            decon.Execute(results);

            var result1    = results.ResultList[0];
            var resolution = result1.IsotopicProfile.GetMZofMostAbundantPeak() / result1.IsotopicProfile.GetFWHM();



            var distcreator = new MercuryDistributionCreator();

            distcreator.CreateDistribution(result1.IsotopicProfile.MonoIsotopicMass, result1.IsotopicProfile.ChargeState, resolution);
            distcreator.OffsetDistribution(result1.IsotopicProfile);

            var sb = new StringBuilder();

            var areafitter = new AreaFitter();
            var fitval     = areafitter.GetFit(distcreator.Data, run.XYData, 10);

            sb.Append(resolution);
            sb.Append("\t");
            sb.Append(fitval);
            sb.Append("\n");

            for (var fwhm = 0.001; fwhm < 0.050; fwhm = fwhm + 0.0005)
            {
                distcreator = new MercuryDistributionCreator();
                resolution  = result1.IsotopicProfile.GetMZofMostAbundantPeak() / fwhm;

                distcreator.CreateDistribution(result1.IsotopicProfile.MonoIsotopicMass, result1.IsotopicProfile.ChargeState, resolution);
                distcreator.OffsetDistribution(result1.IsotopicProfile);
                areafitter = new AreaFitter();
                fitval     = areafitter.GetFit(distcreator.Data, run.XYData, 10);

                sb.Append(resolution);
                sb.Append("\t");
                sb.Append(fitval);
                sb.Append("\n");
            }

            //Console.Write(sb.ToString());
        }
        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);
        }
예제 #3
0
        public void fitterOnRapidDataTest1()
        {
            Run run = new XCaliburRun2(xcaliburTestfile);

            ResultCollection results = new ResultCollection(run);

            run.CurrentScanSet = new ScanSet(6067);

            bool isTicRequested = false;
            Task msGen          = new GenericMSGenerator(1154, 1158, isTicRequested);

            msGen.Execute(results);

            DeconToolsV2.Peaks.clsPeakProcessorParameters detectorParams = new DeconToolsV2.Peaks.clsPeakProcessorParameters();
            detectorParams.PeakBackgroundRatio    = 0.5;
            detectorParams.PeakFitType            = DeconToolsV2.Peaks.PEAK_FIT_TYPE.QUADRATIC;
            detectorParams.SignalToNoiseThreshold = 3;
            detectorParams.ThresholdedData        = false;

            Task peakDetector = new DeconToolsPeakDetectorV2(detectorParams);

            peakDetector.Execute(results);


            Task decon = new RapidDeconvolutor();

            decon.Execute(results);


            IsosResult result1    = results.ResultList[0];
            double     resolution = result1.IsotopicProfile.GetMZofMostAbundantPeak() / result1.IsotopicProfile.GetFWHM();


            MercuryDistributionCreator distcreator = new MercuryDistributionCreator();

            distcreator.CreateDistribution(result1.IsotopicProfile.MonoIsotopicMass, result1.IsotopicProfile.ChargeState, resolution);
            distcreator.OffsetDistribution(result1.IsotopicProfile);



            XYData theorXYData = distcreator.Data;

            // theorXYData.Display();

            AreaFitter areafitter = new AreaFitter();
            double     fitval     = areafitter.GetFit(theorXYData, run.XYData, 10);

            Console.WriteLine(result1.IsotopicProfile.Score + "\t" + fitval);
            Console.WriteLine((result1.IsotopicProfile.Score - fitval) / result1.IsotopicProfile.Score * 100);

            Assert.AreEqual(0.0207350903681061m, (decimal)fitval);
        }
예제 #4
0
        public void fitterOnHornDataTest1()
        {
            Run run = new XCaliburRun2(xcaliburTestfile);

            var results = new ResultCollection(run);

            run.CurrentScanSet = new ScanSet(6067);

            var  isTicRequested = false;
            Task msGen          = new GenericMSGenerator(1154, 1158, isTicRequested);

            msGen.Execute(results);

            Task peakDetector = new DeconToolsPeakDetectorV2(0.5, 3, Globals.PeakFitType.QUADRATIC, false);

            peakDetector.Execute(results);

            var deconParameters = new DeconToolsParameters();

            deconParameters.ThrashParameters.MinMSFeatureToBackgroundRatio = 2;     // PeptideMinBackgroundRatio

            Task decon = new HornDeconvolutor(deconParameters);

            decon.Execute(results);


            var result1 = results.ResultList[0];


            var distcreator = new MercuryDistributionCreator();
            var resolution  = result1.IsotopicProfile.GetMZofMostAbundantPeak() / result1.IsotopicProfile.GetFWHM();

            distcreator.CreateDistribution(result1.IsotopicProfile.MonoIsotopicMass, result1.IsotopicProfile.ChargeState, resolution);
            distcreator.OffsetDistribution(result1.IsotopicProfile);



            var theorXYData = distcreator.Data;

            //StringBuilder sb = new StringBuilder();
            //TestUtilities.GetXYValuesToStringBuilder(sb, theorXYData.Xvalues, theorXYData.Yvalues);

            //Console.WriteLine(sb.ToString());

            var areafitter = new AreaFitter();
            var fitval     = areafitter.GetFit(theorXYData, run.XYData, 10);

            Console.WriteLine(result1.IsotopicProfile.Score + "\t" + fitval);
            Console.WriteLine((result1.IsotopicProfile.Score - fitval) / result1.IsotopicProfile.Score);

            Assert.AreEqual(0.0207350903681061m, (decimal)fitval);    //TODO: fix this test... i'm getting 0.0207350903681061m
        }
예제 #5
0
        public void fitterOnHornDataTest2()
        {
            Run run = new XCaliburRun2(xcaliburTestfile);

            var results = new ResultCollection(run);

            run.CurrentScanSet = new ScanSet(6005);

            var  isTicRequested = false;
            Task msGen          = new GenericMSGenerator(579, 582, isTicRequested);

            msGen.Execute(results);

            Task peakDetector = new DeconToolsPeakDetectorV2(0.5, 3, Globals.PeakFitType.QUADRATIC, false);

            peakDetector.Execute(results);


            Task decon = new HornDeconvolutor();

            decon.Execute(results);


            var result1    = results.ResultList[1];
            var resolution = result1.IsotopicProfile.GetMZofMostAbundantPeak() / result1.IsotopicProfile.GetFWHM();

            var distcreator = new MercuryDistributionCreator();

            distcreator.CreateDistribution(result1.IsotopicProfile.MonoIsotopicMass, result1.IsotopicProfile.ChargeState, resolution);
            var sb          = new StringBuilder();
            var theorXYData = distcreator.Data;

            //TestUtilities.GetXYValuesToStringBuilder(sb, theorXYData.Xvalues, theorXYData.Yvalues);



            distcreator.OffsetDistribution(result1.IsotopicProfile);



            TestUtilities.GetXYValuesToStringBuilder(sb, theorXYData.Xvalues, theorXYData.Yvalues);

            //Console.WriteLine(sb.ToString());

            var areafitter = new AreaFitter();
            var fitval     = areafitter.GetFit(theorXYData, run.XYData, 10);

            Console.WriteLine(result1.IsotopicProfile.Score + "\t" + fitval);
            Console.WriteLine((result1.IsotopicProfile.Score - fitval) / result1.IsotopicProfile.Score * 100);

            Assert.AreEqual(0.0763818319332606m, (decimal)fitval);
        }
        private double getFitValue(XYData rawXYData, IsotopicProfile theorIso, IsotopicProfile isoN15)
        {
            var indexOfMostAbundantTheorPeak     = theorIso.GetIndexOfMostIntensePeak();
            var indexOfCorrespondingObservedPeak = PeakUtilities.getIndexOfClosestValue(isoN15.Peaklist,
                                                                                        theorIso.getMostIntensePeak().XValue, 0, isoN15.Peaklist.Count - 1, 0.1);

            var mzOffset = isoN15.Peaklist[indexOfCorrespondingObservedPeak].XValue - theorIso.Peaklist[indexOfMostAbundantTheorPeak].XValue;
            var fwhm     = isoN15.GetFWHM();

            var theorXYData = theorIso.GetTheoreticalIsotopicProfileXYData(isoN15.GetFWHM());

            theorXYData.OffSetXValues(mzOffset);     //May want to avoid this offset if the masses have been aligned using LCMS Warp

            areafitter = new AreaFitter();
            var fitval = areafitter.GetFit(theorXYData, rawXYData, 0.1);

            if (fitval == double.NaN || fitval > 1)
            {
                fitval = 1;
            }
            return(fitval);
        }
        private void PerformIterativeFittingAndGetAlignedProfile(XYData xyData, XYData theorXYData, int chargeState, ref IsotopicProfile theorIso, ref double bestFitVal)
        {
            if (xyData == null || xyData.Xvalues.Length == 0)
            {
                bestFitVal = 1;
                return;
            }

            double relIntensityUseForFitting = 0;

            int ionCountUsed;
            var fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed);

            if (fitval < bestFitVal)
            {
                bestFitVal = fitval;
            }

            double bestOffsetForTheorProfile = 0;

            // move fitting window to the left
            for (var numPeaksToTheLeft = 1; numPeaksToTheLeft < 10; numPeaksToTheLeft++)
            {
                var offsetForTheorProfile = -1 * numPeaksToTheLeft * Globals.MASS_DIFF_BETWEEN_ISOTOPICPEAKS / chargeState;
                //negative offset

                fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed, offsetForTheorProfile);

                if (fitval > bestFitVal || fitval >= 1 || double.IsNaN(fitval))
                {
                    break;
                }

                bestFitVal = fitval;
                bestOffsetForTheorProfile = offsetForTheorProfile;
            }

            //move fitting window to the right
            for (var numPeaksToTheRight = 1; numPeaksToTheRight < 10; numPeaksToTheRight++)
            {
                var offsetForTheorProfile = numPeaksToTheRight * Globals.MASS_DIFF_BETWEEN_ISOTOPICPEAKS / chargeState;

                fitval = _areafitter.GetFit(theorXYData, xyData, relIntensityUseForFitting, out ionCountUsed, offsetForTheorProfile);

                if (fitval >= bestFitVal || fitval >= 1 || double.IsNaN(fitval))
                {
                    break;
                }

                bestFitVal = fitval;
                bestOffsetForTheorProfile = offsetForTheorProfile;
            }


            foreach (var theorMSPeak in theorIso.Peaklist)
            {
                theorMSPeak.XValue = theorMSPeak.XValue + bestOffsetForTheorProfile;
            }

            theorIso.MonoPeakMZ = theorIso.getMonoPeak().XValue;

            theorIso.MonoIsotopicMass        = (theorIso.MonoPeakMZ - Globals.PROTON_MASS) * chargeState;
            theorIso.MostAbundantIsotopeMass = (theorIso.getMostIntensePeak().XValue - Globals.PROTON_MASS) * chargeState;
        }
예제 #8
0
        public override void Deconvolute(ResultCollection resultList)
        {
            float[] xvals = new float[1];
            float[] yvals = new float[1];
            resultList.Run.XYData.GetXYValuesAsSingles(ref xvals, ref yvals);

            int sizeOfRapidArray = 10000;

            int[]    chargeResults           = new int[sizeOfRapidArray];
            double[] intensityResults        = new double[sizeOfRapidArray];
            double[] mzResults               = new double[sizeOfRapidArray];
            double[] scoreResults            = new double[sizeOfRapidArray];
            double[] avgmassResults          = new double[sizeOfRapidArray];
            double[] massResults             = new double[sizeOfRapidArray];
            double[] mostAbundantMassResults = new double[sizeOfRapidArray];

            if (resultList.Run.PeakList == null || resultList.Run.PeakList.Count == 0)
            {
                return;
            }

            rapidPeakList = ConvertPeakListToRapidPeakList(resultList.Run.PeakList);
            if (rapidPeakList == null || rapidPeakList.Length == 0)
            {
                return;
            }

            double rapidsBackgroundIntensityParameter = (resultList.Run.CurrentBackgroundIntensity * minPeptideToBackgroundRatio);

            Transformer.PerformTransform_cluster(Convert.ToSingle(rapidsBackgroundIntensityParameter),
                                                 ref xvals, ref yvals, ref rapidPeakList, ref chargeResults,
                                                 ref intensityResults, ref mzResults, ref scoreResults, ref avgmassResults,
                                                 ref massResults, ref mostAbundantMassResults);

            GenerateResults(resultList, ref chargeResults, ref intensityResults,
                            ref mzResults, ref scoreResults,
                            ref avgmassResults, ref massResults,
                            ref mostAbundantMassResults, this.resultCombiningMode);

            if (this.IsNewFitCalculationPerformed)
            {
                //HACK:  RAPID doesn't return the peaks of the isotopic profile. And it's score is meaningless. So will iterate over
                //the results and 1) get the peaks of the isotopic profile  and  2) get a least-squares fit of the isotopic profile.
                foreach (IsosResult result in resultList.IsosResultBin)
                {
                    //create a temporary mass tag, as a data object for storing relevent info, and using the CalculateMassesForIsotopicProfile() method.
                    PeptideTarget mt = new PeptideTarget();

                    mt.ChargeState      = (short)result.IsotopicProfile.ChargeState;
                    mt.MonoIsotopicMass = result.IsotopicProfile.MonoIsotopicMass;
                    mt.MZ = (mt.MonoIsotopicMass / mt.ChargeState) + Globals.PROTON_MASS;

                    mt.EmpiricalFormula = _TomIsotopicPatternCreator.GetClosestAvnFormula(result.IsotopicProfile.MonoIsotopicMass, false);

                    mt.IsotopicProfile = _TomIsotopicPatternCreator.GetIsotopePattern(mt.EmpiricalFormula, _TomIsotopicPatternCreator.aafIsos);
                    mt.CalculateMassesForIsotopicProfile(mt.ChargeState);

                    double toleranceInPPM = calcToleranceInPPMFromIsotopicProfile(result.IsotopicProfile);

                    //this finds the isotopic profile based on the theor. isotopic profile.
                    BasicTFF bff = new BasicTFF(toleranceInPPM, false);

                    IsotopicProfile iso = bff.FindMSFeature(resultList.Run.PeakList, mt.IsotopicProfile);

                    if (iso != null && iso.Peaklist != null && iso.Peaklist.Count > 1)
                    {
                        //start at the second peak... and add the newly found peaks
                        for (int i = 1; i < iso.Peaklist.Count; i++)
                        {
                            result.IsotopicProfile.Peaklist.Add(iso.Peaklist[i]);
                        }

                        //now that we have the peaks, we can get info for MonoPlusTwoAbundance
                        result.IsotopicProfile.MonoPlusTwoAbundance = result.IsotopicProfile.GetMonoPlusTwoAbundance();
                    }

                    XYData theorXYData = mt.IsotopicProfile.GetTheoreticalIsotopicProfileXYData(result.IsotopicProfile.GetFWHM());

                    //offset the theor isotopic profile
                    offsetDistribution(theorXYData, mt.IsotopicProfile, result.IsotopicProfile);

                    AreaFitter areafitter = new AreaFitter();
                    int        ionCountUsed;
                    double     fitval = areafitter.GetFit(theorXYData, result.Run.XYData, 0.1, out ionCountUsed);

                    if (fitval == double.NaN || fitval > 1)
                    {
                        fitval = 1;
                    }

                    result.IsotopicProfile.Score = fitval;
                }
            }
        }