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);
        }
示例#2
0
        public PeptideDocNode EnsureMods(PeptideModifications source, PeptideModifications target,
            MappedList<string, StaticMod> defSetStat, MappedList<string, StaticMod> defSetHeavy)
        {
            // Create explicit mods matching the implicit mods on this peptide for each document.
            var sourceImplicitMods = new ExplicitMods(this, source.StaticModifications, defSetStat, source.GetHeavyModifications(), defSetHeavy);
            var targetImplicitMods = new ExplicitMods(this, target.StaticModifications, defSetStat, target.GetHeavyModifications(), defSetHeavy);

            // If modifications match, no need to create explicit modifications for the peptide.
            if (sourceImplicitMods.Equals(targetImplicitMods))
                return this;

            // Add explicit mods if static mods not implicit in the target document.
            IList<ExplicitMod> newExplicitStaticMods = null;
            bool preserveVariable = HasVariableMods;
            // Preserve non-variable explicit modifications
            if (!preserveVariable && HasExplicitMods && ExplicitMods.StaticModifications != null)
            {
                // If they are not the same as the implicit modifications in the new document
                if (!ArrayUtil.EqualsDeep(ExplicitMods.StaticModifications, targetImplicitMods.StaticModifications))
                    newExplicitStaticMods = ExplicitMods.StaticModifications;
            }
            else if (!ArrayUtil.EqualsDeep(sourceImplicitMods.StaticModifications, targetImplicitMods.StaticModifications))
            {
                preserveVariable = false;
                newExplicitStaticMods = sourceImplicitMods.StaticModifications;
            }
            else if (preserveVariable)
            {
                newExplicitStaticMods = ExplicitMods.StaticModifications;
            }

            // Drop explicit mods if matching implicit mods are found in the target document.
            IList<TypedExplicitModifications> newExplicitHeavyMods = new List<TypedExplicitModifications>();
            // For each heavy label type, add explicit mods if static mods not found in the target document.
            var newTypedStaticMods = newExplicitStaticMods != null
                ? new TypedExplicitModifications(Peptide, IsotopeLabelType.light, newExplicitStaticMods)
                : null;
            foreach (TypedExplicitModifications targetDocMod in targetImplicitMods.GetHeavyModifications())
            {
                // Use explicit modifications when available.  Otherwise, compare against new implicit modifications
                IList<ExplicitMod> heavyMods = (HasExplicitMods ? ExplicitMods.GetModifications(targetDocMod.LabelType) : null) ??
                    sourceImplicitMods.GetModifications(targetDocMod.LabelType);
                if (heavyMods != null && !ArrayUtil.EqualsDeep(heavyMods, targetDocMod.Modifications) && heavyMods.Count > 0)
                {
                    var newTypedHeavyMods = new TypedExplicitModifications(Peptide, targetDocMod.LabelType, heavyMods);
                    newTypedHeavyMods = newTypedHeavyMods.AddModMasses(newTypedStaticMods);
                    newExplicitHeavyMods.Add(newTypedHeavyMods);
                }
            }

            if (newExplicitStaticMods != null || newExplicitHeavyMods.Count > 0)
                return ChangeExplicitMods(new ExplicitMods(Peptide, newExplicitStaticMods, newExplicitHeavyMods, preserveVariable));
            return ChangeExplicitMods(null);
        }