public void OkDialog() { var peptide = NodePeptide.Peptide; var explicitModsCurrent = NodePeptide.ExplicitMods; var modsDoc = DocSettings.PeptideSettings.Modifications; var implicitMods = new ExplicitMods(NodePeptide, modsDoc.StaticModifications, Settings.Default.StaticModList, modsDoc.GetHeavyModifications(), Settings.Default.HeavyModList); // Get static modifications from the dialog, and check for equality with // the document implicit modifications. TypedExplicitModifications staticTypedMods = null; bool isVariableStaticMods = false; var staticMods = GetExplicitMods(_listComboStatic, Settings.Default.StaticModList); if (ArrayUtil.EqualsDeep(staticMods, implicitMods.StaticModifications)) { if (!NodePeptide.HasVariableMods) staticMods = null; // Use implicit modifications else { staticMods = explicitModsCurrent.StaticModifications; isVariableStaticMods = true; } } else if (explicitModsCurrent != null && ArrayUtil.EqualsDeep(staticMods, explicitModsCurrent.StaticModifications)) { staticMods = explicitModsCurrent.StaticModifications; } if (staticMods != null) { staticTypedMods = new TypedExplicitModifications(peptide, IsotopeLabelType.light, staticMods); } var listHeavyTypedMods = new List<TypedExplicitModifications>(); for (int i = 0; i < _listLabelTypeHeavy.Count; i++) { var labelType = _listLabelTypeHeavy[i]; var heavyMods = GetExplicitMods(_listListComboHeavy[i], Settings.Default.HeavyModList); if (ArrayUtil.EqualsDeep(heavyMods, implicitMods.GetModifications(labelType))) continue; var heavyTypedMods = new TypedExplicitModifications(peptide, labelType, heavyMods); listHeavyTypedMods.Add(heavyTypedMods.AddModMasses(staticTypedMods)); } ExplicitMods explicitMods = null; if (staticMods != null || listHeavyTypedMods.Count > 0) explicitMods = new ExplicitMods(peptide, staticMods, listHeavyTypedMods, isVariableStaticMods); Helpers.AssignIfEquals(ref explicitMods, explicitModsCurrent); ExplicitMods = explicitMods; DialogResult = DialogResult.OK; Close(); }
public ExplicitMods ChangeModifications(IsotopeLabelType labelType, IList<ExplicitMod> prop) { int index = GetModIndex(labelType); if (index == -1) throw new IndexOutOfRangeException(string.Format(Resources.ExplicitMods_ChangeModifications_Modification_type__0__not_found, labelType)); var modifications = _modifications.ToArrayStd(); var typedMods = new TypedExplicitModifications(Peptide, labelType, prop); if (index != 0) typedMods = typedMods.AddModMasses(modifications[0]); modifications[index] = typedMods; return ChangeProp(ImClone(this), im => im._modifications = MakeReadOnly(modifications)); }
private static IEnumerable<TypedExplicitModifications> GetShuffledHeavyMods(SequenceMods seqMods, TypedExplicitModifications typedStaticMods, int lenSeq, int[] newIndices) { var shuffledHeavyMods = seqMods.Mods.GetHeavyModifications().Select(typedMod => new TypedExplicitModifications(seqMods.Peptide, typedMod.LabelType, GetShuffledMods(typedMod.Modifications, lenSeq, newIndices))); foreach (var typedMods in shuffledHeavyMods) { yield return typedMods.AddModMasses(typedStaticMods); } }
public ExplicitMods ChangeGlobalMods(IList<StaticMod> staticMods, IList<StaticMod> heavyMods, IList<IsotopeLabelType> heavyLabelTypes) { var modifications = new List<TypedExplicitModifications>(); int index = GetModIndex(IsotopeLabelType.light); TypedExplicitModifications typedStaticMods = (index != -1 ? _modifications[index] : null); if (typedStaticMods != null) { IList<ExplicitMod> staticExplicitMods = ChangeGlobalMods(staticMods, typedStaticMods.Modifications); if (!ReferenceEquals(staticExplicitMods, typedStaticMods.Modifications)) typedStaticMods = new TypedExplicitModifications(Peptide, IsotopeLabelType.light, staticExplicitMods); modifications.Add(typedStaticMods); } foreach (TypedExplicitModifications typedMods in GetHeavyModifications()) { // Discard explicit modifications for label types that no longer exist if (!heavyLabelTypes.Contains(typedMods.LabelType)) continue; var heavyExplicitMods = ChangeGlobalMods(heavyMods, typedMods.Modifications); var typedHeavyMods = typedMods; if (!ReferenceEquals(heavyExplicitMods, typedMods.Modifications)) { typedHeavyMods = new TypedExplicitModifications(Peptide, typedMods.LabelType, heavyExplicitMods); typedHeavyMods = typedHeavyMods.AddModMasses(typedStaticMods); } modifications.Add(typedHeavyMods); } if (ArrayUtil.ReferencesEqual(modifications, _modifications)) return this; if (modifications.Count == 0) return null; return ChangeProp(ImClone(this), im => im._modifications = MakeReadOnly(modifications)); }
/// <summary> /// Create a new set of explicit modifications on a peptide from a list of desired /// modifications of each type, and the global lists of available modifications. /// </summary> /// <param name="nodePep">The peptide to modify</param> /// <param name="staticMods">Static modifications to be applied</param> /// <param name="listStaticMods">Global static modifications</param> /// <param name="heavyMods">All sets of isotope labeled mods to be applied</param> /// <param name="listHeavyMods">Global isotope labeled mods</param> /// <param name="implicitOnly">True to create an explicit expression of the implicit modifications</param> public ExplicitMods(PeptideDocNode nodePep, IList<StaticMod> staticMods, MappedList<string, StaticMod> listStaticMods, IEnumerable<TypedModifications> heavyMods, MappedList<string, StaticMod> listHeavyMods, bool implicitOnly = false) { Peptide = nodePep.Peptide; var modifications = new List<TypedExplicitModifications>(); TypedExplicitModifications staticTypedMods = null; // Add static mods, if applicable if (staticMods != null) { IList<ExplicitMod> explicitMods = GetImplicitMods(staticMods, listStaticMods); // If the peptide has variable modifications, make them all override // the modification state of the default implicit mods if (!implicitOnly && nodePep.HasVariableMods) { explicitMods = MergeExplicitMods(nodePep.ExplicitMods.StaticModifications, explicitMods, staticMods); } staticTypedMods = new TypedExplicitModifications(Peptide, IsotopeLabelType.light, explicitMods); modifications.Add(staticTypedMods); } foreach (TypedModifications typedMods in heavyMods) { var explicitMods = GetImplicitMods(typedMods.Modifications, listHeavyMods); var typedHeavyMods = new TypedExplicitModifications(Peptide, typedMods.LabelType, explicitMods); modifications.Add(typedHeavyMods.AddModMasses(staticTypedMods)); } _modifications = MakeReadOnly(modifications.ToArray()); }
public bool Equals(TypedExplicitModifications other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.LabelType, LabelType) && ArrayUtil.EqualsDeep(other.Modifications, Modifications); }
public TypedExplicitModifications AddModMasses(TypedExplicitModifications typedStaticMods) { if (typedStaticMods == null) return this; if (_typedStaticMods != null) throw new InvalidOperationException(Resources.TypedExplicitModifications_AddModMasses_Static_mod_masses_have_already_been_added_for_this_heavy_type); if (LabelType.IsLight) throw new InvalidOperationException(Resources.TypedExplicitModifications_AddModMasses_Static_mod_masses_may_not_be_added_to_light_type); var im = ImClone(this); im._typedStaticMods = typedStaticMods; im._modMassesMono = AddModMasses(im._modMassesMono, typedStaticMods._modMassesMono); im._modMassesAvg = AddModMasses(im._modMassesAvg, typedStaticMods._modMassesAvg); return im; }
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); }