File: tabix_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 (76 lines) | stat: -rw-r--r-- 2,349 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
64
65
66
67
68
69
70
71
72
73
74
75
76
import gzip
import pysam
import timeit

iterations = 5
repeats = 100
print ("repeats=", repeats, "iterations=", iterations)

fn_compressed = '/tmp/windows_small.bed.gz'
fn_uncompressed = '/tmp/windows_small.bed'

def test_python_compressed():
    '''iterate through with python.'''
    f = gzip.open( fn_compressed)
    l = len( [x.encode().split("\t") for x in f])
 
def test_python_uncompressed():
    '''iterate through with python.'''
    f = open( "windows_small.bed")
    l = len( [x.split("\t") for x in f])
 
def test_fetch_plain():
    """Stupid test function"""
    f = pysam.Tabixfile(fn_compressed)
    l = len( list(f.fetch()) )

def test_fetch_parsed():
    """Stupid test function"""
    f = pysam.Tabixfile(fn_compressed)
    l = len( list(f.fetch( parser = pysam.asBed())) )

def test_iterator_generic_compressed():
    f = gzip.open(fn_compressed)
    l = len( list( pysam.tabix_generic_iterator( f, parser = pysam.asBed() )))

def test_iterator_generic_uncompressed():
    f = open("windows_small.bed")
    l = len( list( pysam.tabix_generic_iterator( f, parser = pysam.asBed() )))

def test_iterator_parsed_compressed():
    f = gzip.open(fn_compressed)
    l = len( list( pysam.tabix_iterator( f, parser = pysam.asBed() )))

def test_iterator_parsed_uncompressed():
    f = open("windows_small.bed")
    l = len( list( pysam.tabix_iterator( f, parser = pysam.asBed() )))

def test_iterator_file_compressed():
    f = gzip.open("windows_small.bed")
    l = len( list( pysam.tabix_file_iterator( f, parser = pysam.asBed() )))

def test_iterator_file_uncompressed():
    f = open("windows_small.bed")
    l = len( list( pysam.tabix_file_iterator( f, parser = pysam.asBed() )))

tests = ( test_python_compressed, 
          test_python_uncompressed, 
          test_fetch_plain, 
          test_fetch_parsed,
          test_iterator_generic_compressed, 
          test_iterator_generic_uncompressed, 
          test_iterator_parsed_compressed,
          test_iterator_parsed_uncompressed,
          test_iterator_file_compressed,
          test_iterator_file_uncompressed )

for repeat in range( repeats ):
    print ("# repeat=", repeat)
    for test in tests:
        try:
            t = timeit.timeit( test, number = iterations )
        except AttributeError:
            continue
        print ("%5.2f\t%s" % (t,str(test)))