public void UseResults() { CheckDisposed(); var document = Program.ActiveDocumentUI; if (!document.Settings.HasResults) { MessageDlg.Show(this, Resources.CalibrateIrtDlg_UseResults_The_document_must_contain_results_to_calibrate_a_standard); return; } var targetResolver = TargetResolver.MakeTargetResolver(document); calibratePeptides.TargetResolver = targetResolver; int count = document.Molecules.Count(nodePep => nodePep.SchedulingTime.HasValue); if (count > 20) { using (var dlg = new AddIrtStandardsDlg(count)) { if (dlg.ShowDialog(this) != DialogResult.OK) { return; } count = dlg.StandardCount; } } _gridViewDriver.Recalculate(document, count); }
public void MultiParser_Run_With_TargetResolver() { var resolver = new TargetResolver(); resolver.RegisterTargetType(() => new Sample_02()); resolver.RegisterTargetType(() => new Sample_03()); var mock = new MethodInvokerMock(); var called = false; mock.Action = (method, obj, parameters) => { called = true; Assert.IsTrue(method.Name == "Print"); Assert.IsTrue(obj.GetType().Name == "Sample_03"); }; MethodInvoker.Invoker = mock; Parser.Run(new[] { "sample_03.print", "-c=8", "-prefix=xyz" }, resolver); Assert.IsTrue(called); }
public PeptideGroupDocNode RemovePeptides(TargetResolver targetResolver, IEnumerable <string> pepLines) { var textTargets = TextTargets(targetResolver, pepLines); return((PeptideGroupDocNode)Protein.ChangeChildren(Protein.Molecules .Where(molecule => textTargets.ContainsKey(molecule.ModifiedTarget)).Cast <DocNode>().ToList())); }
public EditDriftTimePredictorDlg(IEnumerable <IonMobilityPredictor> existing) { _existing = existing; _showRegressions = true; InitializeComponent(); foreach (eIonMobilityUnits units in Enum.GetValues(typeof(eIonMobilityUnits))) { if (units != eIonMobilityUnits.none) // Don't present "none" as an option { comboBoxIonMobilityUnits.Items.Add(IonMobilityFilter.IonMobilityUnitsL10NString(units)); } } _smallMoleculeUI = Program.MainWindow.Document.HasSmallMolecules || Program.MainWindow.ModeUI != SrmDocument.DOCUMENT_TYPE.proteomic; if (_smallMoleculeUI) { gridMeasuredDriftTimes.Columns[COLUMN_SEQUENCE].HeaderText = Resources.EditDriftTimePredictorDlg_EditDriftTimePredictorDlg_Molecule; gridMeasuredDriftTimes.Columns[COLUMN_CHARGE].HeaderText = Resources.EditDriftTimePredictorDlg_EditDriftTimePredictorDlg_Adduct; } var targetResolver = TargetResolver.MakeTargetResolver(Program.ActiveDocumentUI); MeasuredDriftTimeSequence.TargetResolver = targetResolver; // TODO: ion mobility libraries are more complex than initially thought - leave these conversions to the mass spec vendors for now labelIonMobilityLibrary.Visible = comboLibrary.Visible = false; Icon = Resources.Skyline; _driverIonMobilityLibraryListComboDriver = new SettingsListComboDriver <IonMobilityLibrarySpec>(comboLibrary, Settings.Default.IonMobilityLibraryList); _driverIonMobilityLibraryListComboDriver.LoadList(null); UpdateControls(); }
private bool SetCalibrationPeptides(ICollection <PeptideDocNode> exclude) { CheckDisposed(); var document = Program.ActiveDocumentUI; if (!document.Settings.HasResults) { MessageDlg.Show(this, Resources.CalibrateIrtDlg_UseResults_The_document_must_contain_results_to_calibrate_a_standard); return(false); } var targetResolver = TargetResolver.MakeTargetResolver(document); _gridViewDriver.TargetResolver = targetResolver; var peptides = document.Molecules.Where(nodePep => nodePep.SchedulingTime.HasValue).ToArray(); var count = peptides.Length; if (exclude != null && exclude.Count > 0) { peptides = peptides.Where(nodePep => !exclude.Contains(nodePep)).ToArray(); count = peptides.Length; if (count < MIN_STANDARD_PEPTIDES) { MessageDlg.Show(this, ModeUIAwareStringFormat( Resources.CalibrateIrtDlg_SetCalibrationPeptides_The_document_contains_results_for__0__peptide_s__not_in_this_standard__which_is_less_than_the_minimum_requirement_of__1__to_calibrate_a_standard_, count, MIN_STANDARD_PEPTIDES)); return(false); } else if (count < MIN_SUGGESTED_STANDARD_PEPTIDES) { if (MultiButtonMsgDlg.Show(this, ModeUIAwareStringFormat( Resources.CalibrateIrtDlg_SetCalibrationPeptides_The_document_only_contains_results_for__0__peptide_s__not_in_this_standard__It_is_recommended_to_use_at_least__1__peptides_to_calibrate_a_standard__Are_you_sure_you_wish_to_continue_, count, MIN_SUGGESTED_STANDARD_PEPTIDES), MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes) { return(false); } } } if (count > 20) { using (var dlg = new AddIrtStandardsDlg(count, exclude != null && exclude.Count > 0)) { if (dlg.ShowDialog(this) != DialogResult.OK) { return(false); } count = dlg.StandardCount; } } _gridViewDriver.Recalculate(document, count, exclude); return(true); }
public void OkDialog() { var reader = new StringReader(textPeptides.Text); var standardPeptides = new List <DbIrtPeptide>(); var invalidLines = new List <string>(); string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); // Skip blank lines if (string.IsNullOrEmpty(line)) { continue; } DbIrtPeptide peptide = null; var target = TargetResolver.ResolveTarget(line); if (target == null || !_dictSequenceToPeptide.TryGetValue(target, out peptide)) // CONSIDER(bspratt) - small molecule equivalent? { invalidLines.Add(line); } standardPeptides.Add(peptide); } if (invalidLines.Count > 0) { string message; if (invalidLines.Count == 1) { message = ModeUIAwareStringFormat(Resources.ChangeIrtPeptidesDlg_OkDialog_The_sequence__0__is_not_currently_in_the_database, invalidLines[0]); MessageBox.Show(this, message, Program.Name); } else { message = TextUtil.LineSeparate(GetModeUIHelper().Translate(Resources.ChangeIrtPeptidesDlg_OkDialog_The_following_sequences_are_not_currently_in_the_database), string.Empty, TextUtil.LineSeparate(invalidLines), string.Empty, GetModeUIHelper().Translate(Resources.ChangeIrtPeptidesDlg_OkDialog_Standard_peptides_must_exist_in_the_database)); MessageBox.Show(this, message, Program.Name); } return; } _standardPeptides = standardPeptides.ToArray(); DialogResult = DialogResult.OK; }
public ChangeIrtPeptidesDlg(IList <DbIrtPeptide> irtPeptides) { TargetResolver = new TargetResolver(irtPeptides.Select(p => p.Target)); _dictSequenceToPeptide = new Dictionary <Target, DbIrtPeptide>(); foreach (var peptide in irtPeptides) { if (!_dictSequenceToPeptide.ContainsKey(peptide.ModifiedTarget)) { _dictSequenceToPeptide.Add(peptide.ModifiedTarget, peptide); } } InitializeComponent(); Peptides = irtPeptides.Where(peptide => peptide.Standard).ToArray(); }
protected override void DoTest() { var documentPath = TestFilesDir.GetTestPath("TargetResolverTest.sky"); TargetResolver resolver; RunUI(() => { SkylineWindow.OpenFile(documentPath); resolver = TargetResolver.MakeTargetResolver(SkylineWindow.DocumentUI); var target = resolver.ResolveTarget("Glc(04)"); // Find by name Assert.AreEqual("Glc(04)", target.DisplayName); target = resolver.ResolveTarget("ZXPLRDFHBYIQOX-BTBVOZEKSA-N"); // Find by InChiKey Assert.AreEqual("Glc(04)", target.DisplayName); target = resolver.ResolveTarget("PEPTIDER"); // Find by sequence Assert.AreEqual("PEPTIDER", target.DisplayName); }); }
public ChangeIrtPeptidesDlg(IList <DbIrtPeptide> irtPeptides, IEnumerable <PeptideGroupDocNode> proteins) { TargetResolver = new TargetResolver(irtPeptides.Select(p => p.Target)); _dictSequenceToPeptide = new TargetMap <DbIrtPeptide>(irtPeptides.Select(pep => new KeyValuePair <Target, DbIrtPeptide>(pep.ModifiedTarget, pep))); InitializeComponent(); comboProteins.Items.Add(new ComboBoxProtein(null)); comboProteins.Items.AddRange(proteins.Select(protein => new ComboBoxProtein(protein)) .Where(protein => protein.PeptideStrings(TargetResolver).Any()).ToArray()); comboProteins.SelectedIndex = 0; if (comboProteins.Items.Count == 1) { comboProteins.Enabled = false; } Peptides = irtPeptides.Where(peptide => peptide.Standard).ToArray(); }
public ChangeIrtPeptidesDlg(SrmDocument document, IList <DbIrtPeptide> irtPeptides) { TargetResolver = new TargetResolver(irtPeptides.Select(p => p.Target)); _dictSequenceToPeptide = new TargetMap <DbIrtPeptide>(irtPeptides.Select(pep => new KeyValuePair <Target, DbIrtPeptide>(pep.ModifiedTarget, pep))); _document = document; _picker = new IrtPeptidePicker(); InitializeComponent(); comboProteins.Items.Add(new ComboBoxProtein(null)); comboProteins.Items.AddRange(document.MoleculeGroups.Select(protein => new ComboBoxProtein(protein)) .Where(protein => protein.PeptideStrings(TargetResolver).Any()).ToArray()); comboProteins.SelectedIndex = 0; if (comboProteins.Items.Count == 1) { comboProteins.Enabled = false; } Peptides = irtPeptides.Where(peptide => peptide.Standard).ToArray(); // Find and select matching protein for (var i = 1; i < comboProteins.Items.Count; i++) { var item = (ComboBoxProtein)comboProteins.Items[i]; if (item.Protein.PeptideCount != PeptideLines.Length) { continue; } var targets = new TargetMap <bool>(((ComboBoxProtein)comboProteins.Items[i]).Protein.Peptides.Select(pep => new KeyValuePair <Target, bool>(pep.ModifiedTarget, true))); if (PeptideLines.All(line => targets.ContainsKey(new Target(line)))) { comboProteins.SelectedIndex = i; break; } } }
public IEnumerable <PeptideDocNode> RemovedPeptides(TargetResolver targetResolver, IEnumerable <string> pepLines) { var textTargets = TextTargets(targetResolver, pepLines); return(Protein.Molecules.Where(nodePep => !textTargets.ContainsKey(nodePep.ModifiedTarget))); }
public int RunTargets(string[] args, TargetResolver targetResolver) { ParserRunner parser; try { if (args.None() || args.All(a => string.IsNullOrEmpty(a))) { HandleEmptyArguments(targetResolver); return SuccessCode; } if (m_types.Length == 1) { parser = GetSingleTypeParser(args, Register); } else { Debug.Assert(m_types.Length > 1); parser = GetMultiTypesParser(args, Register); } Debug.Assert(parser != null); } catch (Exception ex) { // handle error using the first available error handler // // (if returns true - should rethrow) // if (TryHandlePrematureError(ex, targetResolver)) { throw; } else { return ErrorCode; } } var target = (targetResolver == null || targetResolver.RegisteredTypes.None()) ? null : targetResolver.Resolve(parser.Type); return parser.Run(args, target); }
/// <summary> /// Run a parser of instance verbs against instances of the verb classes /// </summary> /// <param name="args">The user arguments</param> /// <param name="targets">The instances of the verb classes</param> public int RunTargets(string[] args, params object[] targets) { var targetResolver = new TargetResolver(targets); return RunTargets(args, targetResolver); }
private bool TryHandlePrematureError(Exception ex, TargetResolver targetResolver) { var context = new ExceptionContext(ex); if (Register.RegisteredErrorHandler != null) { Register.RegisteredErrorHandler(context); return context.ReThrow; } else { for (int i = 0; i < m_types.Length; i++) { var type = m_types[i]; var errorHandler = ParserRunner.GetDefinedErrorHandlers(type).FirstOrDefault(); if (errorHandler != null) { var target = targetResolver == null ? null : targetResolver.Resolve(type); errorHandler.Invoke(target, new[] { context }); return context.ReThrow; } } } return true; }
private void HandleEmptyArguments(TargetResolver targetResolver) { if (Register.RegisteredEmptyHandler != null) { Register.RegisteredEmptyHandler(); } else if (m_types.Length == 1) { var parser = new ParserRunner(m_types.First(), Register, HelpGenerator); var target = targetResolver == null ? null : targetResolver.Resolve(m_types[0]); parser.HandleEmptyArguments(target); } }
private static TargetMap <bool> TextTargets(TargetResolver targetResolver, IEnumerable <string> pepLines) { return(new TargetMap <bool>(pepLines.Select(line => line.Trim()) .Where(line => !string.IsNullOrEmpty(line)) .Select(line => new KeyValuePair <Target, bool>(targetResolver.ResolveTarget(line), true)))); }
public IEnumerable <string> PeptideStrings(TargetResolver targetResolver) { return(Protein?.Molecules.Select(pep => targetResolver.FormatTarget(pep.ModifiedTarget)) ?? new string[0]); }
public void OkDialog() { var reader = new StringReader(textPeptides.Text); var standardPeptides = new List <DbIrtPeptide>(); var invalidLines = new List <string>(); string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(); // Skip blank lines if (string.IsNullOrEmpty(line)) { continue; } DbIrtPeptide peptide = null; var target = TargetResolver.ResolveTarget(line); if (target == null || !_dictSequenceToPeptide.TryGetValue(target, out peptide)) // CONSIDER(bspratt) - small molecule equivalent? { invalidLines.Add(line); } standardPeptides.Add(peptide); } if (invalidLines.Count > 0) { string message; if (invalidLines.Count == 1) { message = ModeUIAwareStringFormat(Resources.ChangeIrtPeptidesDlg_OkDialog_The_sequence__0__is_not_currently_in_the_database, invalidLines[0]); MessageBox.Show(this, message, Program.Name); } else { message = TextUtil.LineSeparate(GetModeUIHelper().Translate(Resources.ChangeIrtPeptidesDlg_OkDialog_The_following_sequences_are_not_currently_in_the_database), string.Empty, TextUtil.LineSeparate(invalidLines), string.Empty, GetModeUIHelper().Translate(Resources.ChangeIrtPeptidesDlg_OkDialog_Standard_peptides_must_exist_in_the_database)); MessageBox.Show(this, message, Program.Name); } return; } ReplacementProtein = null; var selected = (ComboBoxProtein)comboProteins.SelectedItem; if (selected.IsNotNull) { var removedPeptides = selected.RemovedPeptides(TargetResolver, textPeptides.Lines).ToArray(); if (removedPeptides.Any()) { switch (MultiButtonMsgDlg.Show(this, TextUtil.LineSeparate( Resources.ChangeIrtPeptidesDlg_OkDialog_The_following_peptides_were_removed_, TextUtil.LineSeparate(removedPeptides.Select(nodePep => nodePep.ModifiedSequenceDisplay)), Resources.ChangeIrtPeptidesDlg_OkDialog_Would_you_like_to_remove_them_from_the_document_), MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, true)) { case DialogResult.Yes: ReplacementProtein = selected.RemovePeptides(TargetResolver, textPeptides.Lines); break; case DialogResult.No: break; case DialogResult.Cancel: return; } } } _standardPeptides = standardPeptides.ToArray(); DialogResult = DialogResult.OK; }
public bool SetCalibrationPeptides() { CheckDisposed(); var document = Program.ActiveDocumentUI; if (!document.Settings.HasResults) { MessageDlg.Show(this, Resources.CalibrateIrtDlg_UseResults_The_document_must_contain_results_to_calibrate_a_standard); return(false); } var targetResolver = TargetResolver.MakeTargetResolver(document); _gridViewDriver.TargetResolver = targetResolver; var docTargets = document.Molecules.Where(nodePep => nodePep.SchedulingTime.HasValue).Select(nodePep => nodePep.ModifiedTarget).Distinct().ToArray(); var count = docTargets.Length; // If calibrating against another standard, exclude peptides in that standard var excludePeps = SelectedRegressionOption?.MatchedRegressionPeptides?.Select(match => match.Item2.ModifiedTarget).ToHashSet(); var exclude = excludePeps != null && excludePeps.Count > 0; if (exclude) { docTargets = docTargets.Where(target => !excludePeps.Contains(target)).ToArray(); count = docTargets.Length; } if (count < MIN_STANDARD_PEPTIDES) { MessageDlg.Show(this, ModeUIAwareStringFormat(!exclude ? Resources.CalibrateIrtDlg_UseResults_The_document_contains_results_for__0__peptides__which_is_less_than_the_minimum_requirement_of__1__to_calibrate_a_standard_ : Resources.CalibrateIrtDlg_SetCalibrationPeptides_The_document_contains_results_for__0__peptide_s__not_in_this_standard__which_is_less_than_the_minimum_requirement_of__1__to_calibrate_a_standard_, count, MIN_STANDARD_PEPTIDES)); return(false); } else if (count < MIN_SUGGESTED_STANDARD_PEPTIDES) { if (MultiButtonMsgDlg.Show(this, ModeUIAwareStringFormat(!exclude ? Resources.CalibrateIrtDlg_UseResults_The_document_contains_results_for__0__peptides__but_using_fewer_than__1__standard_peptides_is_not_recommended__Are_you_sure_you_want_to_continue_ : Resources.CalibrateIrtDlg_UseResults_The_document_contains_results_for__0__peptides_not_in_this_standard__but_using_fewer_than__1__standard_peptides_is_not_recommended__Are_you_sure_you_want_to_continue_, count, MIN_SUGGESTED_STANDARD_PEPTIDES), MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes) { return(false); } } else if (count > 20) { using (var dlg = new AddIrtStandardsDlg(count, excludePeps != null && excludePeps.Count > 0)) { if (dlg.ShowDialog(this) != DialogResult.OK) { return(false); } count = dlg.StandardCount; } } _gridViewDriver.Recalculate(document, count, SelectedRegressionOption, excludePeps); return(true); }
public MeasuredDriftTimeTable(DataGridView gridMeasuredDriftTimePeptides, TargetResolver targetResolver) { _gridMeasuredDriftTimePeptides = gridMeasuredDriftTimePeptides; _targetResolver = targetResolver; }