/// <summary> /// Given two keys that match each other (i.e. the modification masses are within the other's margin of error) /// return a key which has the lower precision of the two. /// For instance, if one key is C[+57.021464]PEPTIDER[+10] and the is C[+57.02]PEPTIDEK[10.0083], /// the result be C[+57.02]PEPTIDER[+10]. /// </summary> private PeptideLibraryKey MostGeneralPeptideKey(PeptideLibraryKey key1, PeptideLibraryKey key2) { Assume.AreEqual(key1.UnmodifiedSequence, key2.UnmodifiedSequence); var mods1 = key1.GetModifications(); var mods2 = key2.GetModifications(); Assume.AreEqual(mods1.Count, mods2.Count); var newMods = new List <KeyValuePair <int, string> >(mods1.Count); for (int i = 0; i < mods1.Count; i++) { var mod1 = mods1[i]; var mod2 = mods2[i]; Assume.AreEqual(mod1.Key, mod2.Key); if (mod1.Value == mod2.Value) { newMods.Add(mod1); continue; } MassModification massMod1 = MassModification.Parse(mod1.Value); MassModification massMod2 = MassModification.Parse(mod2.Value); if (massMod1.Precision <= massMod2.Precision) { newMods.Add(mod1); } else { newMods.Add(mod2); } } return(new PeptideLibraryKey(MakeModifiedSequence(key1.UnmodifiedSequence, newMods), key1.Charge)); }
/// <summary> /// Change the format of all modifications so that they are in the Skyline 3.7 /// format of having one digit after the decimal. /// </summary> public PeptideLibraryKey FormatToOneDecimal() { if (!HasModifications) { return(this); } StringBuilder newSequence = new StringBuilder(); int aaCount = 0; foreach (var mod in GetModifications()) { newSequence.Append(UnmodifiedSequence.Substring(aaCount, mod.Key + 1 - aaCount)); aaCount = mod.Key + 1; var massModification = MassModification.Parse(mod.Value); string newMod; if (massModification == null) { newMod = mod.Value; } else { newMod = new MassModification(massModification.Mass, 1).ToString(); } newSequence.Append(Model.ModifiedSequence.Bracket(newMod)); } newSequence.Append(UnmodifiedSequence.Substring(aaCount)); return(new PeptideLibraryKey(newSequence.ToString(), Charge)); }
public static bool ModificationsMatch(string strMod1, string strMod2) { if (strMod1 == strMod2) { return(true); } var massMod1 = MassModification.Parse(strMod1); var massMod2 = MassModification.Parse(strMod2); if (massMod1 == null || massMod2 == null) { return(false); } return(massMod1.Matches(massMod2)); }