-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
155 lines (104 loc) · 4.38 KB
/
tests.py
File metadata and controls
155 lines (104 loc) · 4.38 KB
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
"""
tests.py
unit tests for CoverageCalculatorPy.py
Aurthor: Christopher Medway
Created: 11th November 2018
Version: 0.0.1
Updated: 11th November 2018
"""
import unittest
import os
from CoverageCalculatorPy import get_avg_depth
from CoverageCalculatorPy import get_gaps
from CoverageCalculatorPy import report_missing_regions
import tabix
class TestCalcCov(unittest.TestCase):
# test calculation of average depth
# instance where entire interval as a depth
def test_avg_depth(self):
if os.path.exists('./tests/test.coverage'):
os.remove('./tests/test.coverage')
filehandel = open("./tests/test.coverage", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
get_avg_depth(filehandel, "1", 115252142, 115252148, "NONE", tb, 180)
filehandel.close()
with open("./tests/test.coverage") as f:
for line in f:
avg_depth = float(line.split("\t")[4])
perc_coverage = float(line.split("\t")[5])
self.assertEqual(avg_depth, 901.0)
self.assertEqual(perc_coverage, 16.7)
# instance where end of interval does not have depth
def test_avg_depth_endofinterval(self):
if os.path.exists('./tests/test.coverage'):
os.remove('./tests/test.coverage')
filehandel = open("./tests/test.coverage", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
get_avg_depth(filehandel, "1", 115258827, 115258834, "NONE", tb, 180)
filehandel.close()
with open("./tests/test.coverage") as f:
for line in f:
avg_depth = float(line.split("\t")[4])
perc_coverage = float(line.split("\t")[5])
self.assertEqual(avg_depth, 119.0)
self.assertEqual(perc_coverage, 28.6)
# instance where start of interval does not have depth
def test_avg_depth_startofinterval(self):
if os.path.exists('./tests/test.coverage'):
os.remove('./tests/test.coverage')
filehandel = open("./tests/test.coverage", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
get_avg_depth(filehandel, "1", 160786640, 160786649, "NONE", tb, 180)
filehandel.close()
with open("./tests/test.coverage") as f:
for line in f:
avg_depth = float(line.split("\t")[4])
perc_coverage = float(line.split("\t")[5])
self.assertEqual(avg_depth, 5455.0)
self.assertEqual(perc_coverage, 33.3)
# test calculation of missing
def test_missing_endofinterval(self):
if os.path.exists('./tests/test.missing'):
os.remove('./tests/test.missing')
filehandel = open("./tests/test.missing", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
report_missing_regions(filehandel, "1", 115258827, 115258834, "NONE", tb)
filehandel.close()
with open("./tests/test.missing") as f:
for line in f:
self.assertEqual(line, "1\t115258829\t115258834\tNONE\n")
# test calculation of gaps
def test_gaps(self):
if os.path.exists('./tests/test.gaps'):
os.remove('./tests/test.gaps')
filehandel = open("./tests/test.gaps", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
get_gaps(filehandel, "1", 115252142, 115252155, "NONE", tb, 180)
filehandel.close()
with open("./tets/test.gaps") as f:
for line in f:
self.assertEqual(line, "1\t115252142\t115252147\n")
# test calculation of gaps
def test_gaps(self):
if os.path.exists('./tests/test.gaps'):
os.remove('./tests/test.gaps')
filehandel = open("./tests/test.gaps", 'a+')
depthfile = "./tests/test.gz"
tb = tabix.open(depthfile)
get_gaps(filehandel, "1", 115252142, 115252155, "NONE", tb, 4910)
filehandel.close()
with open("./tests/test.gaps") as f:
cnt = 1
for line in f:
if cnt == "1":
self.assertEqual(line, "1\t115252142\t115252147\n")
cnt = cnt + 1
if cnt == "2":
self.assertEqual(line, "1\t115252149\t115252155\n")
if __name__ == '__main__':
unittest.main()