コード例 #1
0
        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();
            //}
        }
コード例 #2
0
        public override void Execute(ResultCollection resultList)
        {
            Check.Require(resultList.CurrentTargetedResult is SipperLcmsTargetedResult, "Sipper Quantifier only works on Sipper-type result objects");
            Check.Require(resultList.Run.CurrentMassTag != null, this.Name + " failed; CurrentMassTag is empty");
            Check.Require(resultList.Run.CurrentMassTag.IsotopicProfile != null, this.Name + " failed; Theor isotopic profile is empty. Run a TheorFeatureGenerator");


            var result = (SipperLcmsTargetedResult)resultList.CurrentTargetedResult;

            result.AreaUnderDifferenceCurve = -9999;
            result.AreaUnderRatioCurve      = -9999;



            RatioVals.Xvalues = new double[] { 1, 2, 3, 4, 5, 6, 7 };
            RatioVals.Yvalues = new double[] { 0, 0, 0, 0, 0, 0, 0 };

            RatioLogVals.Xvalues = new double[] { 1, 2, 3, 4, 5, 6, 7 };
            RatioLogVals.Yvalues = new double[] { 0, 0, 0, 0, 0, 0, 0 };

            ChromatogramRSquaredVals.Clear();


            Check.Require(result != null, "No MassTagResult has been generated for CurrentMassTag");

            if (result.IsotopicProfile == null || result.IsotopicProfile.Peaklist == null || result.IsotopicProfile.Peaklist.Count < 2)
            {
                return;
            }


            var theorUnlabelledIso = resultList.Run.CurrentMassTag.IsotopicProfile.CloneIsotopicProfile();

            IsotopicProfileUtilities.NormalizeIsotopicProfile(theorUnlabelledIso);

            //PeakUtilities.TrimIsotopicProfile(unlabeledIso, 0.001);



            var sb = new StringBuilder();

            sb.Append(result.Target.ID + "\t" + result.Target.MZ.ToString("0.0000") + "\t" + result.Target.ChargeState +
                      "-----------------------------\n");


            var indexMostAbundantTheorPeak = theorUnlabelledIso.GetIndexOfMostIntensePeak();

            NormalizedIso = result.IsotopicProfile.CloneIsotopicProfile();
            IsotopicProfileUtilities.NormalizeIsotopicProfileToSpecificPeak(NormalizedIso, indexMostAbundantTheorPeak);

            //            return;


            if (result.Flags.Count > 0)
            {
                var flagstring = "";

                foreach (var resultFlag in result.Flags)
                {
                    flagstring += resultFlag.Description + ";";
                }

                result.ErrorDescription = flagstring.TrimEnd(';');
                result.FailedResult     = true;
                if (flagstring.Contains("PeakToTheLeft"))
                {
                    result.FailureType = Globals.TargetedResultFailureType.DeisotopingProblemDetected;
                }
                else
                {
                    result.FailureType = Globals.TargetedResultFailureType.QuantifierFailure;
                }
            }


            var resultPassesMinimalCriteria = (result.Score < MaximumFitScoreForFurtherProcessing && result.Flags.Count == 0);



            if (resultPassesMinimalCriteria)
            {
                //------------------------------------- Get chromatogramCorrelation data -------------------------------

                if (IsChromatogramCorrelationPerformed)
                {
                    GetChromatogramCorrelationData(result);
                }



                NormalizedAdjustedIso = NormalizedIso.CloneIsotopicProfile();

                //this is experimental!!  it attempts to correct the problems caused by Orbitraps on isotopic profile intensities
                //UpdateIsoIntensitiesUsingChromCorrData(result.ChromCorrelationData, NormalizedAdjustedIso);


                //----------------- create ratio data -------------------------------------------------------
                var ratioData = NormalizedAdjustedIso.CloneIsotopicProfile();
                for (var i = 0; i < NormalizedIso.Peaklist.Count; i++)
                {
                    if (i < theorUnlabelledIso.Peaklist.Count && theorUnlabelledIso.Peaklist[i].Height > MinimumRelativeIntensityForRatioCalc)
                    {
                        ratioData.Peaklist[i].Height = (NormalizedIso.Peaklist[i].Height / theorUnlabelledIso.Peaklist[i].Height - 1);
                    }
                    else
                    {
                        ratioData.Peaklist[i].Height = 0;
                    }
                }

                //trim off zeros from ratio data
                for (var i = ratioData.Peaklist.Count - 1; i >= 0; i--)
                {
                    if (ratioData.Peaklist[i].Height == 0)
                    {
                        ratioData.Peaklist.RemoveAt(i);
                    }
                    else
                    {
                        break;
                    }
                }

                var xvals = ratioData.Peaklist.Select((p, i) => new { peak = p, index = i }).Select(n => (double)n.index).ToList();
                var yvals = ratioData.Peaklist.Select(p => (double)p.Height).ToList();
                result.AreaUnderRatioCurve = yvals.Sum();

                RatioVals.Xvalues = xvals.ToArray();
                RatioVals.Yvalues = yvals.ToArray();


                GetLinearRegressionData(result, xvals, yvals);



                //------------- subtract unlabelled profile from normalized profile ----------------------
                var subtractedIsoData = NormalizedAdjustedIso.CloneIsotopicProfile();
                for (var i = 0; i < subtractedIsoData.Peaklist.Count; i++)
                {
                    float intensityTheorPeak = 0;
                    if (i < theorUnlabelledIso.Peaklist.Count)
                    {
                        intensityTheorPeak = theorUnlabelledIso.Peaklist[i].Height;
                    }


                    var subtractedIntensity = subtractedIsoData.Peaklist[i].Height - intensityTheorPeak;
                    if (subtractedIntensity < 0)
                    {
                        subtractedIntensity = 0;
                    }

                    subtractedIsoData.Peaklist[i].Height = subtractedIntensity;
                }


                result.AreaUnderDifferenceCurve = subtractedIsoData.Peaklist.Select(p => p.Height).Sum();
                result.NumCarbonsLabelled       = calculateNumCarbonsFromSubtractedProfile(subtractedIsoData);


                //-------------- calculate Label Distribution ------------------------------------------------
                double[] numLabelVals;
                double[] labelDistributionVals;

                var theorIntensityVals = theorUnlabelledIso.Peaklist.Select(p => (double)p.Height).ToList();
                var normalizedCorrectedIntensityVals = NormalizedAdjustedIso.Peaklist.Select(p => (double)p.Height).ToList();

                var numRightPads = 3;
                _labelingDistributionCalculator.CalculateLabelingDistribution(theorIntensityVals, normalizedCorrectedIntensityVals,
                                                                              LabeldistCalcIntensityThreshold,
                                                                              LabeldistCalcIntensityThreshold,
                                                                              out numLabelVals,
                                                                              out labelDistributionVals, true, true, 0, numRightPads, 0, 0);


                //negative distribution values are zeroed out. And, then the remaining values are adjusted such that they add up to 1.
                result.LabelDistributionVals = AdjustLabelDistributionVals(labelDistributionVals);


                double distFractionUnlabelled, distFractionLabelled, distAverageLabelsIncorporated;
                _labelingDistributionCalculator.OutputLabelingInfo(result.LabelDistributionVals, out distFractionUnlabelled,
                                                                   out distFractionLabelled,
                                                                   out distAverageLabelsIncorporated);



                //-------------- make calculations using inputs from chrom correlation data -------------------



                HighQualitySubtractedProfile = GetIsoDataPassingChromCorrelation(result.ChromCorrelationData, subtractedIsoData);

                var highQualityRatioProfileData = GetIsoDataPassingChromCorrelation(result.ChromCorrelationData, ratioData);

                if (highQualityRatioProfileData.Peaklist != null && highQualityRatioProfileData.Peaklist.Count > 0)
                {
                    result.AreaUnderDifferenceCurve = HighQualitySubtractedProfile.Peaklist.Select(p => p.Height).Sum();
                }
                else
                {
                    result.AreaUnderDifferenceCurve = 0;
                }

                if (HighQualitySubtractedProfile.Peaklist != null && HighQualitySubtractedProfile.Peaklist.Count > 0)
                {
                    result.AreaUnderRatioCurveRevised = highQualityRatioProfileData.Peaklist.Select(p => p.Height).Sum();
                }
                else
                {
                    result.AreaUnderRatioCurveRevised = 0;
                }


                var numCarbonsLabelled = GetNumCarbonsLabelledUsingAverageMassDifferences(theorUnlabelledIso,
                                                                                          HighQualitySubtractedProfile);



                //result.NumCarbonsLabelled = numCarbonsLabelled;
                result.NumCarbonsLabelled = distAverageLabelsIncorporated;

                var numCarbons = result.Target.GetAtomCountForElement("C");

                result.PercentCarbonsLabelled = (result.NumCarbonsLabelled / numCarbons) * 100;
                result.PercentPeptideLabelled = distFractionLabelled * 100;

                //if (HighQualitySubtractedProfile.Peaklist != null && HighQualitySubtractedProfile.Peaklist.Count > 0)
                //{
                //    result.PercentPeptideLabelled = HighQualitySubtractedProfile.Peaklist.Max(p => p.Height) * 100;
                //}
                //else
                //{
                //    result.PercentPeptideLabelled = 0;
                //}

                result.NumHighQualityProfilePeaks = highQualityRatioProfileData.Peaklist != null
                                                        ? highQualityRatioProfileData.Peaklist.Count
                                                        : 0;

                //Console.WriteLine();
                //Console.WriteLine(result);
                //foreach (var val in ChromatogramRSquaredVals)
                //{
                //    Console.WriteLine(val);
                //}
            }
            else
            {
                result.FailedResult = true;

                if (result.FailureType == Globals.TargetedResultFailureType.None)
                {
                    result.FailureType = Globals.TargetedResultFailureType.MinimalCriteriaNotMet;
                }
            }
        }
コード例 #3
0
        public void CalculateLabelingDistributionTest1()
        {
            // LabelDistribution calculation is based on John Chik's work
            // He provided a standard set of data here:  http://people.ucalgary.ca/~dschriem/CalcDeut/CalcDeut/
            // We will use his test values and pass it through our implementation

            /*
             *#<<<Isotope Calculation Result >>>
             #Formula: ISO:|VDWCPTGF| H2O + (H)1
             #Resolution: 10000 resolving power
             #Threshold (%): 1.0000
             #Isotope List - 5 Mass(es)
             #
             #Isotope Mass   Relative Intensity
             #     924.39202        100.0000
             #     925.39495         53.0190
             #     926.39553         20.6161
             #     927.39655          5.9286
             #     928.39781          1.3694
             */
            //observed: (from J. Chik's data)          118.8932 73.8074 34.413 14.4563 6.3169

            /*
             *  Output Data from 'CalcDeut' testing from Dave Schriemer's data (see link above)
             *  File: MS924.3_Z1_10.0-10.2_A344-351_dist.xml
             *
             *    <DeutDist startdeut='-0.0' chisq='5.80293903626e-05' content_type='numlist' distsum='1.00331024913' entries='5'>
             *       0.832945525577
             *       0.0747772118716
             *       0.0305125766799
             *       0.0704222225599
             *       -0.00534728755986
             *   </DeutDist>
             *
             *
             */
            var theorIntensities = new List <double>(new[] { 1, 0.530190, 0.206161, 0.059286, 0.013694 });
            var obsIntensities   = new List <double>(new[] { 118.8932, 73.8074, 34.413, 14.4563, 6.3169 });

            var labelDistCalc = new LabelingDistributionCalculator();

            double[] solvedXVals;
            double[] solvedYvals;

            var intensityThreshold = 0.01;

            labelDistCalc.CalculateLabelingDistribution(theorIntensities, obsIntensities, intensityThreshold, intensityThreshold, out solvedXVals, out solvedYvals,
                                                        truncateTheorBasedOnRelIntensity: false,
                                                        truncateObservedBasedOnRelIntensity: false,
                                                        leftPadding: 0,
                                                        rightPadding: 2,
                                                        numPeaksForAbsoluteTheorList: 3,
                                                        numPeaksForAbsoluteObsList: 5);

            Assert.AreEqual(0.8329455, Math.Round(solvedYvals[0]), 7);
            Assert.AreEqual(0.0747772, Math.Round(solvedYvals[1]), 7);
            Assert.AreEqual(0.0305126, Math.Round(solvedYvals[2]), 7);
            Assert.AreEqual(0.0704222, Math.Round(solvedYvals[3]), 7);
            Assert.AreEqual(-0.0053473, Math.Round(solvedYvals[4]), 7);

            var xydata = new XYData();

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

            Console.WriteLine();
            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);
        }
コード例 #4
0
        public override void Execute(ResultCollection resultList)
        {
            Check.Require(resultList.CurrentTargetedResult is SipperLcmsTargetedResult, "Sipper Quantifier only works on Sipper-type result objects");
            Check.Require(resultList.Run.CurrentMassTag != null, this.Name + " failed; CurrentMassTag is empty");
            Check.Require(resultList.Run.CurrentMassTag.IsotopicProfile != null, this.Name + " failed; Theor isotopic profile is empty. Run a TheorFeatureGenerator");

            ResetQuantifierData();


            var result = (SipperLcmsTargetedResult)resultList.CurrentTargetedResult;

            result.AreaUnderDifferenceCurve = -9999;
            result.AreaUnderRatioCurve      = -9999;

            RatioVals.Xvalues = new double[] { 1, 2, 3, 4, 5, 6, 7 };
            RatioVals.Yvalues = new double[] { 0, 0, 0, 0, 0, 0, 0 };

            ChromatogramRSquaredVals.Clear();
            FitScoreData.Clear();


            Check.Require(result != null, "No MassTagResult has been generated for CurrentMassTag");

            if (result.IsotopicProfile == null || result.IsotopicProfile.Peaklist == null || result.IsotopicProfile.Peaklist.Count < 2)
            {
                return;
            }


            var theorUnlabelledIso = resultList.Run.CurrentMassTag.IsotopicProfile.CloneIsotopicProfile();

            IsotopicProfileUtilities.NormalizeIsotopicProfile(theorUnlabelledIso);

            //PeakUtilities.TrimIsotopicProfile(unlabeledIso, 0.001);

            var indexOfCorrespondingObservedPeak = PeakUtilities.getIndexOfClosestValue(result.IsotopicProfile.Peaklist,
                                                                                        theorUnlabelledIso.getMostIntensePeak().XValue, 0, result.IsotopicProfile.Peaklist.Count - 1, 0.1);

            NormalizedIso = result.IsotopicProfile.CloneIsotopicProfile();


            if (indexOfCorrespondingObservedPeak >= 0)
            {
                IsotopicProfileUtilities.NormalizeIsotopicProfileToSpecificPeak(NormalizedIso, indexOfCorrespondingObservedPeak);
            }
            else
            {
                IsotopicProfileUtilities.NormalizeIsotopicProfile(NormalizedIso);
            }


            //insert zero intensity peaks into observed



            //            return;


            if (result.Flags.Count > 0)
            {
                var flagstring = "";

                foreach (var resultFlag in result.Flags)
                {
                    flagstring += resultFlag.Description + ";";
                }

                result.ErrorDescription = flagstring.TrimEnd(';');
                result.FailedResult     = true;
                if (flagstring.Contains("PeakToTheLeft"))
                {
                    result.FailureType = Globals.TargetedResultFailureType.DeisotopingProblemDetected;
                }
                else
                {
                    result.FailureType = Globals.TargetedResultFailureType.QuantifierFailure;
                }
            }


            var resultPassesMinimalCriteria = (result.Score < MaximumFitScoreForFurtherProcessing && result.Flags.Count == 0);

            if (resultPassesMinimalCriteria)
            {
                //------------------------------------- Get chromatogramCorrelation data -------------------------------

                if (IsChromatogramCorrelationPerformed)
                {
                    GetChromatogramCorrelationData(result);
                }

                NormalizedAdjustedIso = NormalizedIso.CloneIsotopicProfile();

                //this is experimental!!  it attempts to correct the problems caused by Orbitraps on isotopic profile intensities
                //UpdateIsoIntensitiesUsingChromCorrData(result.ChromCorrelationData, NormalizedAdjustedIso);


                //----------------- create ratio data -------------------------------------------------------
                var ratioData = NormalizedAdjustedIso.CloneIsotopicProfile();
                for (var i = 0; i < NormalizedIso.Peaklist.Count; i++)
                {
                    if (i < theorUnlabelledIso.Peaklist.Count && theorUnlabelledIso.Peaklist[i].Height > MinimumRelativeIntensityForRatioCalc)
                    {
                        ratioData.Peaklist[i].Height = (NormalizedIso.Peaklist[i].Height / theorUnlabelledIso.Peaklist[i].Height - 1);
                    }
                    else
                    {
                        ratioData.Peaklist[i].Height = 0;
                    }
                }

                //trim off zeros from ratio data
                for (var i = ratioData.Peaklist.Count - 1; i >= 0; i--)
                {
                    if (ratioData.Peaklist[i].Height == 0)
                    {
                        ratioData.Peaklist.RemoveAt(i);
                    }
                    else
                    {
                        break;
                    }
                }

                var xvals = ratioData.Peaklist.Select((p, i) => new { peak = p, index = i }).Select(n => (double)n.index).ToList();
                var yvals = ratioData.Peaklist.Select(p => (double)p.Height).ToList();
                result.AreaUnderRatioCurve = yvals.Sum();

                RatioVals.Xvalues = xvals.ToArray();
                RatioVals.Yvalues = yvals.ToArray();


                //NOTE:  Sept 23, 2013 - the 'R is no longer used.
                result.RSquaredValForRatioCurve = GetLinearRegressionData(result, xvals, yvals);



                //------------- subtract unlabelled profile from normalized profile ----------------------
                var subtractedIsoData = NormalizedAdjustedIso.CloneIsotopicProfile();
                for (var i = 0; i < subtractedIsoData.Peaklist.Count; i++)
                {
                    float intensityTheorPeak = 0;
                    if (i < theorUnlabelledIso.Peaklist.Count)
                    {
                        intensityTheorPeak = theorUnlabelledIso.Peaklist[i].Height;
                    }


                    var subtractedIntensity = subtractedIsoData.Peaklist[i].Height - intensityTheorPeak;
                    if (subtractedIntensity < 0)
                    {
                        subtractedIntensity = 0;
                    }

                    subtractedIsoData.Peaklist[i].Height = subtractedIntensity;
                }

                result.AreaUnderDifferenceCurve = subtractedIsoData.Peaklist.Select(p => p.Height).Sum();



                //----------- get data for the subtracted, labeled isotopic profile------------------------

                var peaksForLabeledIsoQuant = new List <Peak>(subtractedIsoData.Peaklist.Where(p => p.Height > 0));


                // var isoFromPartialLabelingQuantifier = _partialLabelingQuantifier.FindBestLabeledProfile(result.Target, peaksForLabeledIsoQuant);
                //FitScoreData = _partialLabelingQuantifier.FitScoreData;

                //result.FitScoreLabeledProfile = isoFromPartialLabelingQuantifier.IsotopicProfile == null ? 1.00d : isoFromPartialLabelingQuantifier.IsotopicProfile.Score;
                //result.PercentCarbonsLabelled = isoFromPartialLabelingQuantifier.PercentLabeling;

                //int numCarbons = result.Target.GetAtomCountForElement("C");
                //result.NumCarbonsLabelled = result.PercentCarbonsLabelled * numCarbons / 100;

                //StringBuilder sb = new StringBuilder();
                //sb.Append(result.Target.ID + "\t" + result.Target.MZ.ToString("0.0000") + "\t" + result.Target.ChargeState +
                //          "-----------------------------\n");

                //int counter = 0;
                //foreach (var fsData in _partialLabelingQuantifier.FitScoreData)
                //{
                //    sb.Append(fsData.Key + "\t" + fsData.Value.ToString("0.000") + "\n");
                //    counter++;
                //}

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


                //-------------- make calculations using inputs from chrom correlation data -------------------

                HighQualitySubtractedProfile = GetIsoDataPassingChromCorrelation(result.ChromCorrelationData, subtractedIsoData);


                var contiguousnessScore = GetContiguousnessScore(HighQualitySubtractedProfile);
                result.ContiguousnessScore = contiguousnessScore;

                //GORD ------------- note this section is a duplicate of the above....  choose one or the other ------------------------
                //Feb 26, 2013...  I processed the results and these look really good. ROC curve nice
                peaksForLabeledIsoQuant = new List <Peak>(HighQualitySubtractedProfile.Peaklist.Where(p => p.Height > 0));



                //calculate labeled fit score
                var isoFromPartialLabelingQuantifier = _partialLabelingQuantifier.FindBestLabeledProfile(result.Target, peaksForLabeledIsoQuant);
                FitScoreData = _partialLabelingQuantifier.FitScoreData;

                result.FitScoreLabeledProfile = isoFromPartialLabelingQuantifier.IsotopicProfile == null ? 1.00d : isoFromPartialLabelingQuantifier.IsotopicProfile.Score;
                result.PercentCarbonsLabelled = isoFromPartialLabelingQuantifier.PercentLabeling;

                var numCarbons = result.Target.GetAtomCountForElement("C");
                result.NumCarbonsLabelled = result.PercentCarbonsLabelled * numCarbons / 100;
                //end of section --------------------------------------------------------------------------


                //-------------- calculate Label Distribution ------------------------------------------------
                // see Chik et al:  http://pubs.acs.org/doi/abs/10.1021/ac050988l ; Also see Sipper paper.
                double[] numLabelVals;
                double[] labelDistributionVals;

                var theorIntensityVals = theorUnlabelledIso.Peaklist.Select(p => (double)p.Height).ToList();

                if (isoFromPartialLabelingQuantifier.IsotopicProfile != null)
                {
                    var normalizedCorrectedIntensityVals = NormalizedAdjustedIso.Peaklist.Select(p => (double)p.Height).ToList();

                    var numRightPads = 3;
                    _labelingDistributionCalculator.CalculateLabelingDistribution(theorIntensityVals, normalizedCorrectedIntensityVals,
                                                                                  LabeldistCalcIntensityThreshold,
                                                                                  LabeldistCalcIntensityThreshold,
                                                                                  out numLabelVals,
                                                                                  out labelDistributionVals, true, true, 0, numRightPads, 0, 0);


                    //negative distribution values are zeroed out. And, then the remaining values are adjusted such that they add up to 1.
                    result.LabelDistributionVals = AdjustLabelDistributionVals(labelDistributionVals);


                    double distFractionUnlabelled, distFractionLabelled, distAverageLabelsIncorporated;
                    _labelingDistributionCalculator.OutputLabelingInfo(result.LabelDistributionVals, out distFractionUnlabelled,
                                                                       out distFractionLabelled,
                                                                       out distAverageLabelsIncorporated);

                    result.PercentPeptideLabelled = distFractionLabelled * 100;
                }
                else
                {
                    result.PercentCarbonsLabelled = 0;
                }

                var highQualityRatioProfileData = GetIsoDataPassingChromCorrelation(result.ChromCorrelationData, ratioData);

                if (highQualityRatioProfileData.Peaklist != null && highQualityRatioProfileData.Peaklist.Count > 0)
                {
                    result.AreaUnderDifferenceCurve = HighQualitySubtractedProfile.Peaklist.Select(p => p.Height).Sum();
                }
                else
                {
                    result.AreaUnderDifferenceCurve = 0;
                }

                if (HighQualitySubtractedProfile.Peaklist != null && HighQualitySubtractedProfile.Peaklist.Count > 0)
                {
                    result.AreaUnderRatioCurveRevised = highQualityRatioProfileData.Peaklist.Select(p => p.Height).Sum();
                }
                else
                {
                    result.AreaUnderRatioCurveRevised = 0;
                }

                result.NumHighQualityProfilePeaks = highQualityRatioProfileData.Peaklist != null
                                                      ? highQualityRatioProfileData.Peaklist.Count
                                                      : 0;
            }
            else
            {
                result.FailedResult = true;

                if (result.FailureType == Globals.TargetedResultFailureType.None)
                {
                    result.FailureType = Globals.TargetedResultFailureType.MinimalCriteriaNotMet;
                }
            }
        }