Ejemplo n.º 1
0
 public void TestRatioToStandard()
 {
     var doc = LoadTestDocument();
     foreach (var peptideGroup in doc.MoleculeGroups)
     {
         foreach (var peptide in peptideGroup.Peptides)
         {
             var peptideQuantifier = new PeptideQuantifier(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).Values,
                     peptideQuantifier.NormalizationMethod).Value;
                 Assert.AreEqual(expected, actual, .0001, "Error on replicate {0}", replicateIndex);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void GetDataRows(GroupComparisonSelector selector, IList <DataRowDetails> foldChangeDetails)
 {
     foreach (var replicateEntry in _replicateIndexes)
     {
         if (!replicateEntry.Value.IsControl &&
             !Equals(selector.GroupIdentifier, replicateEntry.Value.GroupIdentifier))
         {
             continue;
         }
         foreach (var peptide in selector.ListPeptides())
         {
             QuantificationSettings quantificationSettings = QuantificationSettings.DEFAULT
                                                             .ChangeNormalizationMethod(ComparisonDef.NormalizationMethod)
                                                             .ChangeMsLevel(selector.MsLevel);
             var peptideQuantifier = new PeptideQuantifier(GetNormalizationData, selector.Protein, peptide,
                                                           quantificationSettings)
             {
                 QValueCutoff = ComparisonDef.QValueCutoff
             };
             if (null != selector.LabelType)
             {
                 peptideQuantifier.MeasuredLabelTypes = ImmutableList.Singleton(selector.LabelType);
             }
             foreach (var quantityEntry in peptideQuantifier.GetTransitionIntensities(SrmDocument.Settings,
                                                                                      replicateEntry.Key, ComparisonDef.UseZeroForMissingPeaks))
             {
                 var dataRowDetails = new DataRowDetails
                 {
                     BioReplicate   = replicateEntry.Value.BioReplicate,
                     Control        = replicateEntry.Value.IsControl,
                     IdentityPath   = quantityEntry.Key,
                     Intensity      = Math.Max(1.0, quantityEntry.Value.Intensity),
                     Denominator    = Math.Max(1.0, quantityEntry.Value.Denominator),
                     ReplicateIndex = replicateEntry.Key,
                 };
                 foldChangeDetails.Add(dataRowDetails);
             }
         }
     }
 }
 private CalibrationCurveFitter GetCalibrationCurveFitter(SrmDocument document)
 {
     var peptideQuantifier = new PeptideQuantifier(
         document.MoleculeGroups.First(),
         document.Peptides.First(), document.Settings.PeptideSettings.Quantification);
     return new CalibrationCurveFitter(peptideQuantifier, document.Settings);
 }
Ejemplo n.º 4
0
        public static NormalizationData GetNormalizationData(SrmDocument document, bool treatMissingValuesAsZero, double?qValueCutoff)
        {
            if (!document.Settings.HasResults)
            {
                return(EMPTY);
            }
            var intensitiesByFileAndLabelType = new Dictionary <DataKey, List <double> >();
            var chromatogramSets = document.Settings.MeasuredResults.Chromatograms;

            foreach (var peptideGroup in document.MoleculeGroups)
            {
                foreach (var peptide in peptideGroup.Molecules)
                {
                    if (peptide.IsDecoy)
                    {
                        continue;
                    }
                    if (PeptideDocNode.STANDARD_TYPE_IRT == peptide.GlobalStandardType)
                    {
                        // Skip all iRT standards because they are excluded in MSstatsGC.R
                        continue;
                    }
                    foreach (var transitionGroup in peptide.TransitionGroups)
                    {
                        Dictionary <DataKey, double> ms1Areas = new Dictionary <DataKey, double>();

                        foreach (var transition in transitionGroup.Transitions)
                        {
                            if (!transition.HasResults)
                            {
                                continue;
                            }
                            for (int iResult = 0; iResult < transition.Results.Count && iResult < chromatogramSets.Count; iResult++)
                            {
                                var results = transition.Results[iResult];
                                foreach (var chromInfo in results)
                                {
                                    if (chromInfo.OptimizationStep != 0)
                                    {
                                        continue;
                                    }
                                    double?area = PeptideQuantifier.GetArea(treatMissingValuesAsZero, qValueCutoff,
                                                                            transitionGroup, transition, iResult, chromInfo);
                                    if (!area.HasValue)
                                    {
                                        continue;
                                    }

                                    var key = new DataKey(chromInfo.FileId, chromatogramSets[iResult].SampleType, transitionGroup.TransitionGroup.LabelType);
                                    if (transition.IsMs1)
                                    {
                                        double totalArea;
                                        ms1Areas.TryGetValue(key, out totalArea);
                                        totalArea    += area.Value;
                                        ms1Areas[key] = totalArea;
                                    }
                                    else
                                    {
                                        List <double> fileLabelTypeIntensities;
                                        if (!intensitiesByFileAndLabelType.TryGetValue(key, out fileLabelTypeIntensities))
                                        {
                                            fileLabelTypeIntensities = new List <double>();
                                            intensitiesByFileAndLabelType.Add(key, fileLabelTypeIntensities);
                                        }
                                        // The logarithm of the area is stored instead of the area itself.
                                        // This has a tiny impact on the way the median is calculated if there are
                                        // an even number of values
                                        fileLabelTypeIntensities.Add(Math.Log(Math.Max(area.Value, 1), 2.0));
                                    }
                                }
                            }
                        }
                        foreach (var entry in ms1Areas)
                        {
                            List <double> fileLabelTypeIntensities;
                            if (!intensitiesByFileAndLabelType.TryGetValue(entry.Key, out fileLabelTypeIntensities))
                            {
                                fileLabelTypeIntensities = new List <double>();
                                intensitiesByFileAndLabelType.Add(entry.Key, fileLabelTypeIntensities);
                            }
                            fileLabelTypeIntensities.Add(Math.Log(Math.Max(entry.Value, 1), 2.0));
                        }
                    }
                }
            }
            var data = new Dictionary <DataKey, DataValue>(intensitiesByFileAndLabelType.Count);

            foreach (var entry in intensitiesByFileAndLabelType)
            {
                data.Add(entry.Key, new DataValue(entry.Value));
            }
            return(new NormalizationData(data));
        }
Ejemplo n.º 5
0
 public CalibrationCurveFitter(PeptideQuantifier peptideQuantifier, SrmSettings srmSettings)
 {
     PeptideQuantifier = peptideQuantifier;
     SrmSettings = srmSettings;
 }