-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittest_motif_mark_oop.py
96 lines (73 loc) · 3.03 KB
/
unittest_motif_mark_oop.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
#!/usr/bin/env python
# import modules
import unittest
import os
from motif_mark_oop import * # TODO: change this
# test files
TEST_MOTIF_FILE = os.path.join(os.path.dirname('../data/input/'),'Fig_1_motifs.txt')
# build test class
class TestMotif(unittest.TestCase):
def setUp(self) -> None:
self.m = 'yY'
self.motif = Motif(self.m)
return super().setUp()
def tearDown(self) -> None:
"""
def tearDown(self):
Clean up temp files
# Remove temp files after tests
os.unlink(self.temp_lib1.name)
os.unlink(self.temp_lib2.name)
os.unlink(self.temp_lib3.name)
# remove temp dir
shutil.rmtree(self.temp_dir)
"""
return super().tearDown()
def test_print_motif(self):
# TODO: build motif class object in each test case
# TODO: standard test case and then extremes (ie empty string)
# TODO: what if motif contains character not in dictionary
# TODO: implimenting exceptions use self.assertRaises
self.assertEqual(self.motif.print_motif('yY'),'yY')
def test_generate_combos(self):
self.assertEqual(self.motif.generate_combos('YY'),['[CTU][CTU]','[ctu][ctu]'])
class TestGene(unittest.TestCase):
def setUp(self) -> None:
self.id_line = '>THOMAS chr1:1-2'
self.sequence = 'aaaaAAAAaaaa'
self.gene = Gene(self.id_line,self.sequence)
# generate motif class
self.m = 'aaaa'
self.motif = Motif(self.m)
return super().setUp()
def test_extract_gene(self):
self.assertEqual(self.gene.extract_gene(self.id_line),'THOMAS')
def test_extract_location(self):
self.assertEqual(self.gene.extract_location(self.id_line), 'chr1:1-2')
def test_identify_exons(self):
self.assertListEqual(self.gene.identify_exons(self.sequence),[(4,8)])
def test_store_motif(self):
self.gene.store_motif(self.motif)
self.assertEqual(self.gene.matches,{self.motif:[]})
def test_identify_matches(self):
self.gene.identify_matches(self.motif,self.sequence)
print(self.gene.matches)
self.assertDictEqual(self.gene.matches,{self.motif:[4, 0, 8]})
class TestAdditionalMethods(unittest.TestCase):
def setUp(self) -> None:
self.id_line = '>THOMAS chr1:1-2'
self.sequence = 'aaaaAAAAaaaa'
self.gene = Gene(self.id_line,self.sequence)
self.m = 'aaaa'
self.motif = Motif(self.m)
return super().setUp()
def tearDown(self) -> None:
return super().tearDown()
def test_read_in_motifs(self):
self.assertListEqual(read_in_motifs(TEST_MOTIF_FILE),['ygcy', 'GCAUG', 'catag', 'YYYYYYYYYY'])
def test_update_longest_gene(self):
master_dict = {'master_list':[self.gene],'longest_gene':3}
new_master_dict = update_longest_gene(master_dict,self.gene)
self.assertEqual(master_dict['longest_gene'],len(self.sequence))
if __name__ == '__main__':
unittest.main()