protected override Object getTraceback()
        {
            StringBuilder align1Buf   = new StringBuilder();
            StringBuilder align2Buf   = new StringBuilder();
            Cell          currentCell = getTracebackStartingCell();

            while (traceBackIsNotDone(currentCell))
            {
                if (currentCell.getRow() - currentCell.getPrevCell().getRow() == 1)
                {
                    align2Buf.Insert(0, sequence2[currentCell.getRow() - 1]);
                }
                else
                {
                    align2Buf.Insert(0, '-');
                }
                if (currentCell.getCol() - currentCell.getPrevCell().getCol() == 1)
                {
                    align1Buf.Insert(0, sequence1[currentCell.getCol() - 1]);
                }
                else
                {
                    align1Buf.Insert(0, '-');
                }
                currentCell = currentCell.getPrevCell();
            }

            String[] alignments = new String[]
            {
                align1Buf.ToString(),
                     align2Buf.ToString()
            };

            return(alignments);
        }
Exemplo n.º 2
0
        protected override void fillInCell(Cell currentCell, Cell cellAbove, Cell cellToLeft,
                                           Cell cellAboveLeft)
        {
            int rowSpaceScore        = cellAbove.getScore() + space;
            int colSpaceScore        = cellToLeft.getScore() + space;
            int matchOrMismatchScore = cellAboveLeft.getScore();

            if (sequence2[currentCell.getRow() - 1] == sequence1[currentCell.getCol() - 1])
            {
                matchOrMismatchScore += match;
            }
            else
            {
                matchOrMismatchScore += mismatch;
            }
            if (rowSpaceScore >= colSpaceScore)
            {
                if (matchOrMismatchScore >= rowSpaceScore)
                {
                    currentCell.setScore(matchOrMismatchScore);
                    currentCell.setPrevCell(cellAboveLeft);
                }
                else
                {
                    currentCell.setScore(rowSpaceScore);
                    currentCell.setPrevCell(cellAbove);
                }
            }
            else
            {
                if (matchOrMismatchScore >= colSpaceScore)
                {
                    currentCell.setScore(matchOrMismatchScore);
                    currentCell.setPrevCell(cellAboveLeft);
                }
                else
                {
                    currentCell.setScore(colSpaceScore);
                    currentCell.setPrevCell(cellToLeft);
                }
            }
        }
        public void printScoreTable()
        {
            ensureTableIsFilledIn();
            for (int i = 0; i < sequence2.Length + 2; i++)
            {
                for (int j = 0; j < sequence1.Length + 2; j++)
                {
                    if (i == 0)
                    {
                        if (j == 0 || j == 1)
                        {
                            Console.Write("  ");
                        }
                        else
                        {
                            if (j == 2)
                            {
                                Console.Write("     ");
                            }
                            else
                            {
                                Console.Write("   ");
                            }
                            Console.Write(sequence1[j - 2]);
                        }
                    }
                    else if (j == 0)
                    {
                        if (i == 1)
                        {
                            Console.Write("  ");
                        }
                        else
                        {
                            Console.Write(" " + sequence2[i - 2]);
                        }
                    }
                    else
                    {
                        String toPrint;
                        Cell   currentCell = scoreTable[i - 1, j - 1];
                        Cell   prevCell    = currentCell.getPrevCell();
                        if (prevCell != null)
                        {
                            if (currentCell.getCol() == prevCell.getCol() + 1 &&
                                currentCell.getRow() == prevCell.getRow() + 1)
                            {
                                toPrint = "\\";
                            }
                            else if (currentCell.getCol() == prevCell.getCol() + 1)
                            {
                                toPrint = "-";
                            }
                            else
                            {
                                toPrint = "|";
                            }
                        }
                        else
                        {
                            toPrint = " ";
                        }
                        int    score = currentCell.getScore();
                        String s     = score.ToString().PadLeft(3, '0');
                        toPrint += s;
                        Console.Write(toPrint);
                    }

                    Console.Write(' ');
                }
                Console.WriteLine();
            }
        }