Debian Codegraph @

tests/tabix_bench.py

raw symbols SCIP
1 import gzip
2 import os
3 import pysam
4
5 from TestUtils import TABIX_DATADIR
6
7 FN_COMPRESSED = "example.bed.gz"
8 FN_UNCOMPRESSED = "example.bed"
9 FN_LARGE_COMPRESSED = "example_large.bed.gz"
10 FN_LARGE_UNCOMPRESSED = "example_large.bed"
11
12
13 def read_python_compressed(fn):
14 '''iterate through with python.'''
15 with gzip.open(fn, mode="r") as f:
16 return len([x.split(b"\t") for x in f])
17
18
19 def read_python_uncompressed(fn):
20 with open(fn) as f:
21 return len([x.split("\t") for x in f])
22
23
24 def fetch_plain(fn):
25 with pysam.Tabixfile(fn) as f:
26 return len(list(f.fetch()))
27
28
29 def fetch_parsed(fn):
30 with pysam.Tabixfile(fn) as f:
31 return len(list(f.fetch(parser=pysam.asBed())))
32
33
34 def iterate_generic_compressed(fn):
35 with gzip.open(fn) as f:
36 return len(list(pysam.tabix_generic_iterator(f, parser=pysam.asBed())))
37
38
39 def iterate_generic_uncompressed(fn):
40 with open(fn) as f:
41 return len(list(pysam.tabix_generic_iterator(f, parser=pysam.asBed())))
42
43
44 def iterate_parsed_compressed(fn):
45 with gzip.open(fn) as f:
46 return len(list(pysam.tabix_iterator(f, parser=pysam.asBed())))
47
48
49 def iterate_parsed_uncompressed(fn):
50 with open(fn) as f:
51 return len(list(pysam.tabix_iterator(f, parser=pysam.asBed())))
52
53
54 def iterate_file_compressed(fn):
55 with gzip.open(fn) as f:
56 return len(list(pysam.tabix_file_iterator(f, parser=pysam.asBed())))
57
58
59 def iterate_file_uncompressed(fn):
60 with open(fn) as f:
61 return len(list(pysam.tabix_file_iterator(f, parser=pysam.asBed())))
62
63
64 def test_read_python_compressed(benchmark):
65 result = benchmark(read_python_compressed,
66 os.path.join(TABIX_DATADIR, FN_COMPRESSED))
67 assert result == 164
68
69
70 def test_read_python_uncompressed(benchmark):
71 result = benchmark(read_python_uncompressed,
72 os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED))
73 assert result == 164
74
75
76 def test_fetch_plain(benchmark):
77 result = benchmark(fetch_plain, os.path.join(TABIX_DATADIR, FN_COMPRESSED))
78 assert result == 164
79
80
81 def test_fetch_parsed(benchmark):
82 result = benchmark(fetch_parsed, os.path.join(
83 TABIX_DATADIR, FN_COMPRESSED))
84 assert result == 164
85
86
87 def test_iterate_generic_compressed(benchmark):
88 result = benchmark(iterate_generic_compressed,
89 os.path.join(TABIX_DATADIR, FN_COMPRESSED))
90 assert result == 164
91
92
93 def test_iterate_generic_uncompressed(benchmark):
94 result = benchmark(iterate_generic_uncompressed,
95 os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED))
96 assert result == 164
97
98
99 def test_iterate_parsed_compressed(benchmark):
100 result = benchmark(iterate_parsed_compressed,
101 os.path.join(TABIX_DATADIR, FN_COMPRESSED))
102 assert result == 164
103
104
105 def test_iterate_parsed_uncompressed(benchmark):
106 result = benchmark(iterate_parsed_uncompressed,
107 os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED))
108 assert result == 164
109
110
111 def test_iterate_file_compressed(benchmark):
112 result = benchmark(iterate_file_compressed,
113 os.path.join(TABIX_DATADIR, FN_COMPRESSED))
114 assert result == 164
115
116
117 def test_iterate_file_uncompressed(benchmark):
118 result = benchmark(iterate_file_uncompressed,
119 os.path.join(TABIX_DATADIR, FN_UNCOMPRESSED))
120 assert result == 164
121
122
123 def test_read_python_large_compressed(benchmark):
124 result = benchmark(read_python_compressed, os.path.join(
125 TABIX_DATADIR, FN_LARGE_COMPRESSED))
126 assert result == 100000
127
128
129 def test_read_python_large_uncompressed(benchmark):
130 result = benchmark(read_python_uncompressed, os.path.join(
131 TABIX_DATADIR, FN_LARGE_UNCOMPRESSED))
132 assert result == 100000
133
134
135 def test_fetch_plain(benchmark):
136 result = benchmark(fetch_plain, os.path.join(
137 TABIX_DATADIR, FN_LARGE_COMPRESSED))
138 assert result == 100000
139
140
141 def test_fetch_parsed(benchmark):
142 result = benchmark(fetch_parsed, os.path.join(
143 TABIX_DATADIR, FN_LARGE_COMPRESSED))
144 assert result == 100000
145
146
147 def test_iterate_generic_large_compressed(benchmark):
148 result = benchmark(iterate_generic_compressed, os.path.join(
149 TABIX_DATADIR, FN_LARGE_COMPRESSED))
150 assert result == 100000
151
152
153 def test_iterate_generic_large_uncompressed(benchmark):
154 result = benchmark(iterate_generic_uncompressed, os.path.join(
155 TABIX_DATADIR, FN_LARGE_UNCOMPRESSED))
156 assert result == 100000
157
158
159 def test_iterate_parsed_large_compressed(benchmark):
160 result = benchmark(iterate_parsed_compressed, os.path.join(
161 TABIX_DATADIR, FN_LARGE_COMPRESSED))
162 assert result == 100000
163
164
165 def test_iterate_parsed_large_uncompressed(benchmark):
166 result = benchmark(iterate_parsed_uncompressed, os.path.join(
167 TABIX_DATADIR, FN_LARGE_UNCOMPRESSED))
168 assert result == 100000
169
170
171 def test_iterate_file_large_compressed(benchmark):
172 result = benchmark(iterate_file_compressed, os.path.join(
173 TABIX_DATADIR, FN_LARGE_COMPRESSED))
174 assert result == 100000
175
176
177 def test_iterate_file_large_uncompressed(benchmark):
178 result = benchmark(iterate_file_uncompressed, os.path.join(
179 TABIX_DATADIR, FN_LARGE_UNCOMPRESSED))
180 assert result == 100000