コード例 #1
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));
            }

            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;
        }
コード例 #2
0
        /// <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}.");
        }
コード例 #3
0
ファイル: ModificationLookupBase.cs プロジェクト: zrolfs/sdk
        /// <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;
        }
コード例 #4
0
 public GlobalModification(IProteoformMassDelta modificationDelta, ICollection <char>?targetAminoAcids)
     : base(modificationDelta)
 {
     this.TargetAminoAcids = targetAminoAcids;
 }
コード例 #5
0
 public TagGroupModification(IProteoformMassDelta modificationDelta, string groupName, IReadOnlyCollection <IProteoformModificationGroupMember> members)
     : base(modificationDelta)
 {
     this.GroupName = groupName;
     this.Members   = members;
 }
コード例 #6
0
 public UnlocalizedModification(IProteoformMassDelta modificationDelta, int count, bool isLabile)
     : base(modificationDelta)
 {
     this.Count    = count;
     this.IsLabile = isLabile;
 }
コード例 #7
0
 public LocalizedModification(IProteoformMassDelta modificationDelta, int zeroBasedStartIndex, int zeroBasedEndIndex)
     : base(modificationDelta)
 {
     this.ZeroBasedStartIndex = zeroBasedStartIndex;
     this.ZeroBasedEndIndex   = zeroBasedEndIndex;
 }
コード例 #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;
 }