private StaticMod GetModByMassInSettings(AAModInfo info, double mass, bool structural)
        {
            StaticMod firstMatch = null;

            foreach (var match in EnumerateModMatchesInSettings(info, mass, structural))
            {
                firstMatch = firstMatch ?? match;
                // Keep looking if it is an isotope modification of the 15N variant where it applies to all amino acids
                if (structural || (info.AppearsToBeSpecificMod && (!string.IsNullOrEmpty(match.AAs) || match.Terminus != null)) ||
                    (!info.AppearsToBeSpecificMod && string.IsNullOrEmpty(match.AAs) && match.Terminus == null))
                {
                    firstMatch = match;
                    break;
                }
            }
            if (firstMatch == null)
            {
                return(null);
            }
            // TODO: Is this necessary
            if (!IsInSettings(firstMatch) && !firstMatch.IsVariable)
            {
                firstMatch = firstMatch.ChangeExplicit(true);
            }
            return(firstMatch);
        }
        private IEnumerable <StaticMod> EnumerateModMatchesInSettings(AAModInfo info, double mass, bool structural)
        {
            var modifications = Settings.PeptideSettings.Modifications;

            foreach (var type in modifications.GetModificationTypes())
            {
                foreach (var mod in modifications.GetModifications(type)
                         .Where(mod => info.IsMassMatch(mod, mass)))
                {
                    if (type.IsLight == structural)
                    {
                        yield return(mod);
                    }
                }
            }
            if (!structural)
            {
                foreach (var mod in DefSetHeavy.Where(mod => info.IsMassMatch(mod, mass)))
                {
                    yield return(mod);
                }
            }
            else
            {
                foreach (var mod in DefSetStatic.Where(mod => info.IsMassMatch(mod, mass)))
                {
                    yield return(mod);
                }
            }
        }
        private AAModMatch?GetModByName(AAModInfo info)
        {
            bool      structural = false;
            StaticMod modMatch   = null;

            // First, look in the document/global settings.
            foreach (var mod in UserDefinedTypedMods.Keys)
            {
                bool matchStuctural = UserDefinedTypedMods[mod].IsLight;
                if (Equals(info.Name, mod.Name) &&
                    (!info.UserIndicatedHeavy || !matchStuctural))
                {
                    modMatch   = mod;
                    structural = matchStuctural;
                }
            }
            // If not found, then look in Unimod.
            modMatch = modMatch ?? UniMod.GetModification(info.Name, out structural);
            if (!info.IsModMatch(modMatch) || (info.UserIndicatedHeavy && structural))
            {
                return(null);
            }
            return(new AAModMatch
            {
                StructuralMod = structural ? modMatch : null,
                HeavyMod = !structural ? modMatch : null
            });
        }
Exemplo n.º 4
0
 public override void UpdateMatcher(AAModInfo info, AAModMatch?match)
 {
     if (match == null)
     {
         var unmatchedSeq = GetSeqModUnmatchedStr(info.IndexAAInSeq);
         if (!UnmatchedSequences.Contains(unmatchedSeq))
         {
             UnmatchedSequences.Add(unmatchedSeq);
         }
     }
 }
        private AAModMatch?GetModByMass(AAModInfo info)
        {
            AAModMatch?match = null;

            // Enumerate all possible partial matches for the given AAModInfo, looking for
            // a complete match for the mass.
            foreach (var partialMatch in SearchPartialModMatches(info))
            {
                // If a partial match explains the entire mass, it is a complete match, so the search is done.
                if (partialMatch.UnexplainedMass == 0)
                {
                    return new AAModMatch
                           {
                               StructuralMod = partialMatch.Structural ? partialMatch.Mod : null,
                               HeavyMod      = !partialMatch.Structural ? partialMatch.Mod : null
                           }
                }
                ;
                // Otherwise, first try to complete the match by looking in the document modifications and
                // global modifications.
                var matchComplete = GetModByMassInSettings(info, partialMatch.UnexplainedMass, !partialMatch.Structural);
                if (matchComplete != null)
                {
                    // If we complete the match with a modification in the document or global settings,
                    // return that match.
                    return(new AAModMatch
                    {
                        StructuralMod = partialMatch.Structural ? partialMatch.Mod : matchComplete,
                        HeavyMod = !partialMatch.Structural ? partialMatch.Mod : matchComplete
                    });
                }
                // If we already have found a potential match in Unimod, don't continue searching Unimod.
                if (match != null)
                {
                    continue;
                }
                // Look in Unimod to complete the match.
                matchComplete = UniMod.MassLookup.MatchModificationMass(partialMatch.UnexplainedMass, info.AA,
                                                                        info.RoundedTo, !partialMatch.Structural,
                                                                        info.Terminus, info.AppearsToBeSpecificMod);
                if (matchComplete != null)
                {
                    // A match that is partially explained by unimod is not as good as a match in the document/gobals,
                    // so keep this match as a good candidate, but keep searching.
                    match = new AAModMatch
                    {
                        StructuralMod = partialMatch.Structural ? partialMatch.Mod : matchComplete,
                        HeavyMod      = !partialMatch.Structural ? partialMatch.Mod : matchComplete
                    };
                }
            }
            return(match);
        }
 EnumeratePartialModMatches(Dictionary <IEnumerable <StaticMod>, bool> dictModLists,
                            AAModInfo info)
 {
     foreach (var dict in dictModLists)
     {
         var mods = dict.Key;
         // Mod can be null to force search for only light/heavy match.
         foreach (var mod in mods.Where(mod => mod == null || info.IsModMatch(mod)))
         {
             double modMass = mod == null ? 0 : GetDefaultModMass(info.AA, mod);
             double mass    = (info.Mass ?? 0) - modMass;
             yield return(new PartialMassMatch
             {
                 Mod = mod == null ? null : mod.ChangeExplicit(true),
                 Structural = dict.Value,
                 UnexplainedMass = Math.Round(mass,
                                              info.RoundedTo)
             });
         }
     }
 }
        /// <summary>
        /// Enumerates partial modifications matches for the given AAModInfo.
        ///
        /// Enumerate matches in the following order:
        /// 1. Partials matches for any previously matched heavy labeling.
        /// 2. Partial structural match with a null structural modification, this means that any complete match
        ///    would have only a heavy modification.
        /// 3. Partial heavy match with a null heavy modification.
        /// 4. Partial matches from the document settings.
        /// 5. Partial heavy matches from UniMod.
        /// 6. Partial heavy matches from UniMod (hidden).
        /// </summary>
        private IEnumerable <PartialMassMatch> SearchPartialModMatches(AAModInfo info)
        {
            Dictionary <IEnumerable <StaticMod>, bool> listsToSearch = new Dictionary <IEnumerable <StaticMod>, bool>();

            if (!info.AppearsToBeSpecificMod)
            {
                listsToSearch.Add(_foundHeavyLabels, false);
            }
            listsToSearch.Add(new StaticMod[] { null }, true);
            listsToSearch.Add(new StaticMod[] { null }, false);
            foreach (var labelType in Settings.PeptideSettings.Modifications.GetModificationTypes())
            {
                listsToSearch.Add(Settings.PeptideSettings.Modifications.GetModifications(labelType).ToArray(),
                                  labelType.IsLight);
            }
            listsToSearch.Add(DefSetStatic, true);
            listsToSearch.Add(DefSetHeavy, false);
            listsToSearch.Add(UniMod.DictIsotopeModNames.Values, false);
            listsToSearch.Add(UniMod.DictHiddenIsotopeModNames.Values, false);
            return(EnumeratePartialModMatches(listsToSearch, info));
        }
        public override void UpdateMatcher(AAModInfo info, AAModMatch?match)
        {
            // Update unmatched sequences.
            if (match == null && !UnmatchedSequences.Contains(info.ModKey.ToString()))
            {
                UnmatchedSequences.Add(info.ModKey.ToString());
            }
            if (match == null || match.Value.StructuralMod == null)
            {
                return;
            }

            // Update the conflicting mod array.
            if (!string.IsNullOrEmpty(match.Value.StructuralMod.AAs))
            {
                AddConflictKey((byte)info.AA, info.Terminus, false);
            }
            if (info.Terminus != null)
            {
                AddConflictKey(null, info.Terminus, false);
            }
        }
Exemplo n.º 9
0
 public override void UpdateMatcher(AAModInfo info, AAModMatch? match)
 {
     if(match == null)
     {
         var unmatchedSeq = GetSeqModUnmatchedStr(info.IndexAAInSeq);
         if (!UnmatchedSequences.Contains(unmatchedSeq))
             UnmatchedSequences.Add(unmatchedSeq);
     }
 }
        public override void UpdateMatcher(AAModInfo info, AAModMatch? match)
        {
            // Update unmatched sequences.
            if (match == null && !UnmatchedSequences.Contains(info.ModKey.ToString()))
                UnmatchedSequences.Add(info.ModKey.ToString());
            if (match == null || match.Value.StructuralMod == null)
                return;

            // Update the conflicting mod array.
            if (!string.IsNullOrEmpty(match.Value.StructuralMod.AAs))
            {
                AddConflictKey((byte) info.AA, info.Terminus, false);
            }
            if (info.Terminus != null)
            {
                AddConflictKey(null, info.Terminus, false);
            }
        }
 private static IEnumerable<PartialMassMatch> EnumeratePartialModMatches(Dictionary<IEnumerable<StaticMod>, bool> dictModLists, 
     AAModInfo info)
 {
     foreach (var dict in dictModLists)
     {
         var mods = dict.Key;
         // Mod can be null to force search for only light/heavy match.
         foreach (var mod in mods.Where(mod => mod == null || info.IsModMatch(mod)))
         {
             double modMass = mod == null ? 0 : GetDefaultModMass(info.AA, mod);
             double mass = (info.Mass ?? 0) - modMass;
             yield return new PartialMassMatch
                              {
                                  Mod = mod == null ? null : mod.ChangeExplicit(true),
                                  Structural = dict.Value,
                                  UnexplainedMass = Math.Round(mass,
                                                               info.RoundedTo)
                              };
         }
     }
 }
 private IEnumerable<StaticMod> EnumerateModMatchesInSettings(AAModInfo info, double mass, bool structural)
 {
     var modifications = Settings.PeptideSettings.Modifications;
     foreach (var type in modifications.GetModificationTypes())
     {
         foreach (var mod in modifications.GetModifications(type)
             .Where(mod => info.IsMassMatch(mod, mass)))
         {
             if (type.IsLight == structural)
                 yield return mod;
         }
     }
     if (!structural)
     {
         foreach (var mod in DefSetHeavy.Where(mod => info.IsMassMatch(mod, mass)))
         {
             yield return mod;
         }
     }
     else
     {
         foreach (var mod in DefSetStatic.Where(mod => info.IsMassMatch(mod, mass)))
         {
             yield return mod;
         }
     }
 }
 public abstract void UpdateMatcher(AAModInfo info, AAModMatch? match);
 public abstract void UpdateMatcher(AAModInfo info, AAModMatch?match);
 /// <summary>
 /// Enumerates partial modifications matches for the given AAModInfo.
 /// 
 /// Enumerate matches in the following order:
 /// 1. Partials matches for any previously matched heavy labeling.
 /// 2. Partial structural match with a null structural modification, this means that any complete match
 ///    would have only a heavy modification.
 /// 3. Partial heavy match with a null heavy modification.
 /// 4. Partial matches from the document settings.
 /// 5. Partial heavy matches from UniMod.
 /// 6. Partial heavy matches from UniMod (hidden).
 /// </summary>
 private IEnumerable<PartialMassMatch> SearchPartialModMatches(AAModInfo info)
 {
     Dictionary<IEnumerable<StaticMod>, bool> listsToSearch = new Dictionary<IEnumerable<StaticMod>, bool>();
     if(!info.AppearsToBeSpecificMod)
         listsToSearch.Add(_foundHeavyLabels, false);
     listsToSearch.Add(new StaticMod[] { null }, true);
     listsToSearch.Add(new StaticMod[] { null }, false);
     foreach (var labelType in Settings.PeptideSettings.Modifications.GetModificationTypes())
     {
         listsToSearch.Add(Settings.PeptideSettings.Modifications.GetModifications(labelType).ToArray(),
             labelType.IsLight);
     }
     listsToSearch.Add(DefSetStatic, true);
     listsToSearch.Add(DefSetHeavy, false);
     listsToSearch.Add(UniMod.DictIsotopeModNames.Values, false);
     listsToSearch.Add(UniMod.DictHiddenIsotopeModNames.Values, false);
     return EnumeratePartialModMatches(listsToSearch, info);
 }
 private AAModMatch? GetModByName(AAModInfo info)
 {
     bool structural = false;
     StaticMod modMatch = null;
     // First, look in the document/global settings.
     foreach (var mod in UserDefinedTypedMods.Keys)
     {
         bool matchStuctural = UserDefinedTypedMods[mod].IsLight;
         if (Equals(info.Name, mod.Name) &&
             (!info.UserIndicatedHeavy || !matchStuctural))
         {
             modMatch = mod;
             structural = matchStuctural;
         }
     }
     // If not found, then look in Unimod.
     modMatch = modMatch ?? UniMod.GetModification(info.Name, out structural);
     if (!info.IsModMatch(modMatch) || (info.UserIndicatedHeavy && structural))
         return null;
     return new AAModMatch
     {
         StructuralMod = structural ? modMatch : null,
         HeavyMod = !structural ? modMatch : null
     };
 }
 private StaticMod GetModByMassInSettings(AAModInfo info, double mass, bool structural)
 {
     StaticMod firstMatch = null;
     foreach (var match in EnumerateModMatchesInSettings(info, mass, structural))
     {
         firstMatch = firstMatch ?? match;
         // Keep looking if it is an isotope modification of the 15N variant where it applies to all amino acids
         if (structural || (info.AppearsToBeSpecificMod && (!string.IsNullOrEmpty(match.AAs) || match.Terminus != null))
                        || (!info.AppearsToBeSpecificMod && string.IsNullOrEmpty(match.AAs) && match.Terminus == null))
         {
             firstMatch = match;
             break;
         }
     }
     if (firstMatch == null)
         return null;
     // TODO: Is this necessary
     if (!IsInSettings(firstMatch) && !firstMatch.IsVariable)
         firstMatch = firstMatch.ChangeExplicit(true);
     return firstMatch;
 }
 private AAModMatch? GetModByMass(AAModInfo info)
 {
     AAModMatch? match = null;
     // Enumerate all possible partial matches for the given AAModInfo, looking for
     // a complete match for the mass.
     foreach (var partialMatch in SearchPartialModMatches(info))
     {
         // If a partial match explains the entire mass, it is a complete match, so the search is done.
         if (partialMatch.UnexplainedMass == 0)
             return new AAModMatch
             {
                 StructuralMod = partialMatch.Structural ? partialMatch.Mod : null,
                 HeavyMod = !partialMatch.Structural ? partialMatch.Mod : null
             };
         // Otherwise, first try to complete the match by looking in the document modifications and
         // global modifications.
         var matchComplete = GetModByMassInSettings(info, partialMatch.UnexplainedMass, !partialMatch.Structural);
         if (matchComplete != null)
         {
             // If we complete the match with a modification in the document or global settings,
             // return that match.
             return new AAModMatch
             {
                 StructuralMod = partialMatch.Structural ? partialMatch.Mod : matchComplete,
                 HeavyMod = !partialMatch.Structural ? partialMatch.Mod : matchComplete
             };
         }
         // If we already have found a potential match in Unimod, don't continue searching Unimod.
         if (match != null)
             continue;
         // Look in Unimod to complete the match.
         matchComplete = UniMod.MassLookup.MatchModificationMass(partialMatch.UnexplainedMass, info.AA,
                                                     info.RoundedTo, !partialMatch.Structural,
                                                     info.Terminus, info.AppearsToBeSpecificMod);
         if (matchComplete != null)
         {
             // A match that is partially explained by unimod is not as good as a match in the document/gobals,
             // so keep this match as a good candidate, but keep searching.
             match = new AAModMatch
             {
                 StructuralMod = partialMatch.Structural ? partialMatch.Mod : matchComplete,
                 HeavyMod = !partialMatch.Structural ? partialMatch.Mod : matchComplete
             };
         }
     }
     return match;
 }