File: AlignedSegment_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 (30 lines) | stat: -rw-r--r-- 677 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
"""Benchmarking module for AlignedSegment functionality"""
import os
import array
import pysam


from TestUtils import BAM_DATADIR


def set_binary_tag():
    read = pysam.AlignedSegment()
    read.set_tag('FZ', array.array('H', range(1000)))
    return len(read.get_tag('FZ'))


def read_binary_tag(fn):
    with pysam.AlignmentFile(fn) as inf:
        read = next(inf.fetch())
    return len(read.get_tag('FZ'))


def test_set_binary_tag(benchmark):
    result = benchmark(set_binary_tag)
    assert result == 1000


def test_read_binary_tag(benchmark):
    result = benchmark(read_binary_tag, os.path.join(
        BAM_DATADIR, "example_btag.bam"))
    assert result == 260