private void InitializeUserDefinedTypedMods(SrmDocument document)
        {
            var mods = document.Settings.PeptideSettings.Modifications;

            foreach (var type in mods.GetModificationTypes())
            {
                // Set the default heavy type to the first heavy type encountered.
                if (!ReferenceEquals(type, IsotopeLabelType.light) && DefaultHeavyLabelType == null)
                {
                    DefaultHeavyLabelType = type;
                }

                foreach (var mod in mods.GetModificationsByName(type.Name).Modifications.Where(m => !m.IsUserSet))
                {
                    UserDefinedTypedMods.Add(mod);
                }
            }

            var staticMods = new TypedModifications(IsotopeLabelType.light, mods.StaticModifications);
            var heavyMods  = new TypedModifications(DefaultHeavyLabelType, mods.GetModifications(DefaultHeavyLabelType));

            foreach (var mod in staticMods.Modifications.Union(heavyMods.Modifications))
            {
                UserDefinedTypedMods.Add(mod);
            }
        }
Exemple #2
0
        /// <summary>
        ///  Create PeptideModifications matching the modifications indicated in the library.
        /// </summary>
        /// <param name="settings">The settings for the document for which the matches will be made</param>
        public PeptideModifications CreateMatcherPeptideSettings(SrmSettings settings)
        {
            var lightMods = new List <StaticMod>();
            var heavyMods = new Dictionary <IsotopeLabelType, List <StaticMod> >();

            if (HasMatches)
            {
                foreach (var matchPair in Matches)
                {
                    var       structuralMod = matchPair.Value.StructuralMod;
                    StaticMod mod1          = structuralMod;
                    if (structuralMod != null && !lightMods.Contains(mod => mod.Equivalent(mod1)))
                    {
                        // Make all found structural mods variable, unless they are preexisting modifications.
                        if (!UserDefinedTypedMods.ContainsKey(structuralMod) || structuralMod.IsUserSet)
                        {
                            structuralMod = structuralMod.ChangeVariable(true);
                        }
                        // Set modification to be implicit if it appears to be implicit in the library.
                        if (!UserDefinedTypedMods.ContainsKey(structuralMod) && !IsVariableMod(structuralMod))
                        {
                            structuralMod = structuralMod.ChangeExplicit(false);
                        }
                        lightMods.Add(structuralMod);
                    }
                    var heavyMod = matchPair.Value.HeavyMod;
                    if (heavyMod == null)
                    {
                        continue;
                    }
                    IsotopeLabelType labelType;
                    if (!UserDefinedTypedMods.TryGetValue(heavyMod, out labelType))
                    {
                        labelType = DocDefHeavyLabelType;
                    }
                    heavyMod = heavyMod.ChangeExplicit(false);
                    if (!heavyMods.ContainsKey(labelType))
                    {
                        heavyMods.Add(labelType, new List <StaticMod> {
                            heavyMod
                        });
                    }
                    else if (!heavyMods[labelType].Contains(mod => mod.Equivalent(heavyMod)))
                    {
                        heavyMods[labelType].Add(heavyMod);
                    }
                }
            }
            var typedModifications = new List <TypedModifications>();

            foreach (var labelType in heavyMods.Keys)
            {
                typedModifications.Add(new TypedModifications(labelType, heavyMods[labelType]));
            }
            var mods = settings.PeptideSettings.Modifications;

            return(new PeptideModifications(lightMods, mods.MaxVariableMods, mods.MaxNeutralLosses,
                                            typedModifications, new[] { IsotopeLabelType.heavy }));
        }
        private void InitUserDefTypedModDict(TypedModifications typedModifications, bool includeExplicit)
        {
            var type = typedModifications.LabelType;

            foreach (StaticMod mod in typedModifications.Modifications
                     .Where(mod => includeExplicit || !mod.IsUserSet))
            {
                var modName = mod.Name;
                if (!UserDefinedTypedMods.Keys.Contains(key => Equals(key.Name, modName)))
                {
                    var newMod = mod;
                    // TODO: This appears to be problematic
                    if (includeExplicit && !mod.IsVariable)
                    {
                        newMod = mod.ChangeExplicit(true);
                    }
                    UserDefinedTypedMods.Add(newMod, type);
                }
            }
        }
        public IEnumerable <StaticMod> GetMatchedMods()
        {
            var allMods = MatcherPepMods.StaticModifications.Union(MatcherHeavyMods);

            return(allMods.Where(mod => !UserDefinedTypedMods.Any(mod.Equivalent)));
        }
        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));
        }