public void AddModification(StaticMod mod, IsotopeLabelType labelType) { if (MatcherPepMods.GetModificationTypes().Contains(labelType)) { var newMods = MatcherPepMods.GetModifications(labelType) .Where(existingMod => !existingMod.Equivalent(mod)).ToList(); newMods.Add(mod); MatcherPepMods = MatcherPepMods.ChangeModifications(labelType, newMods); } else if (labelType.IsLight) { MatcherPepMods = new PeptideModifications(new List<StaticMod> { mod }, MatcherPepMods.GetHeavyModifications().ToArray()); } else { var typedHeavyMods = new List<TypedModifications>(MatcherPepMods.GetHeavyModifications()) { new TypedModifications(labelType, new List<StaticMod> { mod }) }; MatcherPepMods = new PeptideModifications(MatcherPepMods.StaticModifications, typedHeavyMods); } MatchesUpdated = true; }
public void UpdateMatches(PeptideModifications prevPepMods, PeptideModifications newPepMods) { var labelTypes = newPepMods.GetModificationTypes().ToList(); labelTypes.AddRange(prevPepMods.GetModificationTypes()); foreach (var labelType in labelTypes) { var newMods = newPepMods.GetModifications(labelType); var prevMods = prevPepMods.GetModifications(labelType); // Add new modifications. foreach (var mod in newMods.Where(newMod => !prevMods.Contains(prevMod => prevMod.Equivalent(newMod)))) { AddModification(mod, labelType); } // Remove old modifications foreach (var mod in prevMods.Where(prevMod => !newMods.Contains(newMod => newMod.Equivalent(prevMod)))) { RemoveModification(mod, labelType); } } }
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 ImportSearchInternal(CommandArgs commandArgs, ref SrmDocument doc) { var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(String.Empty)); var import = new ImportPeptideSearch { SearchFilenames = commandArgs.SearchResultsFiles.ToArray(), CutoffScore = commandArgs.CutoffScore.GetValueOrDefault() }; // Build library var builder = import.GetLibBuilder(doc, commandArgs.Saving ? commandArgs.SaveFile : commandArgs.SkylineFile, commandArgs.IncludeAmbiguousMatches); ImportPeptideSearch.ClosePeptideSearchLibraryStreams(doc); _out.WriteLine(Resources.CommandLine_ImportSearch_Creating_spectral_library_from_files_); foreach (var file in commandArgs.SearchResultsFiles) _out.WriteLine(Path.GetFileName(file)); if (!builder.BuildLibrary(progressMonitor)) return false; if (!string.IsNullOrEmpty(builder.AmbiguousMatchesMessage)) _out.WriteLine(builder.AmbiguousMatchesMessage); var docLibSpec = builder.LibrarySpec.ChangeDocumentLibrary(true); _out.WriteLine(Resources.CommandLine_ImportSearch_Loading_library); var libraryManager = new LibraryManager(); if (!import.LoadPeptideSearchLibrary(libraryManager, docLibSpec, progressMonitor)) return false; doc = import.AddDocumentSpectralLibrary(doc, docLibSpec); if (doc == null) return false; if (!import.VerifyRetentionTimes(import.GetFoundResultsFiles().Select(f => f.Path))) { _out.WriteLine(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_)); return false; } // Look for results files to import import.InitializeSpectrumSourceFiles(doc); import.UpdateSpectrumSourceFilesFromDirs(import.GetDirsToSearch(Path.GetDirectoryName(commandArgs.SkylineFile)), false, null); var missingResultsFiles = import.GetMissingResultsFiles().ToArray(); if (missingResultsFiles.Any()) { foreach (var file in missingResultsFiles) { if (doc.Settings.HasResults && doc.Settings.MeasuredResults.FindMatchingMSDataFile(new MsDataFilePath(file)) != null) continue; _out.WriteLine(Resources.CommandLine_ImportSearch_Warning__Unable_to_locate_results_file___0__, Path.GetFileName(file)); } } // Add all modifications, if requested if (commandArgs.AcceptAllModifications) { import.InitializeModifications(doc); var foundMods = import.GetMatchedMods().Count(); var newModifications = new PeptideModifications(import.MatcherPepMods.StaticModifications, new[] {new TypedModifications(IsotopeLabelType.heavy, import.MatcherHeavyMods)}); var newSettings = import.AddModifications(doc, newModifications); if (!ReferenceEquals(doc.Settings, newSettings)) { if (foundMods != 1) _out.WriteLine(Resources.CommandLine_ImportSearch_Adding__0__modifications_, foundMods); else _out.WriteLine(Resources.CommandLine_ImportSearch_Adding_1_modification_); doc = doc.ChangeSettings(newSettings); doc.Settings.UpdateDefaultModifications(false); } } // Import FASTA if (commandArgs.ImportingFasta) { _out.WriteLine(Resources.CommandLine_ImportFasta_Importing_FASTA_file__0____, Path.GetFileName(commandArgs.FastaPath)); doc = ImportPeptideSearch.PrepareImportFasta(doc); int emptyProteins; try { IdentityPath firstAdded, nextAdd; doc = ImportPeptideSearch.ImportFasta(doc, commandArgs.FastaPath, progressMonitor, null, out firstAdded, out nextAdd, out emptyProteins); } catch (Exception x) { _out.WriteLine(Resources.CommandLine_Run_Error__Failed_importing_the_file__0____1_, commandArgs.FastaPath, x.Message); _doc = doc; return true; // So that document will be saved with the new library } if (emptyProteins > 0 && !commandArgs.KeepEmptyProteins) { doc = ImportPeptideSearch.RemoveEmptyProteins(doc); } } // Import results _doc = doc; ImportFoundResultsFiles(commandArgs, import); return true; }
public LabelTypeComboDriver(ComboBox combo, PeptideModifications modifications, SettingsListBoxDriver<StaticMod> driverHeavyMod, Label labelIS, ComboBox comboIS, CheckedListBox listBoxIS) { _driverHeavyMod = driverHeavyMod; LabelIS = labelIS; Combo = combo; Combo.DisplayMember = Resources.LabelTypeComboDriver_LabelTypeComboDriver_LabelType; ComboIS = comboIS; ListBoxIS = listBoxIS; LoadList(null, modifications.InternalStandardTypes, modifications.GetHeavyModifications().ToArray()); ShowModifications(); }
public void TestModificationMatcher() { InitSeqs(); var carbC = StaticModList.GetDefaultsOn()[0]; // Test exception thrown if unable to match - mass. UpdateMatcherFail(STR_FAIL_MASS); UpdateMatcherFail(STR_FAIL_NOT_A_NUMBER); // Test exception thrown if unable to match - name. UpdateMatcherFail(STR_FAIL_NAME); // Can't match empty modifications. UpdateMatcherFail(STR_FAIL_EMPTY_MOD); UpdateMatcherFail(STR_FAIL_EMPTY_MOD2); // Can't match double modifications. UpdateMatcherFail(STR_FAIL_DOUBLE_MOD); // Test exception thrown if unimod not specified correctly UpdateMatcherFail(STR_FAIL_UNIMOD); UpdateMatcherFail(STR_UNKNOWN_UNIMOD); // Can't phosphorylate tryptophan UpdateMatcherFail(STR_FAIL_WRONG_AA_UNIMOD); // Can't put C-terminal modification in middle of peptide UpdateMatcherFail(STR_FAIL_UNIMOD_TERMINUS); // Test mods in UniMod match correctly. UpdateMatcher(StaticModList.GetDefaultsOn(), HeavyModList.GetDefaultsOn(), null, null); // A sequence with no modifications should not be explicitly modified. Assert.IsFalse(MATCHER.GetModifiedNode(STR_NO_MODS).HasExplicitMods); var nodeCysOxi = MATCHER.GetModifiedNode(STR_CYS_AND_OXI); Assert.IsTrue(nodeCysOxi.HasExplicitMods); Assert.IsFalse(nodeCysOxi.ExplicitMods.HasHeavyModifications); // Modifications should match by name. Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification.Name, "Phospho (ST)"))); // Test can find terminal modification Assert.IsTrue(MATCHER.GetModifiedNode(STR_TERM_ONLY).ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.EquivalentAll(UniMod.GetModification("Label:13C(6) (C-term R)", false)))); // Test can find matches on terminus that are not terminal Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod => mod.Modification.Terminus == null)); // Test matching negative masses Assert.IsTrue(MATCHER.GetModifiedNode(STR_AMMONIA_LOSS).ExplicitMods.StaticModifications.Contains(mod => mod.Modification.EquivalentAll(UniMod.GetModification("Ammonia-loss (N-term C)", true)))); // General and specific // If all AAs modified, try for most general modification. Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15) .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.Equivalent(LABEL15_N))); // Updating the settings. // Peptide settings should change to include new mods. var docNew = new SrmDocument(SrmSettingsList.GetDefault()); IdentityPath firstAdded; IdentityPath nextAdded; docNew = docNew.AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(), "PepGroup1", "", new[] {MATCHER.GetModifiedNode(STR_MOD_BY_NAME)})}, true, null, out firstAdded, out nextAdded); var pepSetNew = MATCHER.GetDocModifications(docNew); Assert.IsTrue(pepSetNew.StaticModifications.Contains(UniMod.GetModification("Phospho (ST)", true).ChangeExplicit(true))); // Update the document to the new settings. var pepSetNew1 = pepSetNew; var settingsNew2 = docNew.Settings.ChangePeptideModifications(mods => pepSetNew1); var lightGlobalMods = new MappedList<string, StaticMod>(); lightGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.StaticModifications); var heavyGlobalMods = new MappedList<string, StaticMod>(); heavyGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.HeavyModifications); // Match again. Test FoundMatches string should now be empty. MATCHER.CreateMatches(docNew.Settings.ChangePeptideModifications(mods => pepSetNew1), new List<string> { STR_MOD_BY_NAME }, lightGlobalMods, heavyGlobalMods); Assert.IsTrue(string.IsNullOrEmpty(MATCHER.FoundMatches)); // Adding 15N to the settings. UpdateMatcher(new[] { carbC }, new[] { LABEL15_N }, null, null); // Test sequences with only explicit heavy mods should not have explicit light mods Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_ONLY).ExplicitMods.StaticModifications); // Test sequences with only explicit light mods should not have explicit heavy mods Assert.IsFalse(MATCHER.GetModifiedNode(STR_LIGHT_ONLY).ExplicitMods.HasHeavyModifications); // Test global mods take precendence over UniMod UpdateMatcher(new[] { carbC }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N }); Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.StaticModifications .Contains(mod => Equals(mod.Modification, OXIDATION_M_GLOBAL))); // Test document mods take precendence over UniMod UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N }); Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods); // Test exception thrown if match doesn't make sense - wrong AA. UpdateMatcherFail(STR_FAIL_OX_ON_D); // Test exception thrown if match doesn't make sense - wrong terminus. _seqs.Add(STR_FAIL_OX_TERM); AssertEx.ThrowsException<FormatException>(() => UpdateMatcher(new[] {OXIDATION_M_C_TERM}, null, null, null)); _seqs.Remove(STR_FAIL_OX_TERM); // Heavy 15N - All AAs. UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, new[] {LABEL15_N}, null, null); // Node should be created from document settings if possible. Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_15).ExplicitMods); // Heavy 15N - specific AA. // If only a specific AA is modified, there must be an explicit mod. Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).HasExplicitMods); // Test variable mods match correctly. // Put variable mod in global mod and not on doc - make sure don't get variable mod, // should get explicit mod in that case. var variableMetOx = METHIONINE_OXIDATION.ChangeVariable(true); UpdateMatcher(new[] { carbC }, null, new[] { variableMetOx }, null); Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods); Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods); Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods); // Add variable mod to doc UpdateMatcher(new[] { carbC, variableMetOx }, null, null, null); // Mod can be created by the settings. Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods); Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.IsVariableStaticMods); // Mod cannot be created by the settings. Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods); Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods); // Add Met Ox to global. Test: +16 finds it. UpdateMatcher(new[] {carbC}, null, new[] {MET_OX_ROUNDED}, null); Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI). ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED))); // Test: +15.99 finds UniMod. Assert.IsFalse(MATCHER.GetModifiedNode(STR_HEAVY_15). ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED))); // Add Methionine Oxidation before Met Ox. Test: +16 finds it. UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null); Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI). ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED))); Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI). ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, METHIONINE_OXIDATION))); // Test long masses rounded. Assert.IsTrue(MATCHER.GetModifiedNode(STR_METOX_LONG_MASS).ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, METHIONINE_OXIDATION))); // Test UniMod label types var node = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL); Assert.IsNotNull(node); Assert.IsNull(node.ExplicitMods.StaticModifications); Assert.IsTrue(node.ExplicitMods.HeavyModifications.Contains(mod => Equals(mod.Modification, N_TERM_LABEL))); UpdateMatcherWithNoSequences(new[] { carbC }, new[] { N_TERM_LABEL }, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null); var nodeNew = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL); Assert.IsNotNull(nodeNew); Assert.IsTrue(nodeNew.TransitionGroups.Any(group => Equals(group.TransitionGroup.LabelType, IsotopeLabelType.heavy))); UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null); // Test case where there are lots of unimod labels var nodeUniAll = MATCHER.GetModifiedNode(STR_UNIMOD_ALL); Assert.AreEqual(nodeUniAll.ExplicitMods.HeavyModifications.Count, 10); Assert.IsNull(nodeUniAll.ExplicitMods.StaticModifications); foreach (var mod in nodeUniAll.ExplicitMods.HeavyModifications) { Assert.AreEqual(mod.Modification.ShortName, "+01"); Assert.AreEqual(mod.Modification.UnimodId, 994); } // Test unimod terminal label var nodeUniTerm = MATCHER.GetModifiedNode(STR_UNIMOD_TERMINUS); Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications.Count, 1); Assert.IsNull(nodeUniTerm.ExplicitMods.StaticModifications); Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.Terminus, ModTerminus.C); Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.UnimodId, 298); // Basic multi-label test var heavyLabelType2 = new IsotopeLabelType("Heavy2", 1); var typedMod = new TypedModifications(heavyLabelType2, new List<StaticMod> { LABEL15_N }); var peptideMods = new PeptideModifications(new List<StaticMod>(), new List<TypedModifications> { typedMod }); var settingsMultiLabel = SrmSettingsList.GetDefault().ChangePeptideModifications(mods => peptideMods); var defSetSetLight = new MappedList<string, StaticMod>(); defSetSetLight.AddRange(StaticModList.GetDefaultsOn()); var defSetHeavy = new MappedList<string, StaticMod>(); defSetHeavy.AddRange(HeavyModList.GetDefaultsOn()); defSetHeavy.Add( LABEL15_N ); MATCHER.CreateMatches(settingsMultiLabel, new List<string> { STR_HEAVY_15_F }, defSetSetLight, defSetHeavy); Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).ExplicitMods.GetHeavyModifications().Contains(mod => Equals(mod.LabelType, heavyLabelType2))); // Peptide settings should not change. var docNew0 = new SrmDocument(settingsMultiLabel).AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(), "PepGroup1", "", new[] {MATCHER.GetModifiedNode(STR_HEAVY_15_F)})}, true, null, out firstAdded, out nextAdded); var settingsNew = MATCHER.GetDocModifications(docNew0); Assert.AreEqual(settingsMultiLabel.PeptideSettings.Modifications, settingsNew); // Finding specific modifications. // If only specific AA modified, try for most specific modification. UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_F}); Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F) .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.AminoAcids.Contains(c => c == 'F'))); // If only some AAs modified, try for most specific modifications. UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_NOT_ALL }); Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_NOT_ALL) .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.AminoAcids.Contains(c => c == 'I'))); using (var testDir = new TestFilesDir(TestContext, ZIP_FILE)) { var modMatchDocContainer = InitMatchDocContainer(testDir); var libkeyModMatcher = new LibKeyModificationMatcher(); var anlLibSpec = new BiblioSpecLiteSpec("ANL_Combo", testDir.GetTestPath("ANL_Combined.blib")); var yeastLibSpec = new BiblioSpecLiteSpec("Yeast", testDir.GetTestPath("Yeast_atlas_small.blib")); modMatchDocContainer.ChangeLibSpecs(new[] { anlLibSpec, yeastLibSpec }); var docLibraries = modMatchDocContainer.Document.Settings.PeptideSettings.Libraries.Libraries; int anlLibIndex = docLibraries.IndexOf(library => Equals(library.Name, anlLibSpec.Name)); int yeastLibIndex = docLibraries.IndexOf(library => Equals(library.Name, yeastLibSpec.Name)); libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings, docLibraries[anlLibIndex].Keys, defSetSetLight, defSetHeavy); // Test can match 15N Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match => match.HeavyMod != null && match.HeavyMod.Equivalent(LABEL15_N))); var uniModMetOx = UniMod.GetModification("Oxidation (M)", true); // Test can match Met Ox Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match => match.StructuralMod != null && match.StructuralMod.Equivalent(uniModMetOx))); // Test can match 15N and Met ox! Assert.IsTrue(libkeyModMatcher.Matches.Contains(match => match.Key.Mass == 17 && match.Value.StructuralMod != null && match.Value.StructuralMod.Equivalent(uniModMetOx) && match.Value.HeavyMod != null && match.Value.HeavyMod.Equivalent(LABEL15_N))); // Test can match Cysteine (Implicit) and Met Ox (variable) libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings, docLibraries[yeastLibIndex].Keys, defSetSetLight, defSetHeavy); Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod => mod.Formula.Equals(UniMod.GetModification(StaticModList.DEFAULT_NAME, true).Formula) && !mod.IsVariable)); Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod => mod.Formula.Equals("O") && mod.IsVariable)); } }
public PeptideSettings ChangeModifications(PeptideModifications prop) { return ChangeProp(ImClone(this), im => im.Modifications = prop); }
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(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(PeptideModifications obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.MaxVariableMods == MaxVariableMods && obj.MaxNeutralLosses == MaxNeutralLosses && ArrayUtil.EqualsDeep(obj.InternalStandardTypes, InternalStandardTypes) && ArrayUtil.EqualsDeep(obj._modifications, _modifications); }
public static void SetSerializationContext(PeptideModifications mods) { _serializationContext = mods; }
public PeptideDocNode EnsureMods(PeptideModifications source, PeptideModifications target, MappedList<string, StaticMod> defSetStat, MappedList<string, StaticMod> defSetHeavy) { // Create explicit mods matching the implicit mods on this peptide for each document. var sourceImplicitMods = new ExplicitMods(this, source.StaticModifications, defSetStat, source.GetHeavyModifications(), defSetHeavy); var targetImplicitMods = new ExplicitMods(this, target.StaticModifications, defSetStat, target.GetHeavyModifications(), defSetHeavy); // If modifications match, no need to create explicit modifications for the peptide. if (sourceImplicitMods.Equals(targetImplicitMods)) return this; // Add explicit mods if static mods not implicit in the target document. IList<ExplicitMod> newExplicitStaticMods = null; bool preserveVariable = HasVariableMods; // Preserve non-variable explicit modifications if (!preserveVariable && HasExplicitMods && ExplicitMods.StaticModifications != null) { // If they are not the same as the implicit modifications in the new document if (!ArrayUtil.EqualsDeep(ExplicitMods.StaticModifications, targetImplicitMods.StaticModifications)) newExplicitStaticMods = ExplicitMods.StaticModifications; } else if (!ArrayUtil.EqualsDeep(sourceImplicitMods.StaticModifications, targetImplicitMods.StaticModifications)) { preserveVariable = false; newExplicitStaticMods = sourceImplicitMods.StaticModifications; } else if (preserveVariable) { newExplicitStaticMods = ExplicitMods.StaticModifications; } // Drop explicit mods if matching implicit mods are found in the target document. IList<TypedExplicitModifications> newExplicitHeavyMods = new List<TypedExplicitModifications>(); // For each heavy label type, add explicit mods if static mods not found in the target document. var newTypedStaticMods = newExplicitStaticMods != null ? new TypedExplicitModifications(Peptide, IsotopeLabelType.light, newExplicitStaticMods) : null; foreach (TypedExplicitModifications targetDocMod in targetImplicitMods.GetHeavyModifications()) { // Use explicit modifications when available. Otherwise, compare against new implicit modifications IList<ExplicitMod> heavyMods = (HasExplicitMods ? ExplicitMods.GetModifications(targetDocMod.LabelType) : null) ?? sourceImplicitMods.GetModifications(targetDocMod.LabelType); if (heavyMods != null && !ArrayUtil.EqualsDeep(heavyMods, targetDocMod.Modifications) && heavyMods.Count > 0) { var newTypedHeavyMods = new TypedExplicitModifications(Peptide, targetDocMod.LabelType, heavyMods); newTypedHeavyMods = newTypedHeavyMods.AddModMasses(newTypedStaticMods); newExplicitHeavyMods.Add(newTypedHeavyMods); } } if (newExplicitStaticMods != null || newExplicitHeavyMods.Count > 0) return ChangeExplicitMods(new ExplicitMods(Peptide, newExplicitStaticMods, newExplicitHeavyMods, preserveVariable)); return ChangeExplicitMods(null); }
public SrmSettings AddModifications(SrmDocument document, PeptideModifications modifications) { _matcher.MatcherPepMods = modifications; return document.Settings.ChangePeptideModifications(mods => _matcher.SafeMergeImplicitMods(document)); }