def setUp(self): """Setup for NeedlemanWunschMatrix tests.""" self.nw_matrix = NeedlemanWunschMatrix('ACGU', 'CAGU') #Since _init_first_row, _init_first_col and _init_first_cell are #automatically called when NeedlemanWunschMatrix is initialized, #need to change all elements in nw_matrix_empty to 0 to test #that each _init works. self.nw_matrix_empty = \ NeedlemanWunschMatrix('ACGU','CAGU') for i in range(len(self.nw_matrix_empty)): for j in range(len(self.nw_matrix_empty[i])): self.nw_matrix_empty[i][j] = ScoreCell(0)
def setUp(self): """Setup for NeedlemanWunschMatrix tests.""" self.nw_matrix = NeedlemanWunschMatrix("ACGU", "CAGU") # Since _init_first_row, _init_first_col and _init_first_cell are # automatically called when NeedlemanWunschMatrix is initialized, # need to change all elements in nw_matrix_empty to 0 to test # that each _init works. self.nw_matrix_empty = NeedlemanWunschMatrix("ACGU", "CAGU") for i in range(len(self.nw_matrix_empty)): for j in range(len(self.nw_matrix_empty[i])): self.nw_matrix_empty[i][j] = ScoreCell(0)
class NeedlemanWunschMatrixTests(TestCase): """Tests for NeedlemanWunschMatrix class. """ def setUp(self): """Setup for NeedlemanWunschMatrix tests.""" self.nw_matrix = NeedlemanWunschMatrix('ACGU', 'CAGU') #Since _init_first_row, _init_first_col and _init_first_cell are #automatically called when NeedlemanWunschMatrix is initialized, #need to change all elements in nw_matrix_empty to 0 to test #that each _init works. self.nw_matrix_empty = \ NeedlemanWunschMatrix('ACGU','CAGU') for i in range(len(self.nw_matrix_empty)): for j in range(len(self.nw_matrix_empty[i])): self.nw_matrix_empty[i][j] = ScoreCell(0) def test_init_first_row(self): """Tests for NeedlemanWunschMatrix _init_first_row function.""" nw_matrix_empty = copy(self.nw_matrix_empty) #Init first row nw_matrix_empty._init_first_row() #matrix after first row init matrix_scores_first_row_init = [[0, -1, -2, -3, -4], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] for i in range(len(nw_matrix_empty)): for j in range(len(nw_matrix_empty[i])): self.assertEqual(nw_matrix_empty[i][j].Score,\ matrix_scores_first_row_init[i][j]) def test_init_first_col(self): """Tests for NeedlemanWunschMatrix _init_first_col function.""" nw_matrix_empty = copy(self.nw_matrix_empty) #Init first row nw_matrix_empty._init_first_col() #matrix after first row init matrix_scores_first_row_init = [[0, 0, 0, 0, 0], [-1, 0, 0, 0, 0], [-2, 0, 0, 0, 0], [-3, 0, 0, 0, 0], [-4, 0, 0, 0, 0]] for i in range(len(nw_matrix_empty)): for j in range(len(nw_matrix_empty[i])): self.assertEqual(nw_matrix_empty[i][j].Score,\ matrix_scores_first_row_init[i][j]) def test_init_first_cell(self): """Tests for NeedlemanWunschMatrix _init_first_cell function.""" nw_matrix_empty = copy(self.nw_matrix_empty) #Init first row nw_matrix_empty._init_first_cell() self.assertEqual(nw_matrix_empty[0][0].Score, 0) def test_initialized_matrix(self): """Tests for NeedlemanWunschMatrix after full initialization.""" matrix_scores_first_row_init = [[0, -1, -2, -3, -4], [-1, 0, 0, 0, 0], [-2, 0, 0, 0, 0], [-3, 0, 0, 0, 0], [-4, 0, 0, 0, 0]] for i in range(len(self.nw_matrix)): for j in range(len(self.nw_matrix[i])): self.assertEqual(self.nw_matrix[i][j].Score,\ matrix_scores_first_row_init[i][j]) def test_fill(self): """Tests for NeedlemanWunschMatrix fill function.""" filled_nw_matrix = copy(self.nw_matrix) filled_nw_matrix.fill() matrix_scores_filled = [[0, -1, -2, -3, -4], [-1, -1, 0, -1, -2], [-2, 0, -1, -1, -2], [-3, -1, -1, 0, -1], [-4, -2, -2, -1, 1]] matrix_pointers_filled = [[None, 'left', 'left', 'left', 'left'], ['up', 'diag', 'diag', 'left', 'left'], ['up', 'diag', 'up', 'diag', 'diag'], ['up', 'up', 'diag', 'diag', 'left'], ['up', 'up', 'up', 'up', 'diag']] self.assertEqual(filled_nw_matrix.Filled, True) for i in range(len(filled_nw_matrix)): for j in range(len(filled_nw_matrix[i])): self.assertEqual(filled_nw_matrix[i][j].Score,\ matrix_scores_filled[i][j]) self.assertEqual(filled_nw_matrix[i][j].Pointer,\ matrix_pointers_filled[i][j]) self.assertEqual(filled_nw_matrix.MaxScore, (1, 4, 4)) def test_traceback(self): """Tests for NeedlemanWunschMatrix traceback function.""" self.nw_matrix.traceback() self.assertEqual(self.nw_matrix.FirstAlign, ['A', 'C', '-', 'G', 'U']) self.assertEqual(self.nw_matrix.SecondAlign, ['-', 'C', 'A', 'G', 'U'])
class NeedlemanWunschMatrixTests(TestCase): """Tests for NeedlemanWunschMatrix class. """ def setUp(self): """Setup for NeedlemanWunschMatrix tests.""" self.nw_matrix = NeedlemanWunschMatrix("ACGU", "CAGU") # Since _init_first_row, _init_first_col and _init_first_cell are # automatically called when NeedlemanWunschMatrix is initialized, # need to change all elements in nw_matrix_empty to 0 to test # that each _init works. self.nw_matrix_empty = NeedlemanWunschMatrix("ACGU", "CAGU") for i in range(len(self.nw_matrix_empty)): for j in range(len(self.nw_matrix_empty[i])): self.nw_matrix_empty[i][j] = ScoreCell(0) def test_init_first_row(self): """Tests for NeedlemanWunschMatrix _init_first_row function.""" nw_matrix_empty = copy(self.nw_matrix_empty) # Init first row nw_matrix_empty._init_first_row() # matrix after first row init matrix_scores_first_row_init = [ [0, -1, -2, -3, -4], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ] for i in range(len(nw_matrix_empty)): for j in range(len(nw_matrix_empty[i])): self.assertEqual(nw_matrix_empty[i][j].Score, matrix_scores_first_row_init[i][j]) def test_init_first_col(self): """Tests for NeedlemanWunschMatrix _init_first_col function.""" nw_matrix_empty = copy(self.nw_matrix_empty) # Init first row nw_matrix_empty._init_first_col() # matrix after first row init matrix_scores_first_row_init = [ [0, 0, 0, 0, 0], [-1, 0, 0, 0, 0], [-2, 0, 0, 0, 0], [-3, 0, 0, 0, 0], [-4, 0, 0, 0, 0], ] for i in range(len(nw_matrix_empty)): for j in range(len(nw_matrix_empty[i])): self.assertEqual(nw_matrix_empty[i][j].Score, matrix_scores_first_row_init[i][j]) def test_init_first_cell(self): """Tests for NeedlemanWunschMatrix _init_first_cell function.""" nw_matrix_empty = copy(self.nw_matrix_empty) # Init first row nw_matrix_empty._init_first_cell() self.assertEqual(nw_matrix_empty[0][0].Score, 0) def test_initialized_matrix(self): """Tests for NeedlemanWunschMatrix after full initialization.""" matrix_scores_first_row_init = [ [0, -1, -2, -3, -4], [-1, 0, 0, 0, 0], [-2, 0, 0, 0, 0], [-3, 0, 0, 0, 0], [-4, 0, 0, 0, 0], ] for i in range(len(self.nw_matrix)): for j in range(len(self.nw_matrix[i])): self.assertEqual(self.nw_matrix[i][j].Score, matrix_scores_first_row_init[i][j]) def test_fill(self): """Tests for NeedlemanWunschMatrix fill function.""" filled_nw_matrix = copy(self.nw_matrix) filled_nw_matrix.fill() matrix_scores_filled = [ [0, -1, -2, -3, -4], [-1, -1, 0, -1, -2], [-2, 0, -1, -1, -2], [-3, -1, -1, 0, -1], [-4, -2, -2, -1, 1], ] matrix_pointers_filled = [ [None, "left", "left", "left", "left"], ["up", "diag", "diag", "left", "left"], ["up", "diag", "up", "diag", "diag"], ["up", "up", "diag", "diag", "left"], ["up", "up", "up", "up", "diag"], ] self.assertEqual(filled_nw_matrix.Filled, True) for i in range(len(filled_nw_matrix)): for j in range(len(filled_nw_matrix[i])): self.assertEqual(filled_nw_matrix[i][j].Score, matrix_scores_filled[i][j]) self.assertEqual(filled_nw_matrix[i][j].Pointer, matrix_pointers_filled[i][j]) self.assertEqual(filled_nw_matrix.MaxScore, (1, 4, 4)) def test_traceback(self): """Tests for NeedlemanWunschMatrix traceback function.""" self.nw_matrix.traceback() self.assertEqual(self.nw_matrix.FirstAlign, ["A", "C", "-", "G", "U"]) self.assertEqual(self.nw_matrix.SecondAlign, ["-", "C", "A", "G", "U"])