File: pysam_bench.py

package info (click to toggle)
python-pysam 0.10.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,196 kB
  • ctags: 10,087
  • sloc: ansic: 79,627; python: 8,569; sh: 282; makefile: 215; perl: 41
file content (63 lines) | stat: -rw-r--r-- 1,328 bytes parent folder | download | duplicates (4)
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
'''benchmark pysam BAM/SAM access with the samtools commandline tools.

samtools functions are called via the pysam interface to avoid the over-head
of starting additional processes.
'''

import pysam
import timeit 

iterations = 10

def runBenchmark( test, 
                  pysam_way,
                  samtools_way = None):
    print test
    print timeit.repeat( pysam_way, number = iterations, setup="from __main__ import pysam" )
    if samtools_way:
        print timeit.repeat( samtools_way, number = iterations, setup="from __main__ import pysam" )

runBenchmark( "Samfile.fetch",
'''
f = pysam.Samfile( "ex1.bam", "rb" )
results = list(f.fetch())
''',
'''
f = pysam.view( "ex1.bam" )
'''
)

runBenchmark( "Samfile.pileup",
'''
f = pysam.Samfile( "ex1.bam", "rb" )
results = list(f.pileup())
''',
'''
f = pysam.pileup( "ex1.bam" )
''')

runBenchmark( "Samfile.pileup with coverage retrieval",
'''
f = pysam.Samfile( "ex1.bam", "rb" )
results = [ x.n for x in f.pileup() ]
''' )

runBenchmark( "Samfile.pileup with full retrieval",
'''
f = pysam.Samfile( "ex1.bam", "rb" )
results = [ x.pileups for x in f.pileup() ]
''' )

runBenchmark( "Samfile.pileup - many references",
'''
f = pysam.Samfile( "manyrefs.bam", "rb" )
results = [ x.pileups for x in f.pileup() ]
''',
'''
f = pysam.pileup( "manyrefs.bam" )
'''
 )