示例#1
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);
        }