public void AddModification(StaticMod mod, ModType type) { if (mod == null) { return; } ImportPeptideSearch.UserDefinedTypedMods.Add(mod); PeptideSettings newPeptideSettings = SkylineWindow.Document.Settings.PeptideSettings; var newMods = new List <StaticMod>( (type == ModType.structural ? newPeptideSettings.Modifications.StaticModifications : newPeptideSettings.Modifications.HeavyModifications) ) { mod }; newPeptideSettings = (type == ModType.structural) ? newPeptideSettings.ChangeModifications(newPeptideSettings.Modifications.ChangeStaticModifications(newMods)) : newPeptideSettings.ChangeModifications(newPeptideSettings.Modifications.ChangeHeavyModifications(newMods)); SkylineWindow.ChangeSettings(SkylineWindow.Document.Settings.ChangePeptideSettings(newPeptideSettings), true, string.Format(Resources.MatchModificationsControl_AddModification_Add__0__modification__1_, type, mod.Name)); SkylineWindow.Document.Settings.UpdateDefaultModifications(false); FillLists(SkylineWindow.Document); }
private bool AddExistingLibrary(string libraryPath) { var doc = SkylineWindow.Document; var peptideLibraries = doc.Settings.PeptideSettings.Libraries; var existingLib = peptideLibraries.LibrarySpecs.FirstOrDefault(spec => spec.FilePath == libraryPath); if (existingLib != null) { return(true); } LibrarySpec librarySpec = Settings.Default.SpectralLibraryList.FirstOrDefault(spec => spec.FilePath == libraryPath); if (librarySpec == null) { var existingNames = new HashSet <string>(); existingNames.UnionWith(Settings.Default.SpectralLibraryList.Select(spec => spec.Name)); existingNames.UnionWith(peptideLibraries.LibrarySpecs.Select(spec => spec.Name)); string libraryName = Helpers.GetUniqueName(Path.GetFileNameWithoutExtension(libraryPath), existingNames); librarySpec = LibrarySpec.CreateFromPath(libraryName, libraryPath); } peptideLibraries = peptideLibraries.ChangeLibrarySpecs(peptideLibraries.LibrarySpecs.Append(librarySpec).ToArray()); var newSettings = doc.Settings.ChangePeptideSettings(doc.Settings.PeptideSettings.ChangeLibraries(peptideLibraries)); return(SkylineWindow.ChangeSettings(newSettings, true)); }
private bool UpdateTransitionSettings() { TransitionSettings newTransitionSettings = TransitionSettingsControl.GetTransitionSettings(this); if (newTransitionSettings == null) { return(false); } TransitionSettingsControl.SetFields(newTransitionSettings); // Only update, if anything changed Helpers.AssignIfEquals(ref newTransitionSettings, TransitionSettings); if (Equals(newTransitionSettings, TransitionSettings)) { return(true); } if (SkylineWindow.ChangeSettings(SkylineWindow.DocumentUI.Settings.ChangeTransitionSettings(newTransitionSettings), true)) { _transitionSettingsChanged = true; return(true); } return(false); }
public void AddModification(StaticMod mod, ModType type) { if (mod == null) { return; } ImportPeptideSearch.UserDefinedTypedMods.Add(mod); PeptideModifications peptideModifications = SkylineWindow.Document.Settings.PeptideSettings.Modifications; if (type == ModType.structural) { peptideModifications = peptideModifications.ChangeStaticModifications( peptideModifications.StaticModifications.Concat(new[] { mod }).ToArray()); } else { peptideModifications = peptideModifications.AddHeavyModifications(new[] { mod }); } SkylineWindow.ChangeSettings(SkylineWindow.Document.Settings.ChangePeptideSettings( SkylineWindow.Document.Settings.PeptideSettings.ChangeModifications(peptideModifications)), true, string.Format(Resources.MatchModificationsControl_AddModification_Add__0__modification__1_, type, mod.Name)); SkylineWindow.Document.Settings.UpdateDefaultModifications(false); FillLists(SkylineWindow.Document); }
private bool UpdateModificationSettings() { var newSettings = MatchModificationsControl.AddCheckedModifications(SkylineWindow.Document); if (ReferenceEquals(SkylineWindow.Document.Settings, newSettings)) { return(true); } if (SkylineWindow.ChangeSettings(newSettings, true, Resources.MatchModificationsControl_AddCheckedModifications_Add_checked_modifications)) { SkylineWindow.Document.Settings.UpdateDefaultModifications(false); _modificationSettingsChanged = true; } return(true); }
public void OkDialog() { var helper = new MessageBoxHelper(this); var charge = 0; if (textCharge.Visible && !helper.ValidateSignedNumberTextBox(textCharge, _minCharge, _maxCharge, out charge)) { return; } if (RetentionTimeWindow.HasValue && !RetentionTime.HasValue) { helper.ShowTextBoxError(textRetentionTimeWindow, Resources.Peptide_ExplicitRetentionTimeWindow_Explicit_retention_time_window_requires_an_explicit_retention_time_value_); return; } Charge = charge; // Note: order matters here, this settor indirectly updates _formulaBox.MonoMass when formula is empty if (string.IsNullOrEmpty(_formulaBox.Formula)) { // Can the text fields be understood as mz? if (!_formulaBox.ValidateAverageText(helper)) { return; } if (!_formulaBox.ValidateMonoText(helper)) { return; } } var formula = _formulaBox.Formula; var monoMass = _formulaBox.MonoMass ?? 0; var averageMass = _formulaBox.AverageMass ?? 0; if (monoMass < CustomIon.MIN_MASS || averageMass < CustomIon.MIN_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format(Resources.EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_greater_than_or_equal_to__0__, CustomIon.MIN_MASS)); return; } if (monoMass > CustomIon.MAX_MASS || averageMass > CustomIon.MAX_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format(Resources.EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_less_than_or_equal_to__0__, CustomIon.MAX_MASS)); return; } if ((_transitionSettings != null) && (!_transitionSettings.IsMeasurablePrecursor(BioMassCalc.CalculateIonMz(monoMass, charge)) || !_transitionSettings.IsMeasurablePrecursor(BioMassCalc.CalculateIonMz(averageMass, charge)))) { _formulaBox.ShowTextBoxErrorFormula(helper, Resources.SkylineWindow_AddMolecule_The_precursor_m_z_for_this_molecule_is_out_of_range_for_your_instrument_settings_); return; } if (!string.IsNullOrEmpty(_formulaBox.Formula)) { try { ResultCustomIon = new DocNodeCustomIon(formula, textName.Text); } catch (InvalidDataException x) { _formulaBox.ShowTextBoxErrorFormula(helper, x.Message); return; } } else { ResultCustomIon = new DocNodeCustomIon(monoMass, averageMass, textName.Text); } // Did user change the list of heavy labels? if (_driverLabelType != null) { PeptideModifications modifications = new PeptideModifications( _peptideSettings.Modifications.StaticModifications, _peptideSettings.Modifications.MaxVariableMods, _peptideSettings.Modifications.MaxNeutralLosses, _driverLabelType.GetHeavyModifications(), // This is the only thing the user may have altered _peptideSettings.Modifications.InternalStandardTypes); var settings = _peptideSettings.ChangeModifications(modifications); // Only update if anything changed if (!Equals(settings, _peptideSettings)) { SrmSettings newSettings = _parent.DocumentUI.Settings.ChangePeptideSettings(settings); if (!_parent.ChangeSettings(newSettings, true)) { return; } _peptideSettings = newSettings.PeptideSettings; } } // See if this combination of charge and label would conflict with any existing transition groups if (_existingIds != null && _existingIds.Any(t => { var transitionGroup = t as TransitionGroup; return(transitionGroup != null && Equals(transitionGroup.LabelType, IsotopeLabelType) && Equals(transitionGroup.PrecursorCharge, Charge) && !ReferenceEquals(t, _initialId)); })) { helper.ShowTextBoxError(textName, Resources.EditCustomMoleculeDlg_OkDialog_A_precursor_with_that_charge_and_label_type_already_exists_, textName.Text); return; } // See if this would conflict with any existing transitions if (_existingIds != null && (_existingIds.Any(t => { var transition = t as Transition; return(transition != null && ((transition.Charge == Charge) && Equals(transition.CustomIon, ResultCustomIon)) && !ReferenceEquals(t, _initialId)); }))) { helper.ShowTextBoxError(textName, Resources.EditCustomMoleculeDlg_OkDialog_A_similar_transition_already_exists_, textName.Text); return; } DialogResult = DialogResult.OK; }
private bool UpdateFullScanSettings() { var helper = new MessageBoxHelper(this); // Validate and store MS1 full-scan settings // If high resolution MS1 filtering is enabled, make sure precursor m/z type // is monoisotopic and isotope enrichments are set var precursorIsotopes = FullScanSettingsControl.PrecursorIsotopesCurrent; var precursorAnalyzerType = FullScanSettingsControl.PrecursorMassAnalyzer; var precursorMassType = TransitionSettings.Prediction.PrecursorMassType; if (precursorIsotopes == FullScanPrecursorIsotopes.None) { if (WorkflowType != Workflow.dia) { MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_UpdateFullScanSettings_Full_scan_MS1_filtering_must_be_enabled_in_order_to_import_a_peptide_search_); return(false); } else if (FullScanSettingsControl.AcquisitionMethod == FullScanAcquisitionMethod.None) { MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_UpdateFullScanSettings_Full_scan_MS1_or_MS_MS_filtering_must_be_enabled_in_order_to_import_a_peptide_search_); return(false); } } else if (precursorAnalyzerType != FullScanMassAnalyzerType.qit) { precursorMassType = MassType.Monoisotopic; if (FullScanSettingsControl.Enrichments == null) { MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers); return(false); } } if (FullScanSettingsControl.IsolationScheme == null && FullScanSettingsControl.AcquisitionMethod == FullScanAcquisitionMethod.DIA) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors); return(false); } TransitionFilter filter = TransitionSettings.Filter; if (FullScanSettingsControl.PrecursorChargesTextBox.Visible) { Adduct[] precursorCharges; if (!TransitionSettingsControl.ValidateAdductListTextBox(helper, FullScanSettingsControl.PrecursorChargesTextBox, true, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out precursorCharges)) { return(false); } precursorCharges = precursorCharges.Distinct().ToArray(); filter = TransitionSettings.Filter.ChangePeptidePrecursorCharges(precursorCharges); } if (WorkflowType == Workflow.dda && !filter.PeptideIonTypes.Contains(IonType.precursor)) { filter = filter.ChangePeptideIonTypes(new[] { IonType.precursor }); } if (!filter.AutoSelect) { filter = filter.ChangeAutoSelect(true); } Helpers.AssignIfEquals(ref filter, TransitionSettings.Filter); if (FullScanSettingsControl.IsDIA() && filter.ExclusionUseDIAWindow) { if (FullScanSettingsControl.IsolationScheme.IsAllIons) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_); return(false); } if (FullScanSettingsControl.IsolationScheme.FromResults) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_); return(false); } } TransitionFullScan fullScan; if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan)) { return(false); } Helpers.AssignIfEquals(ref fullScan, TransitionSettings.FullScan); var prediction = TransitionSettings.Prediction.ChangePrecursorMassType(precursorMassType); Helpers.AssignIfEquals(ref prediction, TransitionSettings.Prediction); TransitionSettings settings; try { settings = new TransitionSettings(prediction, filter, TransitionSettings.Libraries, TransitionSettings.Integration, TransitionSettings.Instrument, fullScan); } catch (Exception x) { MessageDlg.Show(this, x.Message); return(false); } // Only update, if anything changed if (Equals(settings, TransitionSettings)) { return(true); } if (SkylineWindow.ChangeSettings(SkylineWindow.DocumentUI.Settings.ChangeTransitionSettings(settings), true)) { _fullScanSettingsChanged = true; return(true); } return(false); }
public void OkDialog() { var helper = new MessageBoxHelper(this); var charge = 0; if (textCharge.Visible && !helper.ValidateSignedNumberTextBox(textCharge, _minCharge, _maxCharge, out charge)) { return; } var adduct = Adduct.NonProteomicProtonatedFromCharge(charge); if (RetentionTimeWindow.HasValue && !RetentionTime.HasValue) { helper.ShowTextBoxError(textRetentionTimeWindow, Resources .Peptide_ExplicitRetentionTimeWindow_Explicit_retention_time_window_requires_an_explicit_retention_time_value_); return; } if (Adduct.IsEmpty || Adduct.AdductCharge != adduct.AdductCharge) { Adduct = adduct; // Note: order matters here, this settor indirectly updates _formulaBox.MonoMass when formula is empty } if (string.IsNullOrEmpty(_formulaBox.NeutralFormula)) { // Can the text fields be understood as mz? if (!_formulaBox.ValidateAverageText(helper)) { return; } if (!_formulaBox.ValidateMonoText(helper)) { return; } } var monoMass = new TypedMass(_formulaBox.MonoMass ?? 0, MassType.Monoisotopic); var averageMass = new TypedMass(_formulaBox.AverageMass ?? 0, MassType.Average); if (monoMass < CustomMolecule.MIN_MASS || averageMass < CustomMolecule.MIN_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format( Resources .EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_greater_than_or_equal_to__0__, CustomMolecule.MIN_MASS)); return; } if (monoMass > CustomMolecule.MAX_MASS || averageMass > CustomMolecule.MAX_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format( Resources .EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_less_than_or_equal_to__0__, CustomMolecule.MAX_MASS)); return; } if ((_transitionSettings != null) && (!_transitionSettings.IsMeasurablePrecursor( adduct.MzFromNeutralMass(monoMass, MassType.Monoisotopic)) || !_transitionSettings.IsMeasurablePrecursor(adduct.MzFromNeutralMass(averageMass, MassType.Average)))) { _formulaBox.ShowTextBoxErrorFormula(helper, Resources .SkylineWindow_AddMolecule_The_precursor_m_z_for_this_molecule_is_out_of_range_for_your_instrument_settings_); return; } if (_usageMode == UsageMode.precursor) { // Only the adduct should be changing SetResult(_resultCustomMolecule, Adduct); } else if (!string.IsNullOrEmpty(_formulaBox.NeutralFormula)) { try { var name = textName.Text; if (string.IsNullOrEmpty(name)) { name = _formulaBox.NeutralFormula; // Clip off any adduct description } SetResult(new CustomMolecule(_formulaBox.NeutralFormula, name), Adduct); } catch (InvalidDataException x) { _formulaBox.ShowTextBoxErrorFormula(helper, x.Message); return; } } else { SetResult(new CustomMolecule(monoMass, averageMass, textName.Text), Adduct); } // Did user change the list of heavy labels? if (_driverLabelType != null) { PeptideModifications modifications = new PeptideModifications( _peptideSettings.Modifications.StaticModifications, _peptideSettings.Modifications.MaxVariableMods, _peptideSettings.Modifications.MaxNeutralLosses, _driverLabelType.GetHeavyModifications(), // This is the only thing the user may have altered _peptideSettings.Modifications.InternalStandardTypes); var settings = _peptideSettings.ChangeModifications(modifications); // Only update if anything changed if (!Equals(settings, _peptideSettings)) { SrmSettings newSettings = _parent.DocumentUI.Settings.ChangePeptideSettings(settings); if (!_parent.ChangeSettings(newSettings, true)) { return; } _peptideSettings = newSettings.PeptideSettings; } } // See if this combination of charge and label would conflict with any existing transition groups if (_existingIds != null && _existingIds.Any(t => { var transitionGroup = t as TransitionGroup; return(transitionGroup != null && Equals(transitionGroup.LabelType, IsotopeLabelType) && Equals(transitionGroup.PrecursorAdduct.AsFormula(), Adduct .AsFormula()) && // Compare AsFormula so proteomic and non-proteomic protonation are seen as same thing !ReferenceEquals(t, _initialId)); })) { helper.ShowTextBoxError(textName, Resources .EditCustomMoleculeDlg_OkDialog_A_precursor_with_that_adduct_and_label_type_already_exists_, textName.Text); return; } // See if this would conflict with any existing transitions if (_existingIds != null && (_existingIds.Any(t => { var transition = t as Transition; return(transition != null && (Equals(transition.Adduct.AsFormula(), Adduct.AsFormula()) && Equals(transition.CustomIon, ResultCustomMolecule)) && !ReferenceEquals(t, _initialId)); }))) { helper.ShowTextBoxError(textName, Resources.EditCustomMoleculeDlg_OkDialog_A_similar_transition_already_exists_, textName.Text); return; } DialogResult = DialogResult.OK; }
private static void ChangeSettings(Func <SrmSettings, SrmSettings> changeSettings) { RunUI(() => { SkylineWindow.ChangeSettings(changeSettings(SkylineWindow.DocumentUI.Settings), true); }); }
protected override void DoTest() { const double precursorMzAtZNeg2 = 242.0373281; const double productMzAtZNeg2 = 213.5097436; const double precursorCE = 1.23; const double precursorDT = 2.34; const double highEnergyDtOffset = -.012; const double slens = 6.789; const double coneVoltage = 7.89; const double compensationVoltage = 8.901; const double declusteringPotential = 9.012; const double precursorRT = 3.45; const double precursorRTWindow = 4.567; const string note = "noted!"; var docEmpty = SkylineWindow.Document; TestLabelsNoFormulas(); TestPrecursorTransitions(); TestTransitionListArrangementAndReporting(); string line1 = "MyMolecule\tMyMol\tMyFrag\tC34H12O4\tC34H3O\t" + precursorMzAtZNeg2 + "\t" + productMzAtZNeg2 + "\t-2\t-2\tlight\t" + precursorRT + "\t" + precursorRTWindow + "\t" + precursorCE + "\t" + note + "\t" + precursorDT + "\t" + highEnergyDtOffset + "\t" + slens + "\t" + coneVoltage + "\t" + compensationVoltage + "\t" + declusteringPotential; // Legit const string line2start = "\r\nMyMolecule2\tMyMol2\tMyFrag2\tCH12O4\tCH3O\t"; const string line3 = "\r\nMyMolecule2\tMyMol2\tMyFrag2\tCH12O4\tCHH500000000\t\t\t1\t1"; const string line4 = "\r\nMyMolecule3\tMyMol3\tMyFrag3\tH2\tH\t\t\t1\t1"; // Provoke some errors TestError(line1.Replace("C34H12O4", "C77H12O4"), // mz and formula disagree String.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Error_on_line__0___Precursor_m_z__1__does_not_agree_with_value__2__as_calculated_from_ion_formula_and_charge_state__delta____3___Transition_Settings___Instrument___Method_match_tolerance_m_z____4_____Correct_the_m_z_value_in_the_table__or_leave_it_blank_and_Skyline_will_calculate_it_for_you_, 1, (float)precursorMzAtZNeg2, 500.0373, 258, docEmpty.Settings.TransitionSettings.Instrument.MzMatchTolerance)); TestError(line1.Replace("C34H3", "C76H3"), // mz and formula disagree String.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Error_on_line__0___Product_m_z__1__does_not_agree_with_value__2__as_calculated_from_ion_formula_and_charge_state__delta____3___Transition_Settings___Instrument___Method_match_tolerance_m_z____4_____Correct_the_m_z_value_in_the_table__or_leave_it_blank_and_Skyline_will_calculate_it_for_you_, 1, (float)productMzAtZNeg2, 465.5097, 252, docEmpty.Settings.TransitionSettings.Instrument.MzMatchTolerance)); var badcharge = Transition.MAX_PRODUCT_CHARGE + 1; TestError(line1 + line2start + "\t\t1\t" + badcharge, // Excessively large charge for product String.Format(Resources.Transition_Validate_Product_ion_charge__0__must_be_non_zero_and_between__1__and__2__, badcharge, -Transition.MAX_PRODUCT_CHARGE, Transition.MAX_PRODUCT_CHARGE)); badcharge = 120; TestError(line1 + line2start + "\t\t" + badcharge + "\t1", // Insanely large charge for precursor String.Format(Resources.Transition_Validate_Precursor_charge__0__must_be_non_zero_and_between__1__and__2__, badcharge, -TransitionGroup.MAX_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE)); TestError(line1 + line2start + "\t\t1\t", // No mz or charge for product String.Format(Resources.PasteDlg_ValidateEntry_Error_on_line__0___Product_needs_values_for_any_two_of__Formula__m_z_or_Charge_, 2)); TestError(line1 + line2start + "19\t5", // Precursor Formula and m/z don't make sense together String.Format(Resources.PasteDlg_ValidateEntry_Error_on_line__0___Precursor_formula_and_m_z_value_do_not_agree_for_any_charge_state_, 2)); TestError(line1 + line2start + "\t5\t1", // Product Formula and m/z don't make sense together String.Format(Resources.PasteDlg_ValidateEntry_Error_on_line__0___Product_formula_and_m_z_value_do_not_agree_for_any_charge_state_, 2)); TestError(line1 + line2start + "\t", // No mz or charge for precursor or product String.Format(Resources.PasteDlg_ValidateEntry_Error_on_line__0___Precursor_needs_values_for_any_two_of__Formula__m_z_or_Charge_, 2)); TestError(line1 + line3, // Insanely large molecule string.Format(Resources.CustomIon_Validate_The_mass_of_the_custom_ion_exceeeds_the_maximum_of__0_, CustomIon.MAX_MASS)); TestError(line1 + line4, // Insanely small molecule string.Format(Resources.CustomIon_Validate_The_mass_of_the_custom_ion_is_less_than_the_minimum_of__0__, CustomIon.MIN_MASS)); TestError(line1 + line2start + +precursorMzAtZNeg2 + "\t" + productMzAtZNeg2 + "\t-2\t-2\t\t\t" + precursorRTWindow + "\t" + precursorCE + "\t" + precursorDT + "\t" + highEnergyDtOffset, // Explicit retention time window without retention time Resources.Peptide_ExplicitRetentionTimeWindow_Explicit_retention_time_window_requires_an_explicit_retention_time_value_); for (int withSpecials = 2; withSpecials-- > 0;) { // By default we don't show drift or other exotic columns var columnOrder = (withSpecials == 0) ? null : new[] { PasteDlg.SmallMoleculeTransitionListColumnHeaders.moleculeGroup, PasteDlg.SmallMoleculeTransitionListColumnHeaders.namePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.nameProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.formulaPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.formulaProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.mzPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.mzProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.chargePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.chargeProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.labelType, PasteDlg.SmallMoleculeTransitionListColumnHeaders.rtPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.rtWindowPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.cePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.note, PasteDlg.SmallMoleculeTransitionListColumnHeaders.dtPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.dtHighEnergyOffset, PasteDlg.SmallMoleculeTransitionListColumnHeaders.slens, PasteDlg.SmallMoleculeTransitionListColumnHeaders.coneVoltage, PasteDlg.SmallMoleculeTransitionListColumnHeaders.compensationVoltage, PasteDlg.SmallMoleculeTransitionListColumnHeaders.declusteringPotential, }; // Take a legit full paste and mess with each field in turn string[] fields = { "MyMol", "MyPrecursor", "MyProduct", "C12H9O4", "C6H4O2", "217.049535420091", "108.020580420091", "1", "1", "heavy", "123", "5", "25", "this is a note", "7", "9", "88.5", "99.6", "77.3", "66.2" }; string[] badfields = { "", "", "", "123", "123", "fish", "-345", "cat", "pig", "12", "frog", "hamster", "boston", "foosball", "greasy", "mumble", "gumdrop", "dingle", "gorse", "AHHHHHRGH" }; var expectedErrors = new List <string>() { Resources.PasteDlg_ShowNoErrors_No_errors, Resources.PasteDlg_ShowNoErrors_No_errors, Resources.PasteDlg_ShowNoErrors_No_errors, // No name, no problem BioMassCalc.MONOISOTOPIC.FormatArgumentExceptionMessage(badfields[3]), BioMassCalc.MONOISOTOPIC.FormatArgumentExceptionMessage(badfields[4]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_m_z_value__0_, badfields[5]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_m_z_value__0_, badfields[6]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_charge_value__0_, badfields[7]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_charge_value__0_, badfields[8]), string.Format(Resources.SrmDocument_ReadLabelType_The_isotope_modification_type__0__does_not_exist_in_the_document_settings, badfields[9]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_retention_time_value__0_, badfields[10]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_retention_time_window_value__0_, badfields[11]), string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_collision_energy_value__0_, badfields[12]), null // Notes are freeform, so any value is fine }; if (withSpecials > 0) { var s = expectedErrors.Count; expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_drift_time_value__0_, badfields[s++])); expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_drift_time_high_energy_offset_value__0_, badfields[s++])); expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_S_Lens_value__0_, badfields[s++])); expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_cone_voltage_value__0_, badfields[s++])); expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_compensation_voltage__0_, badfields[s++])); expectedErrors.Add( string.Format(Resources.PasteDlg_ReadPrecursorOrProductColumns_Invalid_declustering_potential__0_, badfields[s++])); } expectedErrors.Add(Resources.PasteDlg_ShowNoErrors_No_errors); // N+1'th pass is unadulterated for (var bad = 0; bad < expectedErrors.Count(); bad++) { var line = ""; for (var f = 0; f < expectedErrors.Count() - 1; f++) { line += ((bad == f) ? badfields[f] : fields[f]).Replace(".", LocalizationHelper.CurrentCulture.NumberFormat.NumberDecimalSeparator) + "\t"; } if (!string.IsNullOrEmpty(expectedErrors[bad])) { TestError(line, expectedErrors[bad], columnOrder); } } } // Now load the document with a legit paste TestError(line1 + line2start + "\t\t1\t1", String.Empty); var docOrig = WaitForDocumentChange(docEmpty); var testTransitionGroups = docOrig.MoleculeTransitionGroups.ToArray(); Assert.AreEqual(2, testTransitionGroups.Count()); var transitionGroup = testTransitionGroups[0]; var precursor = docOrig.Molecules.First(); var product = transitionGroup.Transitions.First(); Assert.AreEqual(precursorCE, transitionGroup.ExplicitValues.CollisionEnergy); Assert.AreEqual(precursorDT, transitionGroup.ExplicitValues.DriftTimeMsec); Assert.AreEqual(slens, transitionGroup.ExplicitValues.SLens); Assert.AreEqual(coneVoltage, transitionGroup.ExplicitValues.ConeVoltage); Assert.AreEqual(compensationVoltage, transitionGroup.ExplicitValues.CompensationVoltage); Assert.AreEqual(declusteringPotential, transitionGroup.ExplicitValues.DeclusteringPotential); Assert.AreEqual(note, product.Annotations.Note); Assert.AreEqual(highEnergyDtOffset, transitionGroup.ExplicitValues.DriftTimeHighEnergyOffsetMsec.Value, 1E-7); Assert.AreEqual(precursorRT, precursor.ExplicitRetentionTime.RetentionTime); Assert.AreEqual(precursorRTWindow, precursor.ExplicitRetentionTime.RetentionTimeWindow); Assert.IsTrue(ReferenceEquals(transitionGroup.TransitionGroup, product.Transition.Group)); Assert.AreEqual(precursorMzAtZNeg2, BioMassCalc.CalculateIonMz(precursor.CustomIon.MonoisotopicMass, transitionGroup.PrecursorCharge), 1E-7); Assert.AreEqual(productMzAtZNeg2, BioMassCalc.CalculateIonMz(product.GetIonMass(), product.Transition.Charge), 1E-7); // Does that produce the expected transition list file? TestTransitionListOutput(docOrig, "PasteMoleculeTinyTest.csv", "PasteMoleculeTinyTestExpected.csv", ExportFileType.IsolationList); // Does serialization of imported values work properly? AssertEx.Serializable(docOrig); // Reset RunUI(() => { SkylineWindow.NewDocument(true); docOrig = SkylineWindow.Document; }); // Now a proper user data set var pasteDlg = ShowDialog <PasteDlg>(SkylineWindow.ShowPasteTransitionListDlg); PasteDlg dlg = pasteDlg; RunUI(() => { dlg.IsMolecule = true; dlg.SetSmallMoleculeColumns(null); // Reset column headers to default selection and order }); // Formerly SetExcelFileClipboardText(TestFilesDir.GetTestPath("MoleculeTransitionList.xlsx"),"sheet1",6,false); but TeamCity doesn't like that SetCsvFileClipboardText(TestFilesDir.GetTestPath("MoleculeTransitionList.csv")); RunUI(pasteDlg.PasteTransitions); OkDialog(pasteDlg, pasteDlg.OkDialog); var pastedDoc = WaitForDocumentChange(docOrig); AssertEx.Serializable(pastedDoc); RunUI(() => SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("PasteMolecules.Sky"))); var paths = new [] { "13417_02_WAA283_3805_071514" + ExtensionTestContext.ExtWatersRaw, "13417_03_WAA283_3805_071514" + ExtensionTestContext.ExtWatersRaw, "13418_02_WAA283_3805_071514" + ExtensionTestContext.ExtWatersRaw, "13418_03_WAA283_3805_071514" + ExtensionTestContext.ExtWatersRaw, }; var doc = SkylineWindow.Document; RunUI(() => SkylineWindow.ChangeSettings(doc.Settings. ChangeTransitionSettings( doc.Settings.TransitionSettings.ChangeInstrument( doc.Settings.TransitionSettings.Instrument.ChangeMzMatchTolerance(0.6))), true)); PasteMoleculesTestImportResults(paths); var importDoc = SkylineWindow.Document; var transitionCount = importDoc.MoleculeTransitionCount; var tranWithResults = importDoc.MoleculeTransitions.Count(tran => tran.HasResults); var tranWithPeaks = importDoc.MoleculeTransitions.Count(tran => { for (int i = 0; i < 4; i++) { if (tran.GetPeakCountRatio(i) > 0) { return(true); } } return(false); }); // PauseTest(); // Pretty pictures! Assert.AreEqual(98, transitionCount); Assert.AreEqual(98, tranWithResults); Assert.AreEqual(90, tranWithPeaks); // Does that produce the expected transition list file? TestTransitionListOutput(importDoc, "PasteMoleculeTest.csv", "PasteMoleculeTestExpected.csv", ExportFileType.List); // Verify that MS1 filtering works properly var pasteText = "Steryl esters [ST0102],12:0 Cholesteryl ester,C39H68O2NH4,1\r\n" + "Steryl esters [ST0102],14:0 Cholesteryl ester,C41H72O2NH4,1\r\n" + "Steryl esters [ST0102],14:1 Cholesteryl ester,C41H70O2NH4,1\r\n" + "Steryl esters [ST0102],15:1 Cholesteryl ester,C42H72O2NH4,1"; var columnOrderB = new[] { PasteDlg.SmallMoleculeTransitionListColumnHeaders.moleculeGroup, PasteDlg.SmallMoleculeTransitionListColumnHeaders.namePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.formulaPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.chargePrecursor, }; // Doc is set for MS1 filtering, precursor transitions, charge=1, two peaks, should show M and M+1, M+2 after filter is invoked by changing to 3 peaks RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("small_molecule_missing_m1.sky"))); WaitForDocumentLoaded(); TestError(pasteText, String.Empty, columnOrderB); var docB = SkylineWindow.Document; Assert.AreEqual(4, docB.MoleculeTransitionCount); // Initial import is faithful to what's pasted var transitionSettingsUI = ShowDialog <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI); RunUI(() => { transitionSettingsUI.SelectedTab = TransitionSettingsUI.TABS.FullScan; transitionSettingsUI.Peaks = 3; }); OkDialog(transitionSettingsUI, transitionSettingsUI.OkDialog); docB = WaitForDocumentChange(docB); Assert.AreEqual(12, docB.MoleculeTransitionCount); // Verify that we can import heavy/light pairs var columnOrderC = new[] { PasteDlg.SmallMoleculeTransitionListColumnHeaders.moleculeGroup, PasteDlg.SmallMoleculeTransitionListColumnHeaders.namePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.formulaPrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.mzProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.chargePrecursor, PasteDlg.SmallMoleculeTransitionListColumnHeaders.chargeProduct, PasteDlg.SmallMoleculeTransitionListColumnHeaders.labelType, }; pasteText = "A,27-HC,C36H57N2O3,135,1,1,light\r\n" + "A,27-HC,C36H57N2O3,181,1,1,light\r\n" + "A,27-HC,C36H57N2O3,367,1,1,light\r\n" + "A,27-HC,C36H51H'6N2O3,135,1,1,heavy\r\n" + "A,27-HC,C36H51H'6N2O3,181,1,1,heavy\r\n" + "A,27-HC,C36H51H'6N2O3,215,1,1,heavy\r\n"; RunUI(() => { SkylineWindow.NewDocument(true); }); TestError(pasteText, String.Empty, columnOrderC); var docC = SkylineWindow.Document; Assert.AreEqual(1, docC.MoleculeGroupCount); Assert.AreEqual(1, docC.MoleculeCount); Assert.AreEqual(2, docC.MoleculeTransitionGroupCount); }
private void NextPage() { switch (CurrentPage) { case Pages.spectra_page: { var eCancel = new CancelEventArgs(); if (!BuildPepSearchLibControl.BuildPeptideSearchLibrary(eCancel)) { // Page shows error if (eCancel.Cancel) { return; } CloseWizard(DialogResult.Cancel); } // The user had the option to finish right after // building the peptide search library, but they // did not, so hide the "early finish" button for // the rest of the wizard pages. ShowEarlyFinish(false); if (FastaOptional) { lblFasta.Text = Resources.ImportPeptideSearchDlg_NextPage_Import_FASTA__optional_; } // The next page is going to be the chromatograms page. var oldImportResultsControl = (ImportResultsControl)ImportResultsControl; if (WorkflowType != Workflow.dia) { oldImportResultsControl.InitializeChromatogramsPage(SkylineWindow.DocumentUI); if (WorkflowType == Workflow.dda) { _pagesToSkip.Add(Pages.transition_settings_page); } } else { // DIA workflow, replace old ImportResultsControl ImportResultsControl = new ImportResultsDIAControl(SkylineWindow) { Anchor = oldImportResultsControl.Anchor, Location = oldImportResultsControl.Location }; getChromatogramsPage.Controls.Remove(oldImportResultsControl); getChromatogramsPage.Controls.Add((Control)ImportResultsControl); } ImportResultsControl.ResultsFilesChanged += ImportResultsControl_OnResultsFilesChanged; // Set up full scan settings page TransitionSettingsControl.Initialize(WorkflowType); FullScanSettingsControl.ModifyOptionsForImportPeptideSearchWizard(WorkflowType); if (!MatchModificationsControl.Initialize(SkylineWindow.Document)) { _pagesToSkip.Add(Pages.match_modifications_page); } if (BuildPepSearchLibControl.FilterForDocumentPeptides) { _pagesToSkip.Add(Pages.import_fasta_page); } } break; case Pages.chromatograms_page: { if (!ImportPeptideSearch.VerifyRetentionTimes(ImportResultsControl.FoundResultsFiles.Select(f => f.Path))) { MessageDlg.Show(this, TextUtil.LineSeparate(Resources.ImportPeptideSearchDlg_NextPage_The_document_specific_spectral_library_does_not_have_valid_retention_times_, Resources.ImportPeptideSearchDlg_NextPage_Please_check_your_peptide_search_pipeline_or_contact_Skyline_support_to_ensure_retention_times_appear_in_your_spectral_libraries_)); CloseWizard(DialogResult.Cancel); } if (ImportResultsControl.ResultsFilesMissing) { if (MessageBox.Show(this, Resources.ImportPeptideSearchDlg_NextPage_Some_results_files_are_still_missing__Are_you_sure_you_want_to_continue_, Program.Name, MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } } if (ImportResultsControl.FoundResultsFiles.Count > 1) { string prefix = ImportResultsDlg.GetCommonPrefix(ImportResultsControl.FoundResultsFiles.Select(f => f.Name)); if (prefix.Length >= ImportResultsDlg.MIN_COMMON_PREFIX_LENGTH) { using (var dlgName = new ImportResultsNameDlg(prefix)) { var result = dlgName.ShowDialog(this); if (result == DialogResult.Cancel) { return; } else if (result == DialogResult.Yes) { // Rename all the replicates to remove the specified prefix. ImportResultsControl.FoundResultsFiles = ImportResultsControl.FoundResultsFiles.Select(f => new ImportPeptideSearch.FoundResultsFile(f.Name.Substring(dlgName.Prefix.Length), f.Path)).ToList(); } } } } } break; case Pages.match_modifications_page: { var newSettings = MatchModificationsControl.AddCheckedModifications(SkylineWindow.Document); if (!ReferenceEquals(SkylineWindow.Document.Settings, newSettings)) { SkylineWindow.ChangeSettings(newSettings, true, Resources.MatchModificationsControl_AddCheckedModifications_Add_checked_modifications); SkylineWindow.Document.Settings.UpdateDefaultModifications(false); } // The next page is going to be the MS1 Full-Scan Settings // page, so initialize it. // FullScanSettingsControl.InitializeMs1FullScanSettingsPage(); } break; case Pages.transition_settings_page: // Try to accept changes to transition settings if (!UpdateTransitionSettings()) { return; } break; case Pages.full_scan_settings_page: // Try to accept changes to MS1 full-scan settings if (!UpdateFullScanSettings()) { // We can't allow the user to progress any further until // we can verify that the MS1 full scan settings are valid. return; } break; case Pages.import_fasta_page: // This is the last page if ((FastaOptional && !ImportFastaControl.ContainsFastaContent) || ImportFastaControl.ImportFasta()) { WizardFinish(); } return; } Pages newPage = CurrentPage + 1; while (_pagesToSkip.Contains(newPage)) { ++newPage; } // Skip import FASTA if user filters for document peptides if (newPage > Pages.import_fasta_page) { WizardFinish(); return; } CurrentPage = newPage; if (CurrentPage == LastPage) { btnNext.Text = Resources.ImportPeptideSearchDlg_NextPage_Finish; } }
public void OkDialog() { var helper = new MessageBoxHelper(this); var charge = 0; if (textCharge.Visible && !helper.ValidateSignedNumberTextBox(textCharge, _minCharge, _maxCharge, out charge)) { return; } var adduct = Adduct.NonProteomicProtonatedFromCharge(charge); if (RetentionTimeWindow.HasValue && !RetentionTime.HasValue) { helper.ShowTextBoxError(textRetentionTimeWindow, Resources .Peptide_ExplicitRetentionTimeWindow_Explicit_retention_time_window_requires_an_explicit_retention_time_value_); return; } if (Adduct.IsEmpty || Adduct.AdductCharge != adduct.AdductCharge) { Adduct = adduct; // Note: order matters here, this settor indirectly updates _formulaBox.MonoMass when formula is empty } if (string.IsNullOrEmpty(_formulaBox.NeutralFormula)) { // Can the text fields be understood as mz? if (!_formulaBox.ValidateAverageText(helper)) { return; } if (!_formulaBox.ValidateMonoText(helper)) { return; } } var monoMass = new TypedMass(_formulaBox.MonoMass ?? 0, MassType.Monoisotopic); var averageMass = new TypedMass(_formulaBox.AverageMass ?? 0, MassType.Average); if (monoMass < CustomMolecule.MIN_MASS || averageMass < CustomMolecule.MIN_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format( Resources .EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_greater_than_or_equal_to__0__, CustomMolecule.MIN_MASS)); return; } if (monoMass > CustomMolecule.MAX_MASS || averageMass > CustomMolecule.MAX_MASS) { _formulaBox.ShowTextBoxErrorFormula(helper, string.Format( Resources .EditCustomMoleculeDlg_OkDialog_Custom_molecules_must_have_a_mass_less_than_or_equal_to__0__, CustomMolecule.MAX_MASS)); return; } if ((_transitionSettings != null) && (!_transitionSettings.IsMeasurablePrecursor( adduct.MzFromNeutralMass(monoMass, MassType.Monoisotopic)) || !_transitionSettings.IsMeasurablePrecursor(adduct.MzFromNeutralMass(averageMass, MassType.Average)))) { _formulaBox.ShowTextBoxErrorFormula(helper, Resources .SkylineWindow_AddMolecule_The_precursor_m_z_for_this_molecule_is_out_of_range_for_your_instrument_settings_); return; } // Ion mobility value must have ion mobility units if (textIonMobility.Visible && IonMobility.HasValue) { if (IonMobilityUnits == eIonMobilityUnits.none) { helper.ShowTextBoxError(textIonMobility, Resources.EditCustomMoleculeDlg_OkDialog_Please_specify_the_ion_mobility_units_); comboBoxIonMobilityUnits.Focus(); return; } if (IonMobility.Value == 0 || (IonMobility.Value < 0 && !IonMobilityFilter.AcceptNegativeMobilityValues(IonMobilityUnits))) { helper.ShowTextBoxError(textIonMobility, string.Format(Resources.SmallMoleculeTransitionListReader_ReadPrecursorOrProductColumns_Invalid_ion_mobility_value__0_, IonMobility)); textIonMobility.Focus(); return; } } if (_usageMode == UsageMode.precursor) { // Only the adduct should be changing SetResult(_resultCustomMolecule, Adduct); } else if (!string.IsNullOrEmpty(_formulaBox.NeutralFormula)) { try { var name = textName.Text; if (string.IsNullOrEmpty(name)) { name = _formulaBox.NeutralFormula; // Clip off any adduct description } SetResult(new CustomMolecule(_formulaBox.NeutralFormula, name), Adduct); } catch (InvalidDataException x) { _formulaBox.ShowTextBoxErrorFormula(helper, x.Message); return; } } else { SetResult(new CustomMolecule(monoMass, averageMass, textName.Text), Adduct); } // Did user change the list of heavy labels? if (_driverLabelType != null) { // This is the only thing the user may have altered var newHeavyMods = _driverLabelType.GetHeavyModifications().ToArray(); if (!ArrayUtil.EqualsDeep(newHeavyMods, _peptideSettings.Modifications.HeavyModifications)) { var labelTypes = _peptideSettings.Modifications.InternalStandardTypes.Where(t => newHeavyMods.Any(m => Equals(m.LabelType, t))).ToArray(); if (labelTypes.Length == 0) { labelTypes = new[] { newHeavyMods.First().LabelType } } ; PeptideModifications modifications = new PeptideModifications( _peptideSettings.Modifications.StaticModifications, _peptideSettings.Modifications.MaxVariableMods, _peptideSettings.Modifications.MaxNeutralLosses, newHeavyMods, labelTypes); var settings = _peptideSettings.ChangeModifications(modifications); SrmSettings newSettings = _parent.DocumentUI.Settings.ChangePeptideSettings(settings); if (!_parent.ChangeSettings(newSettings, true)) { // Not expected, since we checked for a change before calling // Otherwise, this is very confusing. The form just refuses to go away // We would prefer to get an unhandled exception and fix this Assume.Fail(); return; } _peptideSettings = newSettings.PeptideSettings; } } // See if this combination of charge and label would conflict with any existing transition groups if (_existingIds != null && _existingIds.Any(t => { var transitionGroup = t as TransitionGroup; return(transitionGroup != null && Equals(transitionGroup.LabelType, IsotopeLabelType) && Equals(transitionGroup.PrecursorAdduct.AsFormula(), Adduct .AsFormula()) && // Compare AsFormula so proteomic and non-proteomic protonation are seen as same thing !ReferenceEquals(t, _initialId)); })) { helper.ShowTextBoxError(textName, Resources .EditCustomMoleculeDlg_OkDialog_A_precursor_with_that_adduct_and_label_type_already_exists_, textName.Text); return; } // See if this would conflict with any existing transitions if (_existingIds != null && (_existingIds.Any(t => { var transition = t as Transition; return(transition != null && (Equals(transition.Adduct.AsFormula(), Adduct.AsFormula()) && Equals(transition.CustomIon, ResultCustomMolecule)) && !ReferenceEquals(t, _initialId)); }))) { helper.ShowTextBoxError(textName, Resources.EditCustomMoleculeDlg_OkDialog_A_similar_transition_already_exists_, textName.Text); return; } DialogResult = DialogResult.OK; }