/// <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)); }
public Peptide(PeptideLibraryKey peptideLibraryKey) : this((LibraryKey)peptideLibraryKey) { var modifications = peptideLibraryKey.GetModifications(); if (modifications.Count > 0) { ModificationIndexes = ImmutableList.ValueOf(modifications.Select(mod => mod.Key)); ModificationNames = ImmutableList.ValueOf(modifications.Select(mod => mod.Value)); } }
public override LibraryKey ValueFromCache(ValueCache valueCache) { var libraryKey = this; if (valueCache.TryGetCachedValue(ref libraryKey)) { return(libraryKey); } libraryKey = new PeptideLibraryKey { ModifiedSequence = valueCache.CacheValue(ModifiedSequence), UnmodifiedSequence = valueCache.CacheValue(UnmodifiedSequence), Charge = Charge, }; return(valueCache.CacheValue(libraryKey)); }
private IEnumerable <PeptideLibraryKey> MergePeptideLibraryKey(ICollection <PeptideLibraryKey> thisKeys, PeptideLibraryKey thatKey) { while (true) { PeptideLibraryKey mostGeneralKey = thatKey; foreach (var thisKey in thisKeys) { if (KeysMatch(thisKey, mostGeneralKey)) { mostGeneralKey = MostGeneralPeptideKey(thisKey, mostGeneralKey); } } if (Equals(mostGeneralKey, thatKey)) { break; } thatKey = mostGeneralKey; } return(new[] { thatKey }.Concat(thisKeys.Where(key => !KeysMatch(thatKey, key)))); }
protected bool Equals(PeptideLibraryKey other) { return(string.Equals(ModifiedSequence, other.ModifiedSequence) && Charge == other.Charge); }