示例#1
0
        public ShiftedSequenceGraph(AminoAcidSet aminoAcidSet, double shiftedMass, bool isForward, int maxSequenceLength, double maxSequenceMass = 50000.0)
        {
            _aminoAcidSet = aminoAcidSet;
            _modificationParams = aminoAcidSet.GetModificationParams();

            _isForward = isForward;

            _index = 0;
            _maxSeqIndex = maxSequenceLength + 2;   // shift + Term + length
            _maxSequenceMass = maxSequenceMass;

            _aminoAcidSequence = new AminoAcid[_maxSeqIndex];
            var shiftAa = new AminoAcid('\0', "Shift", new CompositionWithDeltaMass(shiftedMass));
            _aminoAcidSequence[0] = shiftAa;

            ShiftMass = shiftedMass;

            _fragmentComposition = new Composition.Composition[_maxSeqIndex];
            _fragmentComposition[0] = shiftAa.Composition;

            _graph = new Node[_maxSeqIndex][];
            _graph[0] = new[] { new Node(0) };

            _nodeComposition = new Composition.Composition[_maxSeqIndex][]; 
            _compNodeComposition = new Composition.Composition[_maxSeqIndex][];
            for (var i = 0; i < _maxSeqIndex; i++)
            {
                _compNodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations];
                _nodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations];
            }

            IsValid = true;
        }
示例#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>
        /// <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;
                    Node newNode;
                    // unmodified edge
                    if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out newNode))
                    {
                        newNode.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 newNode))
                        {
                            newNode.AddPrevNodeIndex(prevNodeIndex);
                        }
                        else
                        {
                            modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex));
                        }
                    }
                    _graph[_index] = modCombIndexToNodeMap.Values.ToArray();
                }
            }

            return true;
        }
示例#3
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;
                    Node newNode;
                    // unmodified edge
                    if (modCombIndexToNodeMap.TryGetValue(prevModCombIndex, out newNode))
                    {
                        newNode.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 newNode))
                        {
                            newNode.AddPrevNodeIndex(prevNodeIndex);
                        }
                        else
                        {
                            modCombIndexToNodeMap.Add(modCombIndex, new Node(modCombIndex, prevNodeIndex));
                        }
                    }
                    _graph[_index] = modCombIndexToNodeMap.Values.ToArray();
                }
            }

            return true;
        }
示例#4
0
        protected SequenceGraph(AminoAcidSet aminoAcidSet, AminoAcid nTerm, string sequence, AminoAcid cTerm)
        {
            _aminoAcidSet = aminoAcidSet;
            _sequence = sequence;
            _nTerm = nTerm;

            _modificationParams = aminoAcidSet.GetModificationParams();

            _maxSeqIndex = sequence.Length + 3;  // init + C-term + sequence length + N-term

            _index = 0;

            _aminoAcidSequence = new AminoAcid[_maxSeqIndex];
            _aminoAcidSequence[0] = AminoAcid.Empty;

            _suffixComposition = new Composition.Composition[_maxSeqIndex];
            _suffixComposition[0] = Composition.Composition.Zero;

            _graph = new Node[_maxSeqIndex][];
            _graph[0] = new[] { new Node(0) };

            _nodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations];
            _compNodeComposition = new Composition.Composition[_maxSeqIndex][]; //, _modificationParams.NumModificationCombinations];
            
            for (var i = 0; i < _maxSeqIndex; i++)
            {
                _compNodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations];
                _nodeComposition[i] = new Composition.Composition[_modificationParams.NumModificationCombinations];
            }
            
            NumNTermCleavages = 0;
            IsValid = true;
            SetNTerminalAminoAcid(nTerm);
            AddAminoAcid(cTerm.Residue);
            for (var i = sequence.Length - 1; i >= 0; i--)
            {
                if (AddAminoAcid(sequence[i]) == false)
                {
                    IsValid = false;
                    break;
                }
            }
            if (IsValid) AddAminoAcid(nTerm.Residue);
        }