private PeptideSettings ValidateNewSettings(bool showMessages) { var helper = new MessageBoxHelper(this, showMessages); // Validate and hold digestion settings Enzyme enzyme = Settings.Default.GetEnzymeByName(comboEnzyme.SelectedItem.ToString()); Helpers.AssignIfEquals(ref enzyme, _peptideSettings.Enzyme); int maxMissedCleavages = int.Parse(comboMissedCleavages.SelectedItem.ToString()); bool excludeRaggedEnds = cbRaggedEnds.Checked; DigestSettings digest = new DigestSettings(maxMissedCleavages, excludeRaggedEnds); Helpers.AssignIfEquals(ref digest, Digest); var backgroundProteomeSpec = _driverBackgroundProteome.SelectedItem; BackgroundProteome backgroundProteome = BackgroundProteome.NONE; if (!backgroundProteomeSpec.IsNone) { backgroundProteome = new BackgroundProteome(backgroundProteomeSpec, true); if (backgroundProteome.DatabaseInvalid) { var message = TextUtil.LineSeparate(string.Format(Resources.PeptideSettingsUI_ValidateNewSettings_Failed_to_load_background_proteome__0__, backgroundProteomeSpec.Name), string.Format(Resources.PeptideSettingsUI_ValidateNewSettings_The_file__0__may_not_be_a_valid_proteome_file, backgroundProteomeSpec.DatabasePath)); MessageDlg.Show(this, message); tabControl1.SelectedIndex = 0; _driverBackgroundProteome.Combo.Focus(); return null; } } Helpers.AssignIfEquals(ref backgroundProteome, _peptideSettings.BackgroundProteome); // Validate and hold prediction settings string nameRT = comboRetentionTime.SelectedItem.ToString(); RetentionTimeRegression retentionTime = Settings.Default.GetRetentionTimeByName(nameRT); if (retentionTime != null && retentionTime.Calculator != null) { RetentionScoreCalculatorSpec retentionCalc = Settings.Default.GetCalculatorByName(retentionTime.Calculator.Name); // Just in case the calculator in use in the current documet got removed, // never set the calculator to null. Just keep using the one we have. if (retentionCalc != null && !ReferenceEquals(retentionCalc, retentionTime.Calculator)) retentionTime = retentionTime.ChangeCalculator(retentionCalc); } bool useMeasuredRT = cbUseMeasuredRT.Checked; double? measuredRTWindow = null; if (!string.IsNullOrEmpty(textMeasureRTWindow.Text)) { double measuredRTWindowOut; const double minWindow = PeptidePrediction.MIN_MEASURED_RT_WINDOW; const double maxWindow = PeptidePrediction.MAX_MEASURED_RT_WINDOW; if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Prediction, textMeasureRTWindow, minWindow, maxWindow, out measuredRTWindowOut)) return null; measuredRTWindow = measuredRTWindowOut; } string nameDt = comboDriftTimePredictor.SelectedItem.ToString(); DriftTimePredictor driftTimePredictor = Settings.Default.GetDriftTimePredictorByName(nameDt); if (driftTimePredictor != null && driftTimePredictor.IonMobilityLibrary != null) { IonMobilityLibrarySpec ionMobilityLibrary = Settings.Default.GetIonMobilityLibraryByName(driftTimePredictor.IonMobilityLibrary.Name); // Just in case the library in use in the current documet got removed, // never set the library to null. Just keep using the one we have. if (ionMobilityLibrary != null && !ReferenceEquals(ionMobilityLibrary, driftTimePredictor.IonMobilityLibrary)) driftTimePredictor = driftTimePredictor.ChangeLibrary(ionMobilityLibrary); } bool useLibraryDriftTime = cbUseSpectralLibraryDriftTimes.Checked; double? libraryDTResolvingPower = null; if (useLibraryDriftTime || !string.IsNullOrEmpty(textSpectralLibraryDriftTimesResolvingPower.Text)) { double libraryDTWindowOut; if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Prediction, textSpectralLibraryDriftTimesResolvingPower, null, null, out libraryDTWindowOut)) return null; string errmsg = EditDriftTimePredictorDlg.ValidateResolvingPower(libraryDTWindowOut); if (errmsg != null) { helper.ShowTextBoxError(tabControl1, (int)TABS.Prediction, textSpectralLibraryDriftTimesResolvingPower, errmsg); return null; } libraryDTResolvingPower = libraryDTWindowOut; } var prediction = new PeptidePrediction(retentionTime, driftTimePredictor, useMeasuredRT, measuredRTWindow, useLibraryDriftTime, libraryDTResolvingPower); Helpers.AssignIfEquals(ref prediction, Prediction); // Validate and hold filter settings int excludeNTermAAs; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Filter, textExcludeAAs, PeptideFilter.MIN_EXCLUDE_NTERM_AA, PeptideFilter.MAX_EXCLUDE_NTERM_AA, out excludeNTermAAs)) return null; int minPeptideLength; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Filter, textMinLength, PeptideFilter.MIN_MIN_LENGTH, PeptideFilter.MAX_MIN_LENGTH, out minPeptideLength)) return null; int maxPeptideLength; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Filter, textMaxLength, Math.Max(PeptideFilter.MIN_MAX_LENGTH, minPeptideLength), PeptideFilter.MAX_MAX_LENGTH, out maxPeptideLength)) return null; PeptideExcludeRegex[] exclusions = _driverExclusion.Chosen; bool autoSelect = cbAutoSelect.Checked; PeptideFilter filter; try { filter = new PeptideFilter(excludeNTermAAs, minPeptideLength, maxPeptideLength, exclusions, autoSelect); } catch (InvalidDataException x) { if (showMessages) MessageDlg.ShowException(this, x); return null; } Helpers.AssignIfEquals(ref filter, Filter); // Validate and hold libraries PeptideLibraries libraries; IList<LibrarySpec> librarySpecs = _driverLibrary.Chosen; if (librarySpecs.Count == 0) libraries = new PeptideLibraries(PeptidePick.library, null, null, false, librarySpecs, new Library[0]); else { int? peptideCount = null; if (cbLimitPeptides.Checked) { int peptideCountVal; if (!helper.ValidateNumberTextBox(textPeptideCount, PeptideLibraries.MIN_PEPTIDE_COUNT, PeptideLibraries.MAX_PEPTIDE_COUNT, out peptideCountVal)) return null; peptideCount = peptideCountVal; } PeptidePick pick = (PeptidePick) comboMatching.SelectedIndex; IList<Library> librariesLoaded = new Library[librarySpecs.Count]; bool documentLibrary = false; if (Libraries != null) { // Use existing library spec's, if nothing was changed. // Avoid changing the libraries, just because the the picking // algorithm changed. if (ArrayUtil.EqualsDeep(librarySpecs, Libraries.LibrarySpecs)) { librarySpecs = Libraries.LibrarySpecs; librariesLoaded = Libraries.Libraries; } documentLibrary = Libraries.HasDocumentLibrary; // Otherwise, leave the list of loaded libraries empty, // and let the LibraryManager refill it. This ensures a // clean save of library specs only in the user config, rather // than a mix of library specs and libraries. } PeptideRankId rankId = (PeptideRankId) comboRank.SelectedItem; if (comboRank.SelectedIndex == 0) rankId = null; libraries = new PeptideLibraries(pick, rankId, peptideCount, documentLibrary, librarySpecs, librariesLoaded); } Helpers.AssignIfEquals(ref libraries, Libraries); // Validate and hold modifications int maxVariableMods; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Modifications, textMaxVariableMods, PeptideModifications.MIN_MAX_VARIABLE_MODS, PeptideModifications.MAX_MAX_VARIABLE_MODS, out maxVariableMods)) return null; int maxNeutralLosses; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Modifications, textMaxNeutralLosses, PeptideModifications.MIN_MAX_NEUTRAL_LOSSES, PeptideModifications.MAX_MAX_NEUTRAL_LOSSES, out maxNeutralLosses)) return null; var standardTypes = _driverLabelType.InternalStandardTypes; PeptideModifications modifications = new PeptideModifications( _driverStaticMod.Chosen, maxVariableMods, maxNeutralLosses, _driverLabelType.GetHeavyModifications(), standardTypes); // Should not be possible to change explicit modifications in the background, // so this should be safe. CONSIDER: Document structure because of a library load? modifications = modifications.DeclareExplicitMods(_parent.DocumentUI, Settings.Default.StaticModList, Settings.Default.HeavyModList); Helpers.AssignIfEquals(ref modifications, _peptideSettings.Modifications); PeptideIntegration integration = new PeptideIntegration(_driverPeakScoringModel.SelectedItem); Helpers.AssignIfEquals(ref integration, Integration); QuantificationSettings quantification = QuantificationSettings.DEFAULT .ChangeNormalizationMethod(comboNormalizationMethod.SelectedItem as NormalizationMethod ?? NormalizationMethod.NONE) .ChangeRegressionWeighting(comboWeighting.SelectedItem as RegressionWeighting) .ChangeRegressionFit(comboRegressionFit.SelectedItem as RegressionFit) .ChangeMsLevel(_quantMsLevels[comboQuantMsLevel.SelectedIndex]) .ChangeUnits(tbxQuantUnits.Text); return new PeptideSettings(enzyme, digest, prediction, filter, libraries, modifications, integration, backgroundProteome) .ChangeAbsoluteQuantification(quantification); }
public PeptideSettings ChangePrediction(PeptidePrediction prop) { return ChangeProp(ImClone(this), im => im.Prediction = prop); }
public PeptideSettings(Enzyme enzyme, DigestSettings digestSettings, PeptidePrediction prediction, PeptideFilter filter, PeptideLibraries libraries, PeptideModifications modifications, PeptideIntegration integration, BackgroundProteome backgroundProteome ) { Enzyme = enzyme; DigestSettings = digestSettings; Prediction = prediction; Filter = filter; Libraries = libraries; Modifications = modifications; Integration = integration; BackgroundProteome = backgroundProteome; Quantification = QuantificationSettings.DEFAULT; }
public bool Equals(PeptidePrediction other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.RetentionTime, RetentionTime) && Equals(other.DriftTimePredictor, DriftTimePredictor) && Equals(other.UseLibraryDriftTimes, UseLibraryDriftTimes) && Equals(other.LibraryDriftTimesResolvingPower, LibraryDriftTimesResolvingPower) && other.UseMeasuredRTs.Equals(UseMeasuredRTs) && other.MeasuredRTWindow.Equals(MeasuredRTWindow); }
protected void TestUsePredictedTime() { const double FILTER_LENGTH = 2.7; RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("RetentionTimeFilterTest.sky"))); WaitForDocumentLoaded(); RunUI(() => SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("TestUsePredictedTime.sky"))); SetUiDocument(ChangeFullScanSettings(SkylineWindow.Document, SkylineWindow.Document.Settings.TransitionSettings.FullScan .ChangeRetentionTimeFilter(RetentionTimeFilterType.scheduling_windows, FILTER_LENGTH))); Assert.IsNull(SkylineWindow.Document.Settings.PeptideSettings.Prediction.RetentionTime); Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs); // When we try to import a file, we should get an error about not having a peptide prediction algorithm var messageDlg = ShowDialog<MessageDlg>(() => SkylineWindow.ImportResults()); RunUI(() => { Assert.AreEqual(Resources.SkylineWindow_CheckRetentionTimeFilter_NoPredictionAlgorithm, messageDlg.Message); messageDlg.Close(); }); var ssrCalcRegression = new RetentionTimeRegression("SSRCALC_FOR_RtFilterTest", new RetentionScoreCalculator(RetentionTimeRegression.SSRCALC_100_A), .63, 5.8, 1.4, new MeasuredRetentionTime[0]); // Now give the document a prediction algorithm SetUiDocument(ChangePeptidePrediction(SkylineWindow.Document, SkylineWindow.Document.Settings.PeptideSettings. Prediction.ChangeRetentionTime(ssrCalcRegression))); // Now import two result files { var importResultsDlg = ShowDialog<ImportResultsDlg>(SkylineWindow.ImportResults); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(() => { openDataSourceDialog.SelectFile("200fmol" + extension); openDataSourceDialog.SelectFile("20fmol" + extension); }); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); } WaitForResultsImport(); { var document = WaitForDocumentLoaded(); foreach (var chromatogramSet in document.Settings.MeasuredResults.Chromatograms) { foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { var peptide = tuple.Item1; if (!peptide.IsProteomic) continue; var transitionGroup = tuple.Item2; var predictedRetentionTime = ssrCalcRegression.GetRetentionTime( document.Settings.GetModifiedSequence(peptide.Peptide.Sequence, transitionGroup.TransitionGroup.LabelType, peptide.ExplicitMods)).Value; AssertChromatogramWindow(document, chromatogramSet, predictedRetentionTime - FILTER_LENGTH, predictedRetentionTime + FILTER_LENGTH, tuple.Item3); } } } ChromatogramSet chromSetForScheduling = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms[1]; // Create a SrmDocument with just the one ChromatogramSet that we are going to use for scheduling, so that // we can assert later that the chromatogram windows are where this document says they should be. SrmDocument documentForScheduling = SkylineWindow.Document.ChangeMeasuredResults( SkylineWindow.Document.Settings.MeasuredResults.ChangeChromatograms(new[] {chromSetForScheduling})); SetUiDocument(ChangePeptidePrediction(SkylineWindow.Document, SkylineWindow.Document.Settings.PeptideSettings .Prediction.ChangeUseMeasuredRTs(true).ChangeRetentionTime(null))); { var chooseSchedulingReplicatesDlg = ShowDialog<ChooseSchedulingReplicatesDlg>(SkylineWindow.ImportResults); // Choose a scheduling replicate (the one saved above) RunUI(() => Assert.IsTrue(chooseSchedulingReplicatesDlg.TrySetReplicateChecked( chromSetForScheduling, true))); var importResultsDlg = ShowDialog<ImportResultsDlg>(chooseSchedulingReplicatesDlg.OkDialog); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(()=>openDataSourceDialog.SelectFile("40fmol" + extension)); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); } WaitForResultsImport(); { var document = WaitForDocumentLoaded(); var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "40fmol"); int countNull = 0; foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { var prediction = new PeptidePrediction(null, null, true, 1, false, 0); double windowRtIgnored; var schedulingPeptide = documentForScheduling.Molecules.First(pep => ReferenceEquals(pep.Peptide, tuple.Item1.Peptide)); var schedulingTransitionGroup = (TransitionGroupDocNode) schedulingPeptide.FindNode(tuple.Item2.TransitionGroup); double? predictedRt = prediction.PredictRetentionTime(documentForScheduling, schedulingPeptide, schedulingTransitionGroup, null, ExportSchedulingAlgorithm.Average, true, out windowRtIgnored); if (!predictedRt.HasValue) { countNull++; continue; } AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH, predictedRt.Value + FILTER_LENGTH, tuple.Item3); } Assert.AreEqual((TestSmallMolecules ? 1 : 0), countNull); } // Test using iRT with auto-calculated regression { const string calcName = "TestCalculator"; const string regressionName = "TestCalculatorAutoCalcRegression"; var peptideSettingsDlg = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); var editIrtDlg = ShowDialog<EditIrtCalcDlg>(peptideSettingsDlg.AddCalculator); RunUI(() => { editIrtDlg.OpenDatabase(TestFilesDir.GetTestPath("RetentionTimeFilterTest.irtdb")); editIrtDlg.CalcName = calcName; }); SkylineWindow.BeginInvoke(new Action(editIrtDlg.OkDialog)); var multiButtonMsgDlg = WaitForOpenForm<MultiButtonMsgDlg>(); OkDialog(multiButtonMsgDlg, ()=>multiButtonMsgDlg.DialogResult = DialogResult.Yes); var editRtDlg = ShowDialog<EditRTDlg>(peptideSettingsDlg.AddRTRegression); RunUI(() => { editRtDlg.ChooseCalculator(calcName); editRtDlg.SetAutoCalcRegression(true); editRtDlg.SetRegressionName(regressionName); editRtDlg.SetTimeWindow(1.0); }); OkDialog(editRtDlg, editRtDlg.OkDialog); RunUI(() => { peptideSettingsDlg.ChooseRegression(regressionName); peptideSettingsDlg.UseMeasuredRT(false); }); OkDialog(peptideSettingsDlg, peptideSettingsDlg.OkDialog); Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs); var importResultsDlg = ShowDialog<ImportResultsDlg>(SkylineWindow.ImportResults); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(() => openDataSourceDialog.SelectFile("8fmol" + extension)); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); WaitForResultsImport(); var document = WaitForDocumentLoaded(); var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "8fmol"); var regressionLine = document.Settings.PeptideSettings.Prediction.RetentionTime.GetConversion( chromatogramSet.MSDataFileInfos.First().FileId); var calculator = document.Settings.PeptideSettings.Prediction.RetentionTime.Calculator; double fullGradientStartTime; double fullGradientEndTime; using (var msDataFile = new MsDataFileImpl(TestFilesDir.GetTestPath("8fmol" + extension))) { fullGradientStartTime = msDataFile.GetSpectrum(0).RetentionTime.Value; fullGradientEndTime = msDataFile.GetSpectrum(msDataFile.SpectrumCount - 1).RetentionTime.Value; } foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { if (tuple.Item1.GlobalStandardType != PeptideDocNode.STANDARD_TYPE_IRT) { double? score = calculator.ScoreSequence(document.Settings.GetModifiedSequence(tuple.Item1.Peptide.Sequence, tuple.Item2.TransitionGroup.LabelType, tuple.Item1.ExplicitMods)); if (score.HasValue) { double? predictedRt = regressionLine.GetY(score.Value); AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH, predictedRt.Value + FILTER_LENGTH, tuple.Item3); } } else { // IRT Standards get extracted for the full gradient AssertChromatogramWindow(document, chromatogramSet, fullGradientStartTime, fullGradientEndTime, tuple.Item3); } } } }
private SrmDocument ChangePeptidePrediction(SrmDocument document, PeptidePrediction peptidePrediction) { return document.ChangeSettings( document.Settings.ChangePeptideSettings( document.Settings.PeptideSettings.ChangePrediction(peptidePrediction))); }