/// <summary>
            /// The trace back procedure of Smith Wunsch algorithm is similar to needlemen
            /// but:
            /// 1. start from the high score cells
            /// 2. end at zero-score cell or 0,0 point
            /// </summary>
            public AlignResult traceBack(char[,] traceBackMatrix, string seq1, string seq2, int x, int y)
            {
                // start from the highest cells
                //Seed site
                int ti = x;
                int tj = y;

                char[]        seq_1       = seq1.ToCharArray();
                char[]        seq_2       = seq2.ToCharArray();
                StringBuilder seq1Builder = new StringBuilder();
                StringBuilder seq2Builder = new StringBuilder();

                while (ti > 0 || tj > 0) // stop at (0,0) point
                {
                    if (traceBackMatrix[ti, tj] == '.')
                    {
                        break;                                 //stop at zero cell
                    }
                    switch (traceBackMatrix[ti, tj])
                    {
                    case '|':
                        seq1Builder.Insert(0, '-');
                        seq2Builder.Insert(0, seq_2[ti - 1]);
                        ti--;
                        break;

                    case '\\':
                        seq1Builder.Insert(0, seq_1[tj - 1]);
                        seq2Builder.Insert(0, seq_2[ti - 1]);
                        ti--;
                        tj--;
                        break;

                    case '-':
                        seq1Builder.Insert(0, seq_1[tj - 1]);
                        seq2Builder.Insert(0, '-');
                        tj--;
                        break;

                    default:
                        break;
                    }
                }
                AlignResult AR = new AlignResult(seq1Builder.ToString(), seq2Builder.ToString());

                AR.seq2_end = x; //ti;
                AR.seq1_end = y; // tj;
                return(AR);
            }
Ejemplo n.º 2
0
        public void AlignMatchTypeTest()
        {
            MatchResult <int, string> mr1 = new MatchResult <int, string>(5, "A");
            MatchResult <int, string> mr2 = new MatchResult <int, string>(5, "A");

            Assert.IsTrue(mr1.Equals(mr2));

            mr2 = new MatchResult <int, string>(5, "A1");
            Assert.IsTrue(!mr1.Equals(mr2));

            //-----------------//

            MatchResult <string, string> mr3 = new MatchResult <string, string>("5", "A");
            MatchResult <string, string> mr4 = new MatchResult <string, string>("5", "A");

            Assert.IsTrue(mr3.Equals(mr4));

            mr4 = new MatchResult <string, string>("A", "5");
            Assert.IsTrue(!mr3.Equals(mr4));

            Assert.IsTrue(!mr3.Equals(null));

            Assert.IsTrue(mr3.GetHashCode() == mr4.GetHashCode());

            //-----------------//

            AlignResult <int, string> ar1 = new AlignResult <int, string>(5, "A");
            AlignResult <int, string> ar2 = new AlignResult <int, string>(5, "A");

            Assert.IsTrue(ar1.Equals(ar2));

            ar2 = new AlignResult <int, string>(5, "A1");
            Assert.IsTrue(!ar1.Equals(ar2));

            //-----------------//

            AlignResult <string, string> ar3 = new AlignResult <string, string>("5", "A");
            AlignResult <string, string> ar4 = new AlignResult <string, string>("5", "A");

            Assert.IsTrue(ar3.Equals(ar4));

            ar4 = new AlignResult <string, string>("A", "5");
            Assert.IsTrue(!ar3.Equals(ar4));

            Assert.IsTrue(!ar3.Equals(null));

            Assert.IsTrue(ar3.GetHashCode() == ar4.GetHashCode());
        }