private static string GetMatchString(AAModKey key, StaticMod staticMod, bool structural) { string formatString = structural ? @"{0}[{1}{2}]" : @"{0}{{{1}{2}}}"; var modMass = Math.Round(GetDefaultModMass(key.AA, staticMod), key.RoundedTo); return(string.Format(formatString, key.AA, (modMass > 0 ? @"+" : string.Empty), modMass)); }
protected override AAModMatch?GetMatch(AAModKey key) { var match = base.GetMatch(key); if (match == null || match.Value.StructuralMod == null || UserDefinedTypedMods.Keys.Contains(mod => mod.Equivalent(match.Value.StructuralMod))) { return(match); } // If the match has a structural modification that should be variable, // return a match that indicates that. return(new AAModMatch { // CONSIDER: Should we make all matches variable initially, instead of attempting to guess each time? StructuralMod = match.Value.StructuralMod.ChangeVariable(IsVariableMod(match.Value.StructuralMod)), HeavyMod = match.Value.HeavyMod }); }
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 override AAModMatch? GetMatch(AAModKey key) { var match = base.GetMatch(key); if (match == null || match.Value.StructuralMod == null || UserDefinedTypedMods.Keys.Contains(mod => mod.Equivalent(match.Value.StructuralMod))) return match; // If the match has a structural modification that should be variable, // return a match that indicates that. return new AAModMatch { // CONSIDER: Should we make all matches variable initially, instead of attempting to guess each time? StructuralMod = match.Value.StructuralMod.ChangeVariable(IsVariableMod(match.Value.StructuralMod)), HeavyMod = match.Value.HeavyMod }; }
protected virtual AAModMatch?GetMatch(AAModKey key) { return(Matches.ContainsKey(key) ? Matches[key] : (AAModMatch?)null); }
private void AddMatch(AAModKey key, AAModMatch match) { Matches.Add(key, match); }
private static string GetMatchString(AAModKey key, StaticMod staticMod, bool structural) { string formatString = structural ? "{0}[{1}{2}]" : "{0}{{{1}{2}}}"; // Not L10N var modMass = Math.Round(GetDefaultModMass(key.AA, staticMod), key.RoundedTo); return string.Format(formatString, key.AA, (modMass > 0 ? "+" : string.Empty), modMass); // Not L10N }
protected virtual AAModMatch? GetMatch(AAModKey key) { return Matches.ContainsKey(key) ? Matches[key] : (AAModMatch?)null; }
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]))) // Not L10N { char openBracket = seq[indexBracket]; bool isHeavy = openBracket == '{'; // Not L10N 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; double result; // 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) { 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 if (double.TryParse(mod, NumberStyles.Float, FormatProvider ?? NumberFormatInfo.CurrentInfo, out result)) { mass = result; int decPlace = mod.IndexOf(LocalizationHelper.CurrentCulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal); if (decPlace != -1) roundedTo = Math.Min(mod.Length - decPlace - 1, 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])) // Not L10N { i = indexAAInSeq = iNext; indexAA++; } } }