public bool IsMassMatch(StaticMod mod, double mass) { var mod1 = new MassModification(GetDefaultModMass(AA, mod), RoundedTo); var mod2 = new MassModification(mass, RoundedTo); if (!mod1.Matches(mod2)) { return(false); } return(IsModMatch(mod)); }
public bool Matches(MassModification that) { int minPrecision = Math.Min(Math.Min(Precision, that.Precision), MAX_PRECISION_TO_MATCH); double thisRound = Math.Round(Mass, minPrecision); double thatRound = Math.Round(that.Mass, minPrecision); if (Equals(thisRound, thatRound)) { return(true); } if (Math.Abs(Mass - that.Mass) < .0001) { // Anytime two modifications are within .0001 of each other, that is also // considered good enough since there are search results out there where // the Cysteine modification differs at that point. return(true); } return(false); }
private IEnumerable <AAModInfo> EnumerateSequenceInfos(string seq, bool includeUnmod) { string aas = FastaSequence.StripModifications(seq); bool isSpecificHeavy = FastaSequence.OPEN_MOD.All(paren => aas.Length > seq.Count(c => c == paren)); int indexAA = 0; int indexAAInSeq = 0; int i = 0; while (i < seq.Length) { var aa = aas[indexAA]; int indexBracket = i + 1; if (indexBracket < seq.Length && (FastaSequence.OPEN_MOD.Contains(seq[indexBracket]))) { char openBracket = seq[indexBracket]; bool isHeavy = openBracket == '{'; char closeBracket = FastaSequence.CLOSE_MOD[FastaSequence.OPEN_MOD.IndexOf(c => c == openBracket)]; int indexStart = indexBracket + 1; int indexClose = seq.IndexOf(closeBracket, indexBracket); string mod = seq.Substring(indexStart, indexClose - indexStart); i = indexClose; ModTerminus?modTerminus = null; if (indexAA == 0) { modTerminus = ModTerminus.N; } if (indexAA == aas.Length - 1) { modTerminus = ModTerminus.C; } string name = null; double?mass = null; int roundedTo = 0; // If passed in modification in UniMod notation, look up the id and find the name and mass int uniModId; if (TryGetIdFromUnimod(mod, out uniModId)) { var staticMod = GetStaticMod(uniModId, aa, modTerminus); if (staticMod == null) { throw ThrowUnimodException(seq, uniModId, indexAA, indexBracket, indexClose); } name = staticMod.Name; isHeavy = !UniMod.IsStructuralModification(name); // CONSIDER: Mass depends on TransitionPrediction settings for precursors mass = staticMod.MonoisotopicMass; roundedTo = DEFAULT_ROUNDING_DIGITS; } else { MassModification massModification = MassModification.Parse(mod); if (massModification != null) { mass = massModification.Mass; roundedTo = Math.Min(massModification.Precision, DEFAULT_ROUNDING_DIGITS); } else { name = mod; } } if (mass.HasValue) { mass = Math.Round(mass.Value, roundedTo); } var key = new AAModKey { Name = name, Mass = mass, AA = aa, Terminus = modTerminus, UserIndicatedHeavy = isHeavy, RoundedTo = roundedTo, AppearsToBeSpecificMod = isSpecificHeavy }; yield return(new AAModInfo { ModKey = key, IndexAA = indexAA, IndexAAInSeq = indexAAInSeq, }); } else if (includeUnmod) { // If need unmodified amino acids (as when // checking for equality), yield SequenceKeys for these AA's. var key = new AAModKey { AA = aa, Mass = 0 }; yield return(new AAModInfo { ModKey = key, IndexAA = indexAA, }); } // If the next character is a bracket, continue using the same amino // acid and leave i where it is. int iNext = i + 1; if (iNext >= seq.Length || !FastaSequence.OPEN_MOD.Contains(seq[iNext])) { i = indexAAInSeq = iNext; indexAA++; } } }
protected bool Equals(MassModification other) { return(Mass.Equals(other.Mass) && Precision == other.Precision); }
private IEnumerable <AAModInfo> EnumerateSequenceInfos(PeptideLibraryKey peptideLibraryKey, bool allowDuplicates) { if (peptideLibraryKey == null) { yield break; } string sequence = peptideLibraryKey.ModifiedSequence; bool isSpecificHeavy = !AllAminoAcidsModified(sequence); char? prevAA = null; int indexAA = -1; for (int index = 0; index < sequence.Length; index++) { char b = sequence[index]; if (b != '[') // L10N { if (isSpecificHeavy) { if (index > 0 && prevAA.HasValue) { AddConflictKey(prevAA, null, true); } if (index == 1) { AddConflictKey(prevAA, ModTerminus.N, true); } } prevAA = b; indexAA++; } else { ModTerminus?terminus = null; int startIndex = index + 1; int endIndex = sequence.IndexOf(']', startIndex); if (endIndex == -1) { endIndex = sequence.Length; } if (index == 1) { terminus = ModTerminus.N; } if (endIndex == sequence.Length - 1) { terminus = ModTerminus.C; } // Only if prevAA is an amino acid character should AAModInfo be created // Some libraries, for instance, have been created with the sequence starting // with a modification before any amino acid, as an attempt at a n-terminal modification if (prevAA.HasValue && AminoAcid.IsExAA(prevAA.Value)) { List <string> listMasses; if (!_dictAAMassPairs.TryGetValue(new AATermKey(prevAA, terminus), out listMasses)) { listMasses = new List <string>(); _dictAAMassPairs.Add(new AATermKey(prevAA, terminus), listMasses); } var modArr = sequence.Substring(startIndex, endIndex - startIndex); if (allowDuplicates || !listMasses.Contains(modArr)) { if (!allowDuplicates) { listMasses.Add(modArr); } string massString = modArr; var massModification = MassModification.Parse(massString); if (massModification != null) { yield return(new AAModInfo { IndexAA = indexAA, ModKey = new AAModKey { AA = prevAA.Value, Terminus = terminus, AppearsToBeSpecificMod = isSpecificHeavy, Mass = massModification.Mass, RoundedTo = massModification.Precision } }); } // NistLibraryBase writes [?] for any modification it does not understand else if (!Equals(@"?", massString)) { // Get more information on a failure that was posted to the exception web page throw new FormatException(string.Format(Resources.LibKeyModificationMatcher_EnumerateSequenceInfos_The_number___0___is_not_in_the_correct_format_, massString)); } } } prevAA = null; index = endIndex; } } // If the last AA was not modified, we need to update the conflictingMods array. if (prevAA.HasValue) { AddConflictKey(prevAA, null, true); AddConflictKey(null, ModTerminus.C, true); } }