Ejemplo n.º 1
0
        /// <summary>
        /// Make all heavy modifications explicit.  The document insert code will force them
        /// back to implicit later, if the match the implicit modifications.
        /// </summary>
        public void ConvertAllHeavyModsExplicit()
        {
            foreach (var typedModifications in MatcherPepMods.GetHeavyModifications())
            {
                MatcherPepMods = MatcherPepMods.ChangeModifications(typedModifications.LabelType,
                                                                    typedModifications.Modifications.Select(mod =>
                {
                    if (UserDefinedTypedMods.Keys.Any(userMod => userMod.Equivalent(mod)))
                    {
                        return(mod);
                    }
                    return(mod.ChangeExplicit(true));
                }).ToArray());
            }

            foreach (var key in Matches.Keys.ToArray())
            {
                var match = Matches[key];
                if (match.HeavyMod != null && !UserDefinedTypedMods.Keys.Contains(match.HeavyMod))
                {
                    Matches[key] = new AAModMatch
                    {
                        StructuralMod = match.StructuralMod,
                        HeavyMod      = match.HeavyMod.ChangeExplicit(true)
                    };
                }
            }
        }
        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);
        }
        /// <summary>
        /// Make all heavy modifications explicit.  The document insert code will force them
        /// back to implicit later, if the match the implicit modifications.
        /// </summary>
        public void ConvertAllHeavyModsExplicit()
        {
            MatcherPepMods = MatcherPepMods.ChangeHeavyModifications(MatcherPepMods.HeavyModifications.Select(
                                                                         mod =>
                                                                         UserDefinedTypedMods.Keys.Contains(userMod => userMod.Equivalent(mod))
                    ? mod
                    : mod.ChangeExplicit(true)).ToArray());

            foreach (var key in Matches.Keys.ToArray())
            {
                var match = Matches[key];
                if (match.HeavyMod != null && !UserDefinedTypedMods.Keys.Contains(match.HeavyMod))
                {
                    Matches[key] = new AAModMatch
                    {
                        StructuralMod = match.StructuralMod,
                        HeavyMod      = match.HeavyMod.ChangeExplicit(true)
                    };
                }
            }
        }
        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);
            }
        }
        /// <summary>
        /// Make all heavy modifications explicit.  The document insert code will force them
        /// back to implicit later, if the match the implicit modifications.
        /// </summary>
        public void ConvertAllHeavyModsExplicit()
        {
            MatcherPepMods = MatcherPepMods.ChangeHeavyModifications(MatcherPepMods.HeavyModifications.Select(
                mod =>
                UserDefinedTypedMods.Keys.Contains(userMod => userMod.Equivalent(mod))
                    ? mod
                    : mod.ChangeExplicit(true)).ToArray());

            foreach (var key in Matches.Keys.ToArray())
            {
                var match = Matches[key];
                if (match.HeavyMod != null && !UserDefinedTypedMods.Keys.Contains(match.HeavyMod))
                {
                    Matches[key] = new AAModMatch
                       {
                           StructuralMod = match.StructuralMod,
                           HeavyMod = match.HeavyMod.ChangeExplicit(true)
                       };
                }
            }
        }
        public PeptideDocNode CreateDocNodeFromMatches(PeptideDocNode nodePep, IEnumerable <AAModInfo> infos, bool stringPaste, out bool hasHeavy)
        {
            hasHeavy = false;
            List <ExplicitMod> listLightMods = new List <ExplicitMod>();
            var dictHeavyMods = new Dictionary <IsotopeLabelType, List <ExplicitMod> >();

            foreach (var info in infos)
            {
                var match = GetMatch(info.ModKey);
                if (match == null)
                {
                    return(null);
                }
                AAModMatch modMatch = (AAModMatch)match;
                var        lightMod = modMatch.StructuralMod;
                if (lightMod != null)
                {
                    // Make sure all mods are explicit for ensure mods.
                    if (stringPaste)
                    {
                        lightMod = lightMod.ChangeExplicit(true);
                    }
                    listLightMods.Add(new ExplicitMod(info.IndexAA, lightMod));
                }
                var heavyMod = modMatch.HeavyMod;
                if (heavyMod != null)
                {
                    var type = UserDefinedTypedMods.ContainsKey(modMatch.HeavyMod)
                                   ? UserDefinedTypedMods[modMatch.HeavyMod]
                                   : DocDefHeavyLabelType;
                    List <ExplicitMod> listHeavyMods;
                    if (!dictHeavyMods.TryGetValue(type, out listHeavyMods))
                    {
                        listHeavyMods = new List <ExplicitMod>();
                        dictHeavyMods.Add(type, listHeavyMods);
                    }
                    listHeavyMods.Add(new ExplicitMod(info.IndexAA, heavyMod));
                }
            }

            // Build the set of explicit modifications for the peptide.
            // If ensure mods is set to true, then perform the work here to ensure
            // that the mods persist corectly with the current settings.
            var targetImplicitMods = new ExplicitMods(nodePep,
                                                      Settings.PeptideSettings.Modifications.StaticModifications,
                                                      DefSetStatic,
                                                      Settings.PeptideSettings.Modifications.GetHeavyModifications(),
                                                      DefSetHeavy);

            // If no light modifications are present, this code assumes the user wants the
            // default global light modifications.  Unless not stringPaste, in which case the target
            // static mods must also be empty
            if (listLightMods.Count == 0 && (stringPaste || targetImplicitMods.StaticModifications.Count == 0))
            {
                listLightMods = null;
            }
            else if (stringPaste && ArrayUtil.EqualsDeep(listLightMods.ToArray(), targetImplicitMods.StaticModifications))
            {
                listLightMods = null;
            }
            var listTypedHeavyMods = new List <TypedExplicitModifications>();

            foreach (var targetDocMod in targetImplicitMods.GetHeavyModifications())
            {
                List <ExplicitMod> listMods;
                if (dictHeavyMods.TryGetValue(targetDocMod.LabelType, out listMods) &&
                    (!stringPaste || !ArrayUtil.EqualsDeep(listMods, targetDocMod.Modifications)))
                {
                    listTypedHeavyMods.Add(new TypedExplicitModifications(nodePep.Peptide, targetDocMod.LabelType, listMods)
                                           .AddModMasses(listLightMods == null ? null : new TypedExplicitModifications(nodePep.Peptide, IsotopeLabelType.light, listLightMods)));
                }
            }
            // Put the explicit modifications on the peptide.
            ExplicitMods mods = (listLightMods != null || listTypedHeavyMods.Count > 0)
                ? new ExplicitMods(nodePep.Peptide, listLightMods, listTypedHeavyMods,
                                   listLightMods != null && listLightMods.Contains(mod => mod.Modification.IsVariable))
                : null;

            hasHeavy = dictHeavyMods.Keys.Count > 0;
            return(nodePep.ChangeExplicitMods(mods).ChangeSettings(Settings, SrmSettingsDiff.PROPS));
        }
 private void AddMatch(AAModKey key, AAModMatch match)
 {
     Matches.Add(key, match);
 }
 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;
 }
 private void AddMatch(AAModKey key, AAModMatch match)
 {
     Matches.Add(key, match);
 }
 public abstract void UpdateMatcher(AAModInfo info, AAModMatch? match);
Ejemplo n.º 11
0
 public override void UpdateMatcher(AAModInfo info, AAModMatch? match)
 {
     if(match == null)
     {
         var unmatchedSeq = GetSeqModUnmatchedStr(info.IndexAAInSeq);
         if (!UnmatchedSequences.Contains(unmatchedSeq))
             UnmatchedSequences.Add(unmatchedSeq);
     }
 }