Debian Codegraph @

tests/faidx_bench.py

raw symbols SCIP
1 """Benchmarking the cfaidx module. Usage::
2
3 pytest benchmark/faidx_bench.py
4 """
5 import os
6 import pysam
7
8
9 from TestUtils import BAM_DATADIR
10
11
12 def iterate_over_fastx(fn, persist=True):
13 return len(list(pysam.FastxFile(fn, persist=persist)))
14
15
16 def iterate_over_fastx_as_file(fn):
17 with open(fn) as inf:
18 return len(inf.read())
19
20
21 def test_fasta_iteration_short_sequences(benchmark):
22 result = benchmark(iterate_over_fastx, os.path.join(
23 BAM_DATADIR, "faidx_ex1.fa"))
24 assert result == 3270
25
26
27 def test_fasta_iteration_long_sequences(benchmark):
28 result = benchmark(iterate_over_fastx, os.path.join(BAM_DATADIR, "ex1.fa"))
29 assert result == 2
30
31
32 def test_fasta_iteration_short_sequences_without_persistence(benchmark):
33 result = benchmark(iterate_over_fastx, os.path.join(
34 BAM_DATADIR, "faidx_ex1.fa"), persist=False)
35 assert result == 3270
36
37
38 def test_fasta_iteration_long_sequences_without_persistence(benchmark):
39 result = benchmark(iterate_over_fastx, os.path.join(
40 BAM_DATADIR, "ex1.fa"), persist=False)
41 assert result == 2
42
43
44 def test_fasta_iteration_short_sequences_as_file(benchmark):
45 result = benchmark(iterate_over_fastx_as_file,
46 os.path.join(BAM_DATADIR, "faidx_ex1.fa"))
47 assert result == 195399
48
49
50 def test_fasta_iteration_long_sequences_as_file(benchmark):
51 result = benchmark(iterate_over_fastx_as_file,
52 os.path.join(BAM_DATADIR, "ex1.fa"))
53 assert result == 3225
54
55
56 def test_fastq_iteration_short_sequences(benchmark):
57 result = benchmark(iterate_over_fastx, os.path.join(
58 BAM_DATADIR, "faidx_ex1.fq"))
59 assert result == 3270
60
61
62 def test_fastq_iteration_short_sequences_without_persistence(benchmark):
63 result = benchmark(iterate_over_fastx, os.path.join(
64 BAM_DATADIR, "faidx_ex1.fq"), persist=False)
65 assert result == 3270
66
67
68 def test_fastq_iteration_short_sequences_as_file(benchmark):
69 result = benchmark(iterate_over_fastx_as_file,
70 os.path.join(BAM_DATADIR, "faidx_ex1.fq"))
71 assert result == 320458