/// <summary>
        /// Gets the modification array.
        /// </summary>
        /// <param name="modifications">The modifications.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">modifications</exception>
        protected void SetupModificationArray(IEnumerable <T> modifications)
        {
            if (modifications == null)
            {
                throw new ArgumentNullException(nameof(modifications));
            }

            var modArray = new IProteoformMassDelta[10000]; // More IDs than will ever exist
            int maxId    = -1;

            foreach (T modification in modifications)
            {
                IChemicalFormula?chemicalFormula = this.GetChemicalFormula(modification);

                int id = Convert.ToInt32(this.RemovePrefix(modification.Id));

                if (chemicalFormula != null)
                {
                    modArray[id] = new ModificationWrapper(modification, chemicalFormula);
                }

                // Keep all the way up to the max passed in, even if it turns out to be NULL
                maxId = Math.Max(maxId, id);
            }

            Array.Resize(ref modArray, maxId + 1);

            _modifications = modArray;
        }
        /// <summary>
        /// Gets the modification.
        /// </summary>
        /// <param name="descriptor">The descriptor.</param>
        /// <returns></returns>
        public virtual IProteoformMassDelta GetModification(IProFormaDescriptor descriptor)
        {
            if (_modifications == null)
            {
                throw new Exception("Modification array in not initialized.");
            }

            if (descriptor.Value == null)
            {
                throw new ProteoformModificationLookupException($"Value is NULL in descriptor {descriptor}.");
            }

            if (descriptor.Key == ProFormaKey.Name)
            {
                string value = descriptor.Value;

                IProteoformMassDelta modification = _modifications
                                                    .SingleOrDefault(x => x != null && ((ModificationWrapper)x).Modification.Name == value);

                if (modification == null)
                {
                    throw new ProteoformModificationLookupException($"Could not find modification using Name in descriptor {descriptor}.");
                }

                return(modification);
            }
            else if (descriptor.Key == ProFormaKey.Identifier)
            {
                string value = this.RemovePrefix(descriptor.Value);

                if (int.TryParse(value, out int id))
                {
                    if (id < 0 || id > _modifications.Length - 1 || _modifications[id] == null)
                    {
                        throw new ProteoformModificationLookupException($"Could not find modification using ID in descriptor {descriptor}.");
                    }

                    return(_modifications[id]);
                }

                throw new ProteoformModificationLookupException($"Invalid integer in descriptor {descriptor}.");
            }

            throw new ProteoformModificationLookupException($"Couldn't handle value for descriptor {descriptor}.");
        }
Exemple #3
0
        /// <summary>
        /// Gets the modification array.
        /// </summary>
        /// <param name="modifications">The modifications.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">modifications</exception>
        protected void SetupModificationArray(IEnumerable <T> modifications)
        {
            if (modifications == null)
            {
                throw new ArgumentNullException(nameof(modifications));
            }

            _modificationNames = new Dictionary <string, IProteoformMassDelta>();

            var modArray = new IProteoformMassDelta[10000]; // More IDs than will ever exist
            int maxId    = -1;

            foreach (T modification in modifications)
            {
                IChemicalFormula?chemicalFormula = this.GetChemicalFormula(modification);

                int id = Convert.ToInt32(this.RemovePrefix(modification.Id));

                if (chemicalFormula != null)
                {
                    modArray[id] = new ModificationWrapper(modification, chemicalFormula);
                }

                // Keep all the way up to the max passed in, even if it turns out to be NULL
                maxId = Math.Max(maxId, id);

                if (_modificationNames != null)
                {
                    // HACK for obsolete PSI-MOD terms with same name as something else ... skip
                    if (modification.Id == "MOD:00949" || modification.Id == "MOD:01966")
                    {
                        continue;
                    }

                    _modificationNames.Add(modification.Name, modArray[id]);
                }
            }

            Array.Resize(ref modArray, maxId + 1);

            _modifications = modArray;
        }
 public GlobalModification(IProteoformMassDelta modificationDelta, ICollection <char>?targetAminoAcids)
     : base(modificationDelta)
 {
     this.TargetAminoAcids = targetAminoAcids;
 }
 public TagGroupModification(IProteoformMassDelta modificationDelta, string groupName, IReadOnlyCollection <IProteoformModificationGroupMember> members)
     : base(modificationDelta)
 {
     this.GroupName = groupName;
     this.Members   = members;
 }
 public UnlocalizedModification(IProteoformMassDelta modificationDelta, int count, bool isLabile)
     : base(modificationDelta)
 {
     this.Count    = count;
     this.IsLabile = isLabile;
 }
 public LocalizedModification(IProteoformMassDelta modificationDelta, int zeroBasedStartIndex, int zeroBasedEndIndex)
     : base(modificationDelta)
 {
     this.ZeroBasedStartIndex = zeroBasedStartIndex;
     this.ZeroBasedEndIndex   = zeroBasedEndIndex;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProteoformModificationBase"/> class.
 /// </summary>
 /// <param name="modificationDelta">The modification delta.</param>
 public ProteoformModificationBase(IProteoformMassDelta modificationDelta)
 {
     ModificationDelta = modificationDelta;
 }