Exemple #1
0
        public void TestParsingManyMods()
        {
            const string modFilePath = @"\\protoapps\UserData\Jungkap\Lewy\db\Mods.txt";
            var aaSet = new AminoAcidSet(modFilePath);
            //aaSet.Display();


            //SequenceLocation.ProteinNTerm
            var residue = AminoAcid.ProteinNTerm.Residue;
            var location = SequenceLocation.ProteinNTerm;
            var aa = aaSet.GetAminoAcid(residue, location);
            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }
            Console.WriteLine();
            residue = AminoAcid.ProteinCTerm.Residue;
            location = SequenceLocation.ProteinCTerm;
            aa = aaSet.GetAminoAcid(residue, location);
            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }


            //foreach (var aa in AminoAcid.StandardAminoAcidArr)
            
                /*
                var keys = _locationSpecificResidueMap[location].Keys.ToArray();
                Array.Sort(keys);
                foreach (var residue in keys)
                {
                    var aa = GetAminoAcid(residue, location);
                    Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
                    foreach (var modIndex in GetModificationIndices(residue, location))
                    {
                        Console.Write("\t" + _modificationParams.GetModification(modIndex));
                    }
                    Console.WriteLine();
                }
            }     */            


        }
Exemple #2
0
        /// <summary>
        /// Add an amino acid residue to this generator.
        /// </summary>
        /// <param name="index">index to add the amino acid. 0 is C-term. 1 is the C-term amino acid.</param>
        /// <param name="residue">amino acid residue to add.</param>
        /// <returns>true if residue is a valid amino acid; false otherwise.</returns>
        private bool PutAminoAcid(int index, char residue)
        {
            _index = index + 1;

            SequenceLocation?location = null;

            if (_index == 1) // C-term residue
            {
                if (residue == AminoAcid.PeptideCTerm.Residue)
                {
                    location = SequenceLocation.PeptideCTerm;
                }
                else if (residue == AminoAcid.ProteinCTerm.Residue)
                {
                    location = SequenceLocation.ProteinCTerm;
                }
            }
            else if (_index == _aminoAcidSequence.Length - 1 - NumNTermCleavages)   // N-term residue
            {
                if (residue == AminoAcid.PeptideNTerm.Residue)
                {
                    location = SequenceLocation.PeptideNTerm;
                }
                else if (residue == AminoAcid.ProteinNTerm.Residue)
                {
                    location = SequenceLocation.ProteinNTerm;
                }
            }
            else if (_index == 2) // Amino acid at the C-term
            {
                if (_aminoAcidSequence[1] == AminoAcid.PeptideCTerm)
                {
                    location = SequenceLocation.PeptideCTerm;
                }
                else if (_aminoAcidSequence[1] == AminoAcid.ProteinCTerm)
                {
                    location = SequenceLocation.ProteinCTerm;
                }
            }
            else if (_index == _aminoAcidSequence.Length - 2 - NumNTermCleavages) // Amino acid at the N-term
            {
                if (_aminoAcidSequence[_aminoAcidSequence.Length - 1] == AminoAcid.PeptideNTerm)
                {
                    location = SequenceLocation.PeptideNTerm;
                }
                else if (_aminoAcidSequence[_aminoAcidSequence.Length - 1] == AminoAcid.ProteinNTerm)
                {
                    location = SequenceLocation.ProteinNTerm;
                }
            }
            else
            {
                location = SequenceLocation.Everywhere;
            }

            if (location == null)
            {
                return(false);
            }

            var loc       = (SequenceLocation)location;
            var aminoAcid = AminoAcidSet.GetAminoAcid(residue, loc);

            if (aminoAcid == null) // residue is not valid
            {
                return(false);
            }

            _aminoAcidSequence[_index] = aminoAcid;
            _suffixComposition[_index] = _suffixComposition[_index - 1] + aminoAcid.Composition;

            var modIndices = AminoAcidSet.GetModificationIndices(residue, loc);

            if (!modIndices.Any())  // No modification
            {
                _graph[_index] = new Node[_graph[_index - 1].Length];
                for (var i = 0; i < _graph[_index - 1].Length; i++)
                {
                    _graph[_index][i] = new Node(_graph[_index - 1][i].ModificationCombinationIndex, i);
                }
            }
            else
            {
                var modCombIndexToNodeMap = new Dictionary <int, Node>();
                for (var i = 0; i < _graph[_index - 1].Length; i++)
                {
                    var prevNodeIndex    = i;
                    var prevNode         = _graph[_index - 1][i];
                    var prevModCombIndex = prevNode.ModificationCombinationIndex;

                    // unmodified edge
                    if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out var unmodifiedEdgeNode))
                    {
                        unmodifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex);
                    }
                    else
                    {
                        modCombIndexToNodeMap.Add(prevModCombIndex, new Node(prevModCombIndex, prevNodeIndex));
                    }

                    // modified edge
                    foreach (var modIndex in modIndices)
                    {
                        var modCombIndex = ModificationParams.GetModificationCombinationIndex(
                            prevNode.ModificationCombinationIndex, modIndex);
                        if (modCombIndex < 0)   // too many modifications
                        {
                            continue;
                        }
                        if (modCombIndexToNodeMap.TryGetValue(modCombIndex, out var modifiedEdgeNode))
                        {
                            modifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex);
                        }
                        else
                        {
                            modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex));
                        }
                    }
                    _graph[_index] = modCombIndexToNodeMap.Values.ToArray();
                }
            }

            return(true);
        }
        public static Modification[] GetTerminalModifications(AminoAcidSet aminoAcidSet)
        {
            var terminalModifications = new HashSet<Modification>();
            var terminalLocations = new[] {SequenceLocation.ProteinNTerm, SequenceLocation.ProteinCTerm};
            var terminalResidues = new char[] {AminoAcid.ProteinNTerm.Residue, AminoAcid.ProteinCTerm.Residue};
            var modParam = aminoAcidSet.GetModificationParams();

            for (var i = 0; i < terminalLocations.Length; i++)
            {
                var location = terminalLocations[i];
                var residue = terminalResidues[i];
                foreach (var modIndex in aminoAcidSet.GetModificationIndices(residue, location))
                {
                    var modification = modParam.GetModification(modIndex);
                    terminalModifications.Add(modification);
                }
            }
            return terminalModifications.ToArray();
        }
        public static AminoAcid[] GetExtendedAminoAcidArray(AminoAcidSet aaSet)
        {
            var ret = new List<AminoAcid>();
            var modParam = aaSet.GetModificationParams();
            var aminoAcidArray = AminoAcid.StandardAminoAcidArr;

            foreach (var aa in aminoAcidArray)
            {
                ret.Add(aa);
                foreach (var modIndex in aaSet.GetModificationIndices(aa.Residue, SequenceLocation.Everywhere))
                {
                    var aa2 = new ModifiedAminoAcid(aa, modParam.GetModification(modIndex));
                    ret.Add(aa2);
                }
            }
            return ret.ToArray();
        }
Exemple #5
0
        /// <summary>
        /// Add an amino acid residue to this generator.
        /// </summary>
        /// <param name="index">index to add the amino acid. 0 is C-term. 1 is the C-term amino acid.</param>
        /// <param name="residue">amino acid residue to add.</param>
        /// <param name="loc">location of the residue</param>
        /// <returns>true if residue is a valid amino acid; false otherwise.</returns>
        private bool PutAminoAcid(int index, char residue, SequenceLocation loc)
        {
            _index = index + 1;

            var aminoAcid = AminoAcidSet.GetAminoAcid(residue, loc);

            if (aminoAcid == null) // residue is not valid
            {
                return(false);
            }

            var fragmentComposition = _fragmentComposition[_index - 1] + aminoAcid.Composition;

            if (fragmentComposition.Mass > _maxSequenceMass)
            {
                return(false);
            }

            _aminoAcidSequence[_index]   = aminoAcid;
            _fragmentComposition[_index] = fragmentComposition;

            var modIndices = AminoAcidSet.GetModificationIndices(residue, loc);

            if (!modIndices.Any())  // No modification
            {
                _graph[_index] = new Node[_graph[_index - 1].Length];
                for (var i = 0; i < _graph[_index - 1].Length; i++)
                {
                    _graph[_index][i] = new Node(_graph[_index - 1][i].ModificationCombinationIndex, i);
                }
            }
            else
            {
                var modCombIndexToNodeMap = new Dictionary <int, Node>();
                for (var i = 0; i < _graph[_index - 1].Length; i++)
                {
                    var prevNodeIndex    = i;
                    var prevNode         = _graph[_index - 1][i];
                    var prevModCombIndex = prevNode.ModificationCombinationIndex;

                    // unmodified edge
                    if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out var unmodifiedEdgeNode))
                    {
                        unmodifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex);
                    }
                    else
                    {
                        modCombIndexToNodeMap.Add(prevModCombIndex, new Node(prevModCombIndex, prevNodeIndex));
                    }

                    // modified edge
                    foreach (var modIndex in modIndices)
                    {
                        var modCombIndex = ModificationParams.GetModificationCombinationIndex(
                            prevNode.ModificationCombinationIndex, modIndex);
                        if (modCombIndex < 0)   // too many modifications
                        {
                            continue;
                        }
                        if (modCombIndexToNodeMap.TryGetValue(modCombIndex, out var modifiedEdgeNode))
                        {
                            modifiedEdgeNode.AddPrevNodeIndex(prevNodeIndex);
                        }
                        else
                        {
                            modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex));
                        }
                    }
                    _graph[_index] = modCombIndexToNodeMap.Values.ToArray();
                }
            }

            return(true);
        }