File: faidx_bench.py

package info (click to toggle)
python-pysam 0.15.4+ds-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 27,992 kB
  • sloc: ansic: 140,738; python: 7,881; sh: 265; makefile: 223; perl: 41
file content (71 lines) | stat: -rw-r--r-- 2,084 bytes parent folder | download | duplicates (3)
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
"""Benchmarking the cfaidx module. Usage::

pytest benchmark/faidx_bench.py
"""
import os
import pysam


from TestUtils import BAM_DATADIR


def iterate_over_fastx(fn, persist=True):
    return len(list(pysam.FastxFile(fn, persist=persist)))


def iterate_over_fastx_as_file(fn):
    with open(fn) as inf:
        return len(inf.read())


def test_fasta_iteration_short_sequences(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(
        BAM_DATADIR, "faidx_ex1.fa"))
    assert result == 3270


def test_fasta_iteration_long_sequences(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(BAM_DATADIR, "ex1.fa"))
    assert result == 2


def test_fasta_iteration_short_sequences_without_persistence(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(
        BAM_DATADIR, "faidx_ex1.fa"), persist=False)
    assert result == 3270


def test_fasta_iteration_long_sequences_without_persistence(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(
        BAM_DATADIR, "ex1.fa"), persist=False)
    assert result == 2


def test_fasta_iteration_short_sequences_as_file(benchmark):
    result = benchmark(iterate_over_fastx_as_file,
                       os.path.join(BAM_DATADIR, "faidx_ex1.fa"))
    assert result == 195399


def test_fasta_iteration_long_sequences_as_file(benchmark):
    result = benchmark(iterate_over_fastx_as_file,
                       os.path.join(BAM_DATADIR, "ex1.fa"))
    assert result == 3225


def test_fastq_iteration_short_sequences(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(
        BAM_DATADIR, "faidx_ex1.fq"))
    assert result == 3270


def test_fastq_iteration_short_sequences_without_persistence(benchmark):
    result = benchmark(iterate_over_fastx, os.path.join(
        BAM_DATADIR, "faidx_ex1.fq"), persist=False)
    assert result == 3270


def test_fastq_iteration_short_sequences_as_file(benchmark):
    result = benchmark(iterate_over_fastx_as_file,
                       os.path.join(BAM_DATADIR, "faidx_ex1.fq"))
    assert result == 320458