Пример #1
0
        private void ComputeScoreMatrix()
        {
            // Will be initalized to all zeros since that is the default int value in c#
            this.scoreMatrix = new int[Protein1.Encoding.Length + 1, Protein2.Encoding.Length + 1];

            for (int i = 0; i < Protein1.Encoding.Length; i++)
            {
                for (int j = 0; j < Protein2.Encoding.Length; j++)
                {
                    int v1 = scoreMatrix[i, j] + Blosum62.Sigma(Protein1.Encoding[i].ToString(), Protein2.Encoding[j].ToString());
                    int v2 = scoreMatrix[i, j + 1] + SW.GapPenalty;
                    int v3 = scoreMatrix[i + 1, j] + SW.GapPenalty;
                    int v4 = 0;

                    int max = Math.Max(Math.Max(v1, v2), Math.Max(v3, v4));
                    this.scoreMatrix[i + 1, j + 1] = max;

                    // Update with the new score
                    if (max > this.Score)
                    {
                        this.Score         = max;
                        this.scorePosition = new Tuple <int, int>(i + 1, j + 1);
                    }
                }
            }
        }
Пример #2
0
        private void ComputeTraceback()
        {
            this.P1Trace = new List <int>();
            this.P2Trace = new List <int>();

            if (this.scoreMatrix == null)
            {
                return;
            }

            // Start at the location of the max score and work backwards
            int i = this.scorePosition.Item1;
            int j = this.scorePosition.Item2;

            while (true)
            {
                if (this.scoreMatrix[i, j] == 0)
                {
                    break;
                }

                int current = this.scoreMatrix[i, j];

                // Check which adjacent location caused us to get here

                // Check above
                int x = this.scoreMatrix[i - 1, j];
                if (this.scoreMatrix[i - 1, j] + SW.GapPenalty == current)
                {
                    P1Trace.Add(i);
                    P2Trace.Add(-1); // gap

                    // We could have landed here from the element to the above
                    i = i - 1;

                    continue;
                }

                // Check left
                x = this.scoreMatrix[i, j - 1];
                if (this.scoreMatrix[i, j - 1] + SW.GapPenalty == current)
                {
                    P1Trace.Add(-1); // gap
                    P2Trace.Add(j);

                    // We could have landed here from the element to the left
                    j = j - 1;

                    continue;
                }

                // Check diagonal
                int a = this.scoreMatrix[i - 1, j - 1];
                int b = Blosum62.Sigma(Protein1.Encoding[i - 1].ToString(), Protein2.Encoding[j - 1].ToString());
                x = a + b;
                if (this.scoreMatrix[i - 1, j - 1] + Blosum62.Sigma(Protein1.Encoding[i - 1].ToString(), Protein2.Encoding[j - 1].ToString()) == current)
                {
                    P1Trace.Add(i);
                    P2Trace.Add(j);

                    // We could have landed here from the diagonal adjacent element
                    i = i - 1;
                    j = j - 1;

                    continue;
                }

                break;
            }

            this.P1Trace.Reverse();
            this.P2Trace.Reverse();
        }