예제 #1
0
        public void TestSinglePointExternalCalibrationWithIsConcentration()
        {
            const double internalStandardConcentration = 80.0;
            var          srmDocument = LoadTestDocument();

            srmDocument = ChangeStandardConcentrationCount(srmDocument, 1);
            srmDocument = ChangeQuantificationSettings(srmDocument, QuantificationSettings.DEFAULT
                                                       .ChangeRegressionFit(RegressionFit.LINEAR_THROUGH_ZERO)
                                                       .ChangeNormalizationMethod(NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy)));
            PeptideGroupDocNode protein = srmDocument.MoleculeGroups.First();
            PeptideDocNode      peptide = protein.Peptides.First();

            peptide = peptide.ChangeInternalStandardConcentration(internalStandardConcentration);
            PeptideQuantifier      peptideQuantifier = PeptideQuantifier.GetPeptideQuantifier(srmDocument.Settings, protein, peptide);
            CalibrationCurveFitter curveFitter       = new CalibrationCurveFitter(peptideQuantifier, srmDocument.Settings);

            Assert.AreEqual(CalibrationCurveFitter.ConcentrationRatioText(IsotopeLabelType.light, IsotopeLabelType.heavy),
                            curveFitter.GetXAxisTitle());
            Assert.AreEqual(CalibrationCurveFitter.PeakAreaRatioText(IsotopeLabelType.light, IsotopeLabelType.heavy), curveFitter.GetYAxisTitle());
            var chromatograms = srmDocument.Settings.MeasuredResults.Chromatograms;

            for (int iReplicate = 0; iReplicate < chromatograms.Count; iReplicate++)
            {
                string msg       = string.Format("Replicate {0}", iReplicate);
                var    expectedY = peptide.Results[iReplicate].First().LabelRatios.First().Ratio.Ratio;
                double?actualY   = curveFitter.GetYValue(iReplicate).Value;
                Assert.IsNotNull(actualY);
                Assert.AreEqual(expectedY, actualY.Value, epsilon, msg);
                var calibrationCurve = curveFitter.GetCalibrationCurve();
                Assert.AreEqual(1, calibrationCurve.PointCount);
                var expectedConcentration = expectedY * internalStandardConcentration / calibrationCurve.Slope.Value;
                Assert.AreEqual(expectedConcentration / internalStandardConcentration,
                                curveFitter.GetCalculatedXValue(calibrationCurve, iReplicate).GetValueOrDefault(double.NaN), epsilon, msg);
                Assert.AreEqual(expectedConcentration,
                                curveFitter.GetCalculatedConcentration(calibrationCurve, iReplicate).GetValueOrDefault(double.NaN), epsilon, msg);
                var chromatogramSet = chromatograms[iReplicate];
                if (Equals(chromatogramSet.SampleType, SampleType.STANDARD) && chromatogramSet.AnalyteConcentration.HasValue)
                {
                    // Since there was only one standard, the regression line goes exactly through this sample.
                    Assert.AreEqual(expectedConcentration, chromatogramSet.AnalyteConcentration.Value * peptide.ConcentrationMultiplier.GetValueOrDefault(1.0), epsilon);
                }
            }
        }
예제 #2
0
        public void TestDilutionFactor()
        {
            var baseDocument = LoadTestDocument();

            baseDocument = ChangeQuantificationSettings(baseDocument,
                                                        QuantificationSettings.DEFAULT
                                                        .ChangeNormalizationMethod(NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy))
                                                        .ChangeRegressionFit(RegressionFit.LINEAR)
                                                        .ChangeUnits("ng/mL"));
            var baseCurveFitter = CalibrationCurveFitter.GetCalibrationCurveFitter(baseDocument.Settings,
                                                                                   baseDocument.MoleculeGroups.First(), baseDocument.Molecules.First());
            var baseCurve = baseCurveFitter.GetCalibrationCurve();
            // Set the dilution factor of each external standard to 2.0, and each unknown to 3.0
            var docWithDilutionFactor = baseDocument.ChangeMeasuredResults(
                baseDocument.MeasuredResults.ChangeChromatograms(baseDocument.MeasuredResults.Chromatograms.Select(
                                                                     chrom => Equals(chrom.SampleType, SampleType.STANDARD) ? chrom.ChangeDilutionFactor(2.0) :
                                                                     chrom.ChangeDilutionFactor(3.0)).ToArray()));
            var dilutionFactorCurveFitter = CalibrationCurveFitter.GetCalibrationCurveFitter(
                docWithDilutionFactor.Settings, docWithDilutionFactor.MoleculeGroups.First(),
                docWithDilutionFactor.Molecules.First());
            var dilutionFactorCurve = dilutionFactorCurveFitter.GetCalibrationCurve();

            Assert.AreEqual(2.0 * baseCurve.Slope, dilutionFactorCurve.Slope);
            Assert.AreEqual(baseCurve.Intercept, dilutionFactorCurve.Intercept);
            for (int replicateIndex = 0; replicateIndex < baseDocument.MeasuredResults.Chromatograms.Count; replicateIndex++)
            {
                var sampleType        = baseDocument.MeasuredResults.Chromatograms[replicateIndex].SampleType;
                var baseConcentration = baseCurveFitter.GetCalculatedConcentration(baseCurve, replicateIndex);
                Assert.IsNotNull(baseConcentration);
                var dilutionFactorConcentration =
                    dilutionFactorCurveFitter.GetCalculatedConcentration(dilutionFactorCurve, replicateIndex);
                Assert.IsNotNull(dilutionFactorConcentration);
                if (Equals(sampleType, SampleType.STANDARD))
                {
                    Assert.AreEqual(baseConcentration.Value, dilutionFactorConcentration.Value, epsilon);
                }
                else
                {
                    Assert.AreEqual(1.5 * baseConcentration.Value, dilutionFactorConcentration.Value, epsilon);
                }
            }
            AssertEx.ValidatesAgainstSchema(docWithDilutionFactor);
        }
예제 #3
0
 public static IEnumerable <QuantificationSettings> ListAllQuantificationSettings()
 {
     foreach (var normalizationMethod in
              new[] { NormalizationMethod.NONE, NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy), })
     {
         foreach (var regressionFit in RegressionFit.All)
         {
             foreach (var weighting in RegressionWeighting.All)
             {
                 foreach (var msLevel in new int?[] { 1, 2, null })
                 {
                     yield return(new QuantificationSettings(weighting)
                                  .ChangeNormalizationMethod(normalizationMethod)
                                  .ChangeRegressionFit(regressionFit)
                                  .ChangeMsLevel(msLevel));
                 }
             }
         }
     }
 }
예제 #4
0
        public void TestInternalCalibration()
        {
            const double internalStandardConcentration = 80.0;
            var          srmDocument = LoadTestDocument();

            AssertEx.IsDocumentState(srmDocument, null, 1, 1, 2, 10);
            srmDocument = ChangeStandardConcentrationCount(srmDocument, 0);
            srmDocument = ChangeQuantificationSettings(srmDocument,
                                                       QuantificationSettings.DEFAULT
                                                       .ChangeRegressionFit(RegressionFit.NONE)
                                                       .ChangeNormalizationMethod(NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy))
                                                       .ChangeUnits("ng/mL"));
            PeptideGroupDocNode protein = srmDocument.MoleculeGroups.First();
            PeptideDocNode      peptide = protein.Peptides.First();

            peptide = peptide.ChangeInternalStandardConcentration(internalStandardConcentration);
            CalibrationCurveFitter curveFitter = CalibrationCurveFitter.GetCalibrationCurveFitter(srmDocument.Settings, protein, peptide);
            string expectedXAxis = CalibrationCurveFitter.AppendUnits(QuantificationStrings.Analyte_Concentration, "ng/mL");

            Assert.AreEqual(expectedXAxis, curveFitter.GetXAxisTitle());
            string expectedYAxis = CalibrationCurveFitter.PeakAreaRatioText(IsotopeLabelType.light, IsotopeLabelType.heavy);

            Assert.AreEqual(expectedYAxis, curveFitter.GetYAxisTitle());
            var chromatograms = srmDocument.Settings.MeasuredResults.Chromatograms;

            for (int iReplicate = 0; iReplicate < chromatograms.Count; iReplicate++)
            {
                string msg       = string.Format("Replicate {0}", iReplicate);
                var    expectedY = peptide.Results[iReplicate].First().LabelRatios.First().Ratio.Ratio;
                Assert.AreEqual(expectedY, curveFitter.GetYValue(iReplicate).Value, epsilon, msg);
                var calibrationCurve = curveFitter.GetCalibrationCurve();
                Assert.AreEqual(1 / internalStandardConcentration, calibrationCurve.Slope);
                Assert.IsNull(calibrationCurve.RSquared);
                Assert.AreEqual(expectedY * internalStandardConcentration,
                                curveFitter.GetCalculatedXValue(calibrationCurve, iReplicate).GetValueOrDefault(double.NaN), epsilon, msg);
                Assert.AreEqual(expectedY * internalStandardConcentration,
                                curveFitter.GetCalculatedConcentration(calibrationCurve, iReplicate).GetValueOrDefault(double.NaN), epsilon, msg);
            }
        }
예제 #5
0
        protected override void DoTest()
        {
            Settings.Default.CalibrationCurveOptions.DisplaySampleTypes = new[]
            { SampleType.UNKNOWN.Name, SampleType.QC.Name, SampleType.STANDARD.Name };
            RunUI(() => SkylineWindow.ShowCalibrationForm());
            var calibrationForm = FindOpenForm <CalibrationForm>();

            Assert.AreEqual(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_No_results_available,
                            calibrationForm.ZedGraphControl.GraphPane.Title.Text);
            PauseForScreenShot("Blank document");
            RunUI(() =>
            {
                SkylineWindow.OpenFile(TestFilesDir.GetTestPath("CalibrationTest.sky"));
            });
            Assert.AreEqual(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_Select_a_peptide_to_see_its_calibration_curve,
                            GetGraphTitle(calibrationForm));
            PauseForScreenShot("No peptide selected");

            RunUI(() => SkylineWindow.SequenceTree.SelectedPath = SkylineWindow.DocumentUI.GetPathTo(
                      (int)SrmDocument.Level.Molecules, 0));
            WaitForGraphs();
            Assert.AreEqual(QuantificationStrings.CalibrationForm_DisplayCalibrationCurve_Use_the_Quantification_tab_on_the_Peptide_Settings_dialog_to_control_the_conversion_of_peak_areas_to_concentrations_,
                            GetGraphTitle(calibrationForm));
            PauseForScreenShot("Quantification not configured");
            {
                var peptideSettingsUi = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
                RunUI(() =>
                {
                    peptideSettingsUi.SelectedTab = PeptideSettingsUI.TABS.Quantification;
                    peptideSettingsUi.QuantNormalizationMethod = NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy);
                    peptideSettingsUi.QuantUnits = "ng/mL";
                });
                PauseForScreenShot("Peptide Settings - Quantification tab");
                OkDialog(peptideSettingsUi, peptideSettingsUi.OkDialog);
            }
            PauseForScreenShot("Normalization without Internal Standard Concentration");
            WaitForOpenForm <CalibrationForm>();

            RunUI(() => SkylineWindow.ShowDocumentGrid(true));
            var documentGrid = FindOpenForm <DocumentGridForm>();

            // Now, specify an internal standard concentration.
            RunUI(() => documentGrid.ChooseView("PeptidesWithCalibration"));
            WaitForConditionUI(() => documentGrid.IsComplete);
            RunUI(() =>
            {
                var colInternalStandardQuantification =
                    documentGrid.FindColumn(PropertyPath.Root.Property("InternalStandardConcentration"));
                documentGrid.DataGridView.Rows[0].Cells[colInternalStandardQuantification.Index].Value = 80.0;
                SkylineWindow.ShowCalibrationForm();
            });

            Assert.IsNull(GetGraphTitle(calibrationForm));
            PauseForScreenShot("Internal calibration only");
            RunUI(() =>
            {
                var colInternalStandardQuantification =
                    documentGrid.FindColumn(PropertyPath.Root.Property("InternalStandardConcentration"));
                documentGrid.DataGridView.Rows[0].Cells[colInternalStandardQuantification.Index].Value = null;
            });
            FillInSampleTypesAndConcentrations();
            WaitForGraphs();
            {
                var peptideSettingsUi = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
                RunUI(() =>
                {
                    peptideSettingsUi.QuantNormalizationMethod = NormalizationMethod.NONE;
                    peptideSettingsUi.QuantRegressionFit       = RegressionFit.LINEAR;
                });
                OkDialog(peptideSettingsUi, peptideSettingsUi.OkDialog);
                RunUI(() => SkylineWindow.ShowCalibrationForm());
            }
            PauseForScreenShot("External Calibration Without Internal Standard");

            {
                var peptideSettingsUi = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
                RunUI(() => peptideSettingsUi.QuantNormalizationMethod = NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy));
                OkDialog(peptideSettingsUi, peptideSettingsUi.OkDialog);
            }
            PauseForScreenShot("External Calibration normalized to heavy");

            RunUI(() => documentGrid.ChooseView("PeptidesWithCalibration"));
            WaitForConditionUI(() => documentGrid.IsComplete);
            RunUI(() =>
            {
                var colInternalStandardQuantification =
                    documentGrid.FindColumn(PropertyPath.Root.Property("InternalStandardConcentration"));
                documentGrid.DataGridView.Rows[0].Cells[colInternalStandardQuantification.Index].Value = 80.0;
                SkylineWindow.ShowCalibrationForm();
            });
            PauseForScreenShot("External calibration with internal standard concentration specified");
            TestAllQuantificationSettings();
        }
예제 #6
0
        public void TestRatioToStandard()
        {
            var doc = LoadTestDocument();

            foreach (var peptideGroup in doc.MoleculeGroups)
            {
                foreach (var peptide in peptideGroup.Peptides)
                {
                    var peptideQuantifier = new PeptideQuantifier(null, peptideGroup, peptide,
                                                                  QuantificationSettings.DEFAULT.ChangeNormalizationMethod(NormalizationMethod.GetNormalizationMethod(IsotopeLabelType.heavy)));
                    for (int replicateIndex = 0; replicateIndex < doc.Settings.MeasuredResults.Chromatograms.Count; replicateIndex++)
                    {
                        var expected = peptide.Results[replicateIndex].First().LabelRatios.First().Ratio.Ratio;
                        var actual   = PeptideQuantifier.SumQuantities(
                            peptideQuantifier.GetTransitionIntensities(doc.Settings, replicateIndex, false).Values,
                            peptideQuantifier.NormalizationMethod).Value;
                        Assert.AreEqual(expected, actual, .0001, "Error on replicate {0}", replicateIndex);
                    }
                }
            }
        }