Exemplo n.º 1
0
 public static void SetStandards(IEnumerable <DbIrtPeptide> peptides, IrtStandard standard)
 {
     SetStandards(peptides, standard.Peptides.Select(pep => pep.ModifiedTarget));
 }
Exemplo n.º 2
0
        public static ProcessedIrtAverages ProcessRetentionTimes(IProgressMonitor monitor,
                                                                 IRetentionTimeProvider[] providers, DbIrtPeptide[] standardPeptideList, DbIrtPeptide[] items)
        {
            var matchedStandard = IrtStandard.WhichStandard(standardPeptideList.Select(pep => pep.ModifiedTarget));

            if (matchedStandard != null)
            {
                var dummyDoc = new SrmDocument(SrmSettingsList.GetDefault());
                using (var reader = matchedStandard.GetDocumentReader())
                {
                    if (reader != null)
                    {
                        dummyDoc = dummyDoc.ImportDocumentXml(reader,
                                                              string.Empty,
                                                              MeasuredResults.MergeAction.remove,
                                                              false,
                                                              null,
                                                              Settings.Default.StaticModList,
                                                              Settings.Default.HeavyModList,
                                                              null,
                                                              out _,
                                                              out _,
                                                              false);
                        standardPeptideList = standardPeptideList.Select(pep => new DbIrtPeptide(pep)).ToArray();
                        foreach (var dummyPep in dummyDoc.Molecules.Where(pep => pep.HasExplicitMods))
                        {
                            var standardPepIdx = standardPeptideList.IndexOf(pep => dummyPep.ModifiedTarget.Equals(pep.ModifiedTarget));
                            standardPeptideList[standardPepIdx] = new DbIrtPeptide(standardPeptideList[standardPepIdx])
                            {
                                ModifiedTarget = dummyDoc.Settings.GetModifiedSequence(dummyPep.ModifiedTarget, IsotopeLabelType.heavy, dummyPep.ExplicitMods)
                            };
                        }
                    }
                }
            }

            IProgressStatus status = new ProgressStatus(Resources.LibraryGridViewDriver_ProcessRetentionTimes_Adding_retention_times);
            var             dictPeptideAverages = new Dictionary <Target, IrtPeptideAverages>();
            var             providerData        = new List <RetentionTimeProviderData>();
            var             runCount            = 0;

            foreach (var retentionTimeProvider in providers)
            {
                if (monitor.IsCanceled)
                {
                    return(null);
                }
                monitor.UpdateProgress(status = status.ChangeMessage(string.Format(
                                                                         Resources.LibraryGridViewDriver_ProcessRetentionTimes_Converting_retention_times_from__0__,
                                                                         retentionTimeProvider.Name)));

                runCount++;

                var data = new RetentionTimeProviderData(retentionTimeProvider, standardPeptideList);
                if (data.RegressionSuccess || data.CalcRegressionWith(retentionTimeProvider, standardPeptideList, items))
                {
                    AddRetentionTimesToDict(retentionTimeProvider, data.RegressionRefined, dictPeptideAverages, standardPeptideList);
                }
                providerData.Add(data);

                monitor.UpdateProgress(status = status.ChangePercentComplete(runCount * 100 / providers.Length));
            }

            monitor.UpdateProgress(status.Complete());
            return(new ProcessedIrtAverages(dictPeptideAverages, providerData));
        }
Exemplo n.º 3
0
        public List <DbIrtPeptide> RecalibrateStandards(DbIrtPeptide[] standardPeptideList)
        {
            var peptideAllIrtTimes = new Dictionary <Target, List <Tuple <double, double> > >(); // peptide -> list of (irt, time)

            foreach (var data in ProviderData)
            {
                foreach (var peptide in data.FilteredPeptides)
                {
                    if (!peptideAllIrtTimes.TryGetValue(peptide.Target, out var pepTimes))
                    {
                        pepTimes = new List <Tuple <double, double> >();
                        peptideAllIrtTimes[peptide.Target] = pepTimes;
                    }
                    pepTimes.Add(Tuple.Create(peptide.Irt, peptide.RetentionTime.Value));
                }
            }
            var peptideBestIrtTimes = new Dictionary <Target, Tuple <double, double> >(); // peptide -> (percentile irt, percentile time)

            foreach (var peptide in peptideAllIrtTimes)
            {
                var statIrts   = new Statistics(peptide.Value.Select(p => p.Item1));
                var statTimes  = new Statistics(peptide.Value.Select(p => p.Item2));
                var percentile = IrtStandard.GetSpectrumTimePercentile(peptide.Key);
                peptideBestIrtTimes[peptide.Key] = Tuple.Create(statIrts.Percentile(percentile), statTimes.Percentile(percentile));
            }
            DbIrtPeptide min = null, max = null;

            foreach (var standard in standardPeptideList) // loop over list of standard peptides to find min/max that we have values for
            {
                if ((min == null || standard.Irt < min.Irt) && peptideBestIrtTimes.ContainsKey(standard.ModifiedTarget))
                {
                    min = standard;
                }
                if ((max == null || standard.Irt > max.Irt) && peptideBestIrtTimes.ContainsKey(standard.ModifiedTarget))
                {
                    max = standard;
                }
            }
            if (min == null || max == null)
            {
                throw new Exception(Resources.EditIrtCalcDlg_RecalibrateStandards_Could_not_get_a_minimum_or_maximum_standard_peptide_);
            }

            var statX                  = new Statistics(peptideBestIrtTimes[min.ModifiedTarget].Item2, peptideBestIrtTimes[max.ModifiedTarget].Item2);
            var statY                  = new Statistics(peptideBestIrtTimes[min.ModifiedTarget].Item1, peptideBestIrtTimes[max.ModifiedTarget].Item1);
            var line                   = new RegressionLine(statY.Slope(statX), statY.Intercept(statX));
            var newStandardPeptideList = new List <DbIrtPeptide>();

            foreach (var peptide in standardPeptideList)
            {
                if (!peptideBestIrtTimes.TryGetValue(peptide.ModifiedTarget, out var times))
                {
                    throw new Exception(Resources.ProcessedIrtAverages_RecalibrateStandards_A_standard_peptide_was_missing_when_trying_to_recalibrate_);
                }
                newStandardPeptideList.Add(new DbIrtPeptide(peptide)
                {
                    Irt = line.GetY(times.Item2)
                });
            }
            return(newStandardPeptideList);
        }
Exemplo n.º 4
0
        public static ProcessedIrtAverages ProcessRetentionTimes(IProgressMonitor monitor,
                                                                 IRetentionTimeProvider[] providers, DbIrtPeptide[] standardPeptideList, DbIrtPeptide[] items, IrtRegressionType regressionType)
        {
            var heavyStandards  = new DbIrtPeptide[standardPeptideList.Length];
            var matchedStandard = IrtStandard.WhichStandard(standardPeptideList.Select(pep => pep.ModifiedTarget));

            if (matchedStandard != null && matchedStandard.HasDocument)
            {
                // Check embedded standard document for known standard to determine if the standard peptides should be heavy
                // Import iRT standard document into an empty document (rather than just getting the document), because importing also imports the modifications
                var standardDoc = matchedStandard.ImportTo(new SrmDocument(SrmSettingsList.GetDefault()));
                standardPeptideList = standardPeptideList.Select(pep => new DbIrtPeptide(pep)).ToArray();
                foreach (var dummyPep in standardDoc.Molecules.Where(pep => pep.HasExplicitMods))
                {
                    var standardPepIdx = standardPeptideList.IndexOf(pep => dummyPep.ModifiedTarget.Equals(pep.ModifiedTarget));
                    if (standardPepIdx < 0)
                    {
                        continue;
                    }
                    var heavyTarget = standardDoc.Settings.GetModifiedSequence(dummyPep.ModifiedTarget, IsotopeLabelType.heavy, dummyPep.ExplicitMods);
                    if (!standardPeptideList[standardPepIdx].ModifiedTarget.Equals(heavyTarget))
                    {
                        heavyStandards[standardPepIdx] = new DbIrtPeptide(standardPeptideList[standardPepIdx])
                        {
                            ModifiedTarget = heavyTarget
                        }
                    }
                    ;
                }
            }

            IProgressStatus status = new ProgressStatus(Resources.LibraryGridViewDriver_ProcessRetentionTimes_Adding_retention_times);
            var             dictPeptideAverages = new Dictionary <Target, IrtPeptideAverages>();
            var             providerData        = new List <RetentionTimeProviderData>();
            var             runCount            = 0;

            foreach (var retentionTimeProvider in providers)
            {
                if (monitor.IsCanceled)
                {
                    return(null);
                }
                monitor.UpdateProgress(status = status.ChangeMessage(string.Format(
                                                                         Resources.LibraryGridViewDriver_ProcessRetentionTimes_Converting_retention_times_from__0__,
                                                                         retentionTimeProvider.Name)));

                runCount++;

                var data = new RetentionTimeProviderData(regressionType, retentionTimeProvider, standardPeptideList, heavyStandards);
                if (data.RegressionSuccess ||
                    (ReferenceEquals(regressionType, IrtRegressionType.LINEAR) && data.CalcRegressionWith(retentionTimeProvider, standardPeptideList, items)))
                {
                    AddRetentionTimesToDict(retentionTimeProvider, data.RegressionRefined, dictPeptideAverages, standardPeptideList);
                }
                providerData.Add(data);

                monitor.UpdateProgress(status = status.ChangePercentComplete(runCount * 100 / providers.Length));
            }

            monitor.UpdateProgress(status.Complete());
            return(new ProcessedIrtAverages(dictPeptideAverages, providerData));
        }