-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_translate.py
322 lines (268 loc) · 11.3 KB
/
test_translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#! /usr/bin/env python3
import unittest
import test_util
import translate
class TestTranslateBaseClass(test_util.TestBaseClass):
def setUp(self):
self.genetic_code = {'GUC': 'V', 'ACC': 'T', 'GUA': 'V', 'GUG': 'V', 'ACU': 'T', 'AAC': 'N', 'CCU': 'P', 'UGG': 'W', 'AGC': 'S', 'AUC': 'I', 'CAU': 'H', 'AAU': 'N', 'AGU': 'S', 'GUU': 'V', 'CAC': 'H', 'ACG': 'T', 'CCG': 'P', 'CCA': 'P', 'ACA': 'T', 'CCC': 'P', 'UGU': 'C', 'GGU': 'G', 'UCU': 'S', 'GCG': 'A', 'UGC': 'C', 'CAG': 'Q', 'GAU': 'D', 'UAU': 'Y', 'CGG': 'R', 'UCG': 'S', 'AGG': 'R', 'GGG': 'G', 'UCC': 'S', 'UCA': 'S', 'UAA': '*', 'GGA': 'G', 'UAC': 'Y', 'GAC': 'D', 'UAG': '*', 'AUA': 'I', 'GCA': 'A', 'CUU': 'L', 'GGC': 'G', 'AUG': 'M', 'CUG': 'L', 'GAG': 'E', 'CUC': 'L', 'AGA': 'R', 'CUA': 'L', 'GCC': 'A', 'AAA': 'K', 'AAG': 'K', 'CAA': 'Q', 'UUU': 'F', 'CGU': 'R', 'CGC': 'R', 'CGA': 'R', 'GCU': 'A', 'GAA': 'E', 'AUU': 'I', 'UUG': 'L', 'UUA': 'L', 'UGA': '*', 'UUC': 'F'}
def run_translate_sequence(self, rna_seq,
expected_amino_acid_seq,
gen_code = None):
if gen_code is None:
gen_code = self.genetic_code
key_word_args = {
"rna_sequence" : rna_seq,
"genetic_code" : gen_code,
}
self.run_test_of_function(
function = translate.translate_sequence,
key_word_args = key_word_args,
expected_result = expected_amino_acid_seq)
def run_get_all_translations(self, rna_seq,
expected_result,
gen_code = None):
if gen_code is None:
gen_code = self.genetic_code
key_word_args = {
"rna_sequence" : rna_seq,
"genetic_code" : gen_code,
}
amino_acid_seqs = translate.get_all_translations(**key_word_args)
if amino_acid_seqs:
amino_acid_seqs = sorted(amino_acid_seqs)
if expected_result:
expected_result = sorted(expected_result)
self.assertEqual(amino_acid_seqs, expected_result,
self.get_failure_message(
function = translate.get_all_translations,
key_word_args = key_word_args,
expected_result = expected_result,
result = amino_acid_seqs))
def run_get_reverse(self, seq, expected_result):
self.run_test_of_function(
function = translate.get_reverse,
key_word_args = {"sequence" : seq},
expected_result = expected_result)
def run_get_complement(self, seq, expected_result):
self.run_test_of_function(
function = translate.get_complement,
key_word_args = {"sequence" : seq},
expected_result = expected_result)
def run_reverse_and_complement(self, seq, expected_result):
self.run_test_of_function(
function = translate.reverse_and_complement,
key_word_args = {"sequence" : seq},
expected_result = expected_result)
def run_get_longest_peptide(self, rna_seq,
expected_result,
gen_code = None):
if gen_code is None:
gen_code = self.genetic_code
key_word_args = {
"rna_sequence" : rna_seq,
"genetic_code" : gen_code,
}
self.run_test_of_function(
function = translate.get_longest_peptide,
key_word_args = key_word_args,
expected_result = expected_result)
class TestTranslateSequence(TestTranslateBaseClass):
def test_empty_rna_sequence(self):
rna_seq = ""
expected_amino_acid_seq = ""
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_rna_sequence_with_one_base(self):
rna_seq = "A"
expected_amino_acid_seq = ""
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_rna_sequence_with_two_bases(self):
rna_seq = "AG"
expected_amino_acid_seq = ""
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_only_stop_codon(self):
rna_seq = "UGA"
expected_amino_acid_seq = ""
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_one_codon(self):
rna_seq = "GUC"
expected_amino_acid_seq = "V"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
rna_seq = "GAA"
expected_amino_acid_seq = "E"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_one_codon_lower_case(self):
rna_seq = "guc"
expected_amino_acid_seq = "V"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
rna_seq = "gaa"
expected_amino_acid_seq = "E"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_no_stop_to_end(self):
rna_seq = "GUCGAACGA"
expected_amino_acid_seq = "VER"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_no_stop_with_extra_base(self):
rna_seq = "GUCGAACGAA"
expected_amino_acid_seq = "VER"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_stop_codon_at_end(self):
rna_seq = "GUCGAACGAUAA"
expected_amino_acid_seq = "VER"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
def test_stop_codon_within(self):
rna_seq = "GUCGAAUAACGA"
expected_amino_acid_seq = "VE"
self.run_translate_sequence(
rna_seq = rna_seq,
expected_amino_acid_seq = expected_amino_acid_seq)
class TestGetAllTranslations(TestTranslateBaseClass):
def test_no_translations(self):
rna_seq = "GUCGAAUAACGA"
expected_amino_acid_seqs = []
self.run_get_all_translations(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seqs)
def test_one_start_at_end(self):
rna_seq = "GUCGAAUAACGAAUG"
expected_amino_acid_seqs = ["M"]
self.run_get_all_translations(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seqs)
def test_two_short_peptides(self):
rna_seq = "CCUGAAUGACGUACGUAUGACUGCAGUACGUUACGUACG"
expected_amino_acid_seqs = [
"MTYV",
"MTAVRYV",
]
self.run_get_all_translations(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seqs)
def test_two_short_peptides_lower_case(self):
rna_seq = "ccugaaugacguacguaugacugcaguacguuacguacg"
expected_amino_acid_seqs = [
"MTYV",
"MTAVRYV",
]
self.run_get_all_translations(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seqs)
def test_two_short_peptides_at_beginning(self):
rna_seq = "AUGACGUACGUAUGACUGCAGUACGUUACGUACG"
expected_amino_acid_seqs = [
"MTYV",
"MTAVRYV",
]
self.run_get_all_translations(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seqs)
class TestGetReverse(TestTranslateBaseClass):
def test_empty_string(self):
seq = ""
expected_result = ""
self.run_get_reverse(seq, expected_result)
def test_one_base(self):
seq = "A"
expected_result = "A"
self.run_get_reverse(seq, expected_result)
def test_simple(self):
seq = "AUGC"
expected_result = "CGUA"
self.run_get_reverse(seq, expected_result)
def test_simple_lower_case(self):
seq = "augc"
expected_result = "CGUA"
self.run_get_reverse(seq, expected_result)
class TestGetComplement(TestTranslateBaseClass):
def test_empty_string(self):
seq = ""
expected_result = ""
self.run_get_complement(seq, expected_result)
def test_one_base(self):
seq = "G"
expected_result = "C"
self.run_get_complement(seq, expected_result)
def test_simple(self):
seq = "AUGC"
expected_result = "UACG"
self.run_get_complement(seq, expected_result)
def test_simple_lower_case(self):
seq = "augc"
expected_result = "UACG"
self.run_get_complement(seq, expected_result)
class TestReverseAndComplement(TestTranslateBaseClass):
def test_empty_string(self):
seq = ""
expected_result = ""
self.run_reverse_and_complement(seq, expected_result)
def test_one_base(self):
seq = "A"
expected_result = "U"
self.run_reverse_and_complement(seq, expected_result)
def test_simple(self):
seq = "AUGC"
expected_result = "GCAU"
self.run_reverse_and_complement(seq, expected_result)
def test_simple(self):
seq = "augc"
expected_result = "GCAU"
self.run_reverse_and_complement(seq, expected_result)
class TestGetLongestPeptide(TestTranslateBaseClass):
def test_no_translations(self):
rna_seq = "GUCGAAUAACGA"
# UCGUUAUUCGAC
expected_amino_acid_seq = ""
self.run_get_longest_peptide(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seq)
def test_one_start_at_end(self):
rna_seq = "GUCGAAUAACGAAUG"
# CAUUCGUUAUUCGAC
expected_amino_acid_seq = "M"
self.run_get_longest_peptide(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seq)
def test_two_short_peptides(self):
rna_seq = "CCUGAAUGACGUACGUAUGACUGCAGUACGUUACGUACG"
# CGUACGUAACGUACUGCAGUCAUACGUACGUCAUUCAGG
expected_amino_acid_seq = "MTAVRYV"
self.run_get_longest_peptide(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seq)
def test_two_short_peptides_in_rev_comp(self):
rna_seq = "CGUACGUAACGUACUGCAGUCAUACGUACGUCAUUCAGG"
# "CCUGAAUGACGUACGUAUGACUGCAGUACGUUACGUACG"
expected_amino_acid_seq = "MTAVRYV"
self.run_get_longest_peptide(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seq)
def test_two_short_peptides_lower_case(self):
rna_seq = "ccugaaugacguacguaugacugcaguacguuacguacg"
# CGUACGUAACGUACUGCAGUCAUACGUACGUCAUUCAGG
expected_amino_acid_seq = "MTAVRYV"
self.run_get_longest_peptide(
rna_seq = rna_seq,
expected_result = expected_amino_acid_seq)
if __name__ == '__main__':
unittest.main()