public static IEnumerable <RegressionOption> All(SrmDocument document) { yield return(new RegressionOption(Resources.RegressionOption_All_Fixed_points)); var docPeptides = new Dictionary <Target, PeptideDocNode>(); foreach (var nodePep in document.Peptides.Where(nodePep => nodePep.PercentileMeasuredRetentionTime.HasValue && !nodePep.IsDecoy)) { if (!docPeptides.ContainsKey(nodePep.ModifiedTarget)) { docPeptides[nodePep.ModifiedTarget] = nodePep; } } foreach (var standard in Settings.Default.IrtStandardList.Where(standard => !ReferenceEquals(standard, IrtStandard.EMPTY))) { var pepMatches = new List <Tuple <DbIrtPeptide, PeptideDocNode> >(); foreach (var pep in standard.Peptides) { if (docPeptides.TryGetValue(pep.GetNormalizedModifiedSequence(), out var nodePep)) { pepMatches.Add(Tuple.Create(pep, nodePep)); } } if (RCalcIrt.TryGetRegressionLine( pepMatches.Select(pep => (double)pep.Item2.PercentileMeasuredRetentionTime.Value).ToList(), pepMatches.Select(pep => pep.Item1.Irt).ToList(), RCalcIrt.MinStandardCount(standard.Peptides.Count), out var regressionLine)) { yield return(new RegressionOption(standard.Name, regressionLine, pepMatches, null, false, false)); } } }
private static RegressionLine GetRegression(TargetMap <double> knownIrts, DbIrtPeptide[] matchingPeptides, int?minPoints, out RegressionGraphData graphData) { graphData = null; var matchingPeptideIrts = new TargetMap <List <double> >(matchingPeptides.Select(pep => new KeyValuePair <Target, List <double> >(pep.ModifiedTarget, new List <double>()))); foreach (var pep in matchingPeptides) { var list = matchingPeptideIrts[pep.ModifiedTarget]; list.Add(pep.Irt); } var listX = new List <double>(); var listY = new List <double>(); var targets = new Dictionary <int, Target>(); foreach (var(i, kvp) in matchingPeptideIrts.Where(kvp => kvp.Value.Count > 0).Select((kvp, i) => Tuple.Create(i, kvp))) { targets[i] = kvp.Key; listX.Add(new Statistics(kvp.Value).Median()); listY.Add(knownIrts[kvp.Key]); } var regressionMinPoints = minPoints ?? RCalcIrt.MinStandardCount(knownIrts.Count); var removed = new List <Tuple <double, double> >(); if (!IrtRegression.TryGet <RegressionLine>(listX, listY, regressionMinPoints, out var regression, removed)) { return(null); } var outliers = new HashSet <int>(); for (var i = 0; i < listX.Count; i++) { if (removed.Contains(Tuple.Create(listX[i], listY[i]))) { outliers.Add(i); } } graphData = new RegressionGraphData { Title = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Linear_regression, LabelX = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Library_iRTs, LabelY = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Known_iRTs, XValues = listX.ToArray(), YValues = listY.ToArray(), Tooltips = targets.ToDictionary(target => target.Key, target => target.Value.ToString()), OutlierIndices = outliers, RegressionLine = regression, MinCorrelation = RCalcIrt.MIN_IRT_TO_TIME_CORRELATION, MinPoints = regressionMinPoints, }; return(regression as RegressionLine); }
private static void removePeptidesAndImport(IrtStandard standard, int numPeptides) { Target[] standardPeptides = null; List <Target> removedPeptides = null; RunUI(() => { standardPeptides = standard.Peptides.Select(pep => pep.Target).ToArray(); removedPeptides = standardPeptides.Except(SkylineWindow.DocumentUI.Peptides.Select(nodePep => nodePep.ModifiedTarget)).ToList(); }); var toRemove = standardPeptides.Except(removedPeptides).ToArray(); if (numPeptides > toRemove.Length) { Assert.Fail("Not enough peptides to remove"); } for (var i = 0; i < numPeptides; i++) { RemovePeptide(toRemove[i]); removedPeptides.Add(toRemove[i]); } if (!removedPeptides.Any()) { var importResultsDlg = ShowDialog <ImportResultsDlg>(SkylineWindow.ImportResults); OkDialog(importResultsDlg, importResultsDlg.CancelDialog); return; } var docCount = standardPeptides.Length - removedPeptides.Count; if (docCount >= RCalcIrt.MinStandardCount(standardPeptides.Length)) { var allowedMissing = docCount - RCalcIrt.MinStandardCount(standardPeptides.Length); var warningDlg = ShowDialog <MultiButtonMsgDlg>(SkylineWindow.ImportResults); RunUI(() => { foreach (var pep in removedPeptides) { Assert.IsTrue(warningDlg.Message.Contains(pep.ToString())); } Assert.IsTrue(warningDlg.Message.Contains( string.Format(Resources.SkylineWindow_ImportResults_The_document_contains__0__of_these_iRT_standard_peptides_, docCount))); Assert.IsTrue(warningDlg.Message.Contains( allowedMissing > 0 ? string.Format(Resources.SkylineWindow_ImportResults_A_maximum_of__0__may_be_missing_and_or_outliers_for_a_successful_import_, allowedMissing) : Resources.SkylineWindow_ImportResults_None_may_be_missing_or_outliers_for_a_successful_import_)); }); OkDialog(warningDlg, warningDlg.BtnCancelClick); } else { var errorDlg = ShowDialog <MessageDlg>(SkylineWindow.ImportResults); RunUI(() => { foreach (var pep in removedPeptides) { Assert.IsTrue(errorDlg.Message.Contains(pep.ToString())); } Assert.IsTrue(errorDlg.Message.Contains( docCount > 0 ? string.Format(Resources.SkylineWindow_ImportResults_The_document_only_contains__0__of_these_iRT_standard_peptides_, docCount) : Resources.SkylineWindow_ImportResults_The_document_does_not_contain_any_of_these_iRT_standard_peptides_)); Assert.IsTrue(errorDlg.Message.Contains(Resources.SkylineWindow_ImportResults_Add_missing_iRT_standard_peptides_to_your_document_or_change_the_retention_time_predictor_)); }); OkDialog(errorDlg, errorDlg.OkDialog); } }