Пример #1
0
 public void Add(DataVertex vertex, DataEdge inEdge)
 {
     Add(vertex);
     Sequence.Add(inEdge.AminoAcid);
 }
Пример #2
0
        /// <summary>
        /// Build the data graph from a sequence graph.
        /// </summary>
        private void BuildGraph()
        {
            var sequenceRev = this._sequence.Reverse();
            var sequence    = sequenceRev.Aggregate(string.Empty, (current, aa) => current + aa);

            sequence      = "\0" + sequence;
            this.vertices = new DataVertex[this._maxSeqIndex][];
            var mods       = this.AminoAcidSet.GetModificationParams();
            int id         = 0;
            int ntermIndex = 0;
            int start      = this._maxSeqIndex - 2;
            int end        = 0;
            int offset     = 1;

            if (this.nterminal != null)
            {
                start++;
                sequence += this.nterminal.Residue;
            }

            if (this.cterminal != null)
            {
                end--;
                offset   = 0;
                sequence = sequence.Insert(1, this.cterminal.Residue.ToString(CultureInfo.InvariantCulture));
            }

            // create vertices
            for (var si = start; si > end; si--)
            {
                var graphSi = si - offset;
                this.vertices[graphSi] = new DataVertex[this._graph[si].Length];
                for (var mi = 0; mi < this._graph[si].Length; mi++)
                {
                    var node = this._graph[si][mi];
                    var mod  = mods.GetModificationCombination(node.ModificationCombinationIndex);
                    this.SetSink(mi);
                    this.vertices[graphSi][mi] = new DataVertex
                    {
                        ID                      = id++,
                        NTermIndex              = ntermIndex,
                        ModIndex                = mi,
                        PrefixComposition       = this.GetComplementaryComposition(si, mi),
                        SuffixComposition       = this.GetComposition(si, mi),
                        ModificationCombination = mod,
                        Text                    = string.Empty
                    };
                    var vertex = this.vertices[graphSi][mi];
                    this.DataGraph.AddVertex(vertex);
                }

                ntermIndex++;
            }

            // connect vertices
            for (var si = start; si > (end + 1); si--)
            {
                var graphSi = si - offset;
                for (int mi = 0; mi < this._graph[si].Length; mi++)
                {
                    var node       = this._graph[si][mi];
                    var currVertex = this.vertices[graphSi][mi];
                    foreach (var nextModIndex in node.GetPrevNodeIndices())
                    {
                        var nextVertex     = this.vertices[graphSi - 1][nextModIndex];
                        var currVertexMods = currVertex.ModificationCombination.Modifications;
                        var nextVertexMods = nextVertex.ModificationCombination.Modifications;
                        var result         = new List <Modification>(currVertexMods);
                        foreach (var mod in nextVertexMods)
                        {
                            if (result.Contains(mod))
                            {
                                result.Remove(mod);
                            }
                        }

                        AminoAcid aminoAcid;
                        if (si == start && this.nterminal != null)
                        {
                            aminoAcid = this.nterminal;
                        }
                        else if (si == end + 2 && this.cterminal != null)
                        {
                            aminoAcid = this.cterminal;
                        }
                        else
                        {
                            aminoAcid = this.AminoAcidSet.GetAminoAcid(sequence[graphSi]);
                        }

                        var          modAa        = aminoAcid as ModifiedAminoAcid;
                        Modification aminoAcidMod = null;
                        if (modAa != null)
                        {
                            aminoAcidMod = modAa.Modification;
                        }

                        if (aminoAcidMod != null)
                        {
                            result.Add(aminoAcidMod);
                        }

                        var edgeModifications = new ModificationCombination(result);
                        var edge = new DataEdge(currVertex, nextVertex)
                        {
                            AminoAcid     = aminoAcid,
                            SequenceIndex = graphSi,
                            Modifications = edgeModifications
                        };

                        this.DataGraph.AddEdge(edge);
                    }
                }
            }
        }