-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathperformance.py
executable file
·73 lines (56 loc) · 1.83 KB
/
performance.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
#!/usr/bin/env python
from __future__ import print_function, division, absolute_import
import sys
import pstats
import cProfile as profile
import timeit
from pysam import Samfile, Fastafile
sys.path.append('.')
import pysamstats
def do_profiling(fun, end=1000):
samfile = Samfile('fixture/test.bam')
count = 0
f = getattr(pysamstats, fun)
for _ in f(samfile, chrom='Pf3D7_01_v3', start=0, end=end):
count += 1
def do_profiling_withrefseq(fun, end=1000):
samfile = Samfile('fixture/test.bam')
fafile = Fastafile('fixture/ref.fa')
count = 0
f = getattr(pysamstats, fun)
for _ in f(samfile, fafile, chrom='Pf3D7_01_v3', start=0, end=end):
count += 1
stats_types_requiring_fasta = ('variation',
'variation_strand',
'baseq_ext',
'baseq_ext_strand',
'coverage_gc',
'coverage_normed_gc',
'coverage_binned',
'coverage_ext_binned')
fun = sys.argv[1]
if len(sys.argv) > 2:
end = sys.argv[2]
else:
end = 1000
if len(sys.argv) > 3:
number = int(sys.argv[3])
else:
number = 1
if len(sys.argv) > 4:
repeat = int(sys.argv[4])
else:
repeat = 3
if fun in stats_types_requiring_fasta:
cmd = 'do_profiling_withrefseq("stat_%s", %s)' % (fun, end)
else:
cmd = 'do_profiling("stat_%s", %s)' % (fun, end)
prof_fn = '%s.prof' % fun
profile.runctx(cmd, globals(), locals(), prof_fn)
s = pstats.Stats(prof_fn)
s.strip_dirs().sort_stats('time').print_stats()
print(timeit.repeat(cmd,
number=number,
repeat=repeat,
setup='from __main__ import do_profiling, '
'do_profiling_withrefseq'))