-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
149 lines (126 loc) · 7.18 KB
/
test.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
import unittest
from pileup_reader import pileup_reader, preprocess_bases, get_indel_string
from variant_caller import VariantCaller
class TestPreprocess(unittest.TestCase):
def test_empty(self):
self.assertEqual(preprocess_bases(''), '')
def test_normal(self):
self.assertEqual(preprocess_bases(',.$...,,,.,..^+.'),'.............')
self.assertEqual(preprocess_bases(',.$$$..A..,'),'....A...')
self.assertEqual(preprocess_bases('$$$^.'),'')
class TestIndelString(unittest.TestCase):
def test_normal(self):
self.assertEqual(get_indel_string('.+1AAT'),'AAT')
self.assertEqual(get_indel_string('.-1C'),'C')
self.assertEqual(get_indel_string('.-2G'),'GG')
self.assertEqual(get_indel_string('.+3CGC'),'CGCCGCCGC')
self.assertEqual(get_indel_string('.-12G'),'GGGGGGGGGGGG')
class TestPileupReader(unittest.TestCase):
def test_normal(self):
pileup_lines = []
pileup_lines.append({'chromosome': '21', 'position': 9483252,
'ref_base': 'T', 'read_count': 1,
'read_bases': '.', 'qualities': 'B',
'A': 0, 'C': 0, 'G': 0, 'T': 1,
'insertions': [], 'deletitions': []})
pileup_lines.append({'chromosome': '21', 'position': 9483266,
'ref_base': 'T', 'read_count': 3,
'read_bases': '..^<.', 'qualities': '@@>',
'A': 0, 'C': 0, 'G': 0, 'T': 3,
'insertions': [], 'deletitions': []})
pileup_lines.append({'chromosome': '22', 'position': 41616770,
'ref_base': 'G', 'read_count': 90,
'read_bases': '...,..,....,,............,.,..........-1A,,,,,,...,.,...,..,.,,..,...........,..,,.,........^],',
'qualities': 'fA]@@ZA_HhGGG<rgAJpIkGCoKJIBV=AFIJJJHk@8B@BFIGF>J@eJA9CJ0II>FFBJJ<IBHJJHJJEDH@8AEHJFHCG?AC',
'A': 0, 'C': 0, 'G': 89, 'T': 0,
'insertions': [], 'deletitions': [['A', 1]]})
i = 0
for item in pileup_reader('test_data/test.pileup'):
self.assertEqual(item, pileup_lines[i])
i += 1
class TestVariantCaller(unittest.TestCase):
def test_normal(self):
variant_caller = VariantCaller()
mockPositionInfo = { 'A' : 8, 'G' : 1, 'C' : 1, 'T' : 1 , 'ref_base' : 'A'}
variant_caller.call_variant(mockPositionInfo, 0.8)
self.assertEqual(mockPositionInfo['alts'],'.')
mockPositionInfo = { 'A' : 1, 'G' : 7, 'C' : 1, 'T' : 8 , 'ref_base' : 'G'}
variant_caller.call_variant(mockPositionInfo, 0.8)
self.assertEqual(mockPositionInfo['genotype'],(0, 1))
self.assertEqual(mockPositionInfo['alts'],['T'])
mockPositionInfo = { 'A' : 1, 'G' : 7, 'C' : 1, 'T' : 8 , 'ref_base' : 'A'}
variant_caller.call_variant(mockPositionInfo, 0.8)
self.assertEqual(mockPositionInfo['genotype'],(1, 2))
self.assertEqual(mockPositionInfo['alts'],['T', 'G'])
def test_indels(self):
def test_one_insert(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 7, 'C' : 1, 'T' : 1, \
'ref_base' : 'G', 'insertions': [('ACAC', 8)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (0, 1))
self.assertEqual(mockPositionInfo['alts'], ['GACAC'])
self.assertEqual(mockPositionInfo['ref_base'], 'G')
def test_one_snv_one_insert(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 7, 'C' : 1, 'T' : 1, \
'ref_base' : 'A', 'insertions': [('ACAC', 8)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (1, 2))
self.assertEqual(mockPositionInfo['alts'], ['AACAC', 'G'])
self.assertEqual(mockPositionInfo['ref_base'], 'A')
def test_two_inserts(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 1, 'C' : 1, 'T' : 1, \
'ref_base' : 'A', 'insertions': [('ACAC', 8), ('GTGT', 7)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (1, 2))
self.assertEqual(mockPositionInfo['alts'], ['AACAC', 'AGTGT'])
self.assertEqual(mockPositionInfo['ref_base'], 'A')
def test_one_delete(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 7, 'C' : 1, 'T' : 1, \
'ref_base' : 'G', 'deletitions': [('ACAC', 8)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (0, 1))
self.assertEqual(mockPositionInfo['alts'], ['G'])
self.assertEqual(mockPositionInfo['ref_base'], 'GACAC')
def test_one_delete_one_snv(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 7, 'C' : 1, 'T' : 1, \
'ref_base' : 'A', 'deletitions': [('ACAC', 8)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (1, 2))
self.assertEqual(mockPositionInfo['alts'], ['A', 'GACAC'])
self.assertEqual(mockPositionInfo['ref_base'], 'AACAC')
def test_one_delete_one_insert(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 1, 'C' : 1, 'T' : 1, \
'ref_base' : 'T', 'deletitions': [('ACAC', 8)], 'insertions' : [('GT', 7)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (1, 2))
self.assertEqual(mockPositionInfo['alts'], ['T', 'TGTACAC'])
self.assertEqual(mockPositionInfo['ref_base'], 'TACAC')
def test_two_deletes(variant_caller):
mockPositionInfo = { 'A' : 1, 'G': 1, 'C' : 1, 'T' : 1, \
'ref_base' : 'T', 'deletitions': [('ACAC', 8), ('AC', 7)]}
variant_caller.call_variant(mockPositionInfo)
self.assertEqual(mockPositionInfo['genotype'], (1, 2))
self.assertEqual(mockPositionInfo['alts'], ['T', 'TAC'])
self.assertEqual(mockPositionInfo['ref_base'], 'TACAC')
variant_caller = VariantCaller()
test_one_snv_one_insert(variant_caller)
test_one_insert(variant_caller)
test_two_inserts(variant_caller)
test_one_delete(variant_caller)
test_one_delete_one_snv(variant_caller)
test_one_delete_one_insert(variant_caller)
test_two_deletes(variant_caller)
def suite():
suite = unittest.TestSuite()
suite.addTest(TestPreprocess('test_empty'))
suite.addTest(TestPreprocess('test_normal'))
suite.addTest(TestIndelString('test_normal'))
suite.addTest(TestPileupReader('test_normal'))
suite.addTest(TestVariantCaller('test_normal'))
suite.addTest(TestVariantCaller('test_indels'))
return suite
def main():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == '__main__':
main()