1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from unittest import TestCase
24
25
26 from lib.sequence_alignment.needleman_wunsch import needleman_wunsch_align
27 from lib.sequence_alignment.substitution_matrices import NUC_4_4, NUC_4_4_SEQ, SIMILARITY_DNA, SIMILARITY_DNA_SEQ
28
29
31 """Unit tests for the lib.sequence_alignment.needleman_wunsch relax module."""
32
34 """Test the Needleman-Wunsch sequence alignment for two DNA sequences."""
35
36
37 seq1 = 'GCATTACT'
38 seq2 = 'GATTACT'
39 print("\nIn:")
40 print(seq1)
41 print(seq2)
42
43
44 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=SIMILARITY_DNA, sub_seq=SIMILARITY_DNA_SEQ, gap_open_penalty=1, gap_extend_penalty=1)
45 print("\nOut:")
46 print(score)
47 print(align1)
48 print(align2)
49 print(gaps)
50 print("\n")
51
52
53 self.assertEqual(align1, 'GCATTACT')
54 self.assertEqual(align2, 'G-ATTACT')
55
56
57 real_gaps = [
58 [0, 0, 0, 0, 0, 0, 0, 0],
59 [0, 1, 0, 0, 0, 0, 0, 0]
60 ]
61 for i in range(2):
62 for j in range(8):
63 self.assertEqual(gaps[i, j], real_gaps[i][j])
64
65
67 """Test the Needleman-Wunsch sequence alignment for two DNA sequences using the NUC 4.4 matrix.
68
69 From online servers, the results with a gap open penalty of 5 and gap extend of 1 should be::
70
71 https://www.ebi.ac.uk/Tools/psa/emboss_needle/
72 EMBOSS_001 1 GAAAAAAT 8
73 | |||
74 EMBOSS_001 1 G----AAT 4
75 """
76
77
78 seq1 = 'GAAAAAAT'
79 seq2 = 'GAAT'
80 print("\nIn:")
81 print(seq1)
82 print(seq2)
83
84
85 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=NUC_4_4, sub_seq=NUC_4_4_SEQ, gap_open_penalty=5, gap_extend_penalty=1)
86 print("\nOut:")
87 print(score)
88 print(align1)
89 print(align2)
90 print(gaps)
91 print("\n")
92
93
94 self.assertEqual(align1, 'GAAAAAAT')
95 self.assertEqual(align2, 'G----AAT')
96
97
98 real_gaps = [
99 [0, 0, 0, 0, 0, 0, 0, 0],
100 [0, 1, 1, 1, 1, 0, 0, 0]
101 ]
102 for i in range(2):
103 for j in range(8):
104 self.assertEqual(gaps[i, j], real_gaps[i][j])
105
106
108 """Test the Needleman-Wunsch sequence alignment for two DNA sequences using the NUC 4.4 matrix.
109
110 From online servers, the results with a gap open penalty of 5 and gap extend of 1 should be::
111
112 https://www.ebi.ac.uk/Tools/psa/emboss_needle/
113 EMBOSS_001 1 GACAGAAT- 8
114 ||||
115 EMBOSS_001 1 ----GAATA 5
116 """
117
118
119 seq1 = 'GACAGAAT'
120 seq2 = 'GAATA'
121 print("\nIn:")
122 print(seq1)
123 print(seq2)
124
125
126 score, align1, align2, gaps = needleman_wunsch_align(seq1, seq2, sub_matrix=NUC_4_4, sub_seq=NUC_4_4_SEQ, gap_open_penalty=5, gap_extend_penalty=1)
127 print("\nOut:")
128 print(score)
129 print(align1)
130 print(align2)
131 print(gaps)
132 print("\n")
133
134
135 self.assertEqual(align1, 'GACAGAAT-')
136 self.assertEqual(align2, '----GAATA')
137
138
139 real_gaps = [
140 [0, 0, 0, 0, 0, 0, 0, 0, 1],
141 [1, 1, 1, 1, 0, 0, 0, 0, 0]
142 ]
143 for i in range(2):
144 for j in range(8):
145 self.assertEqual(gaps[i, j], real_gaps[i][j])
146