| 1 | """Benchmarking module for AlignedSegment functionality""" |
| 2 | import os |
| 3 | import array |
| 4 | import pysam |
| 5 | |
| 6 | |
| 7 | from TestUtils import BAM_DATADIR |
| 8 | |
| 9 | |
| 10 | def set_binary_tag(): |
| 11 | read = pysam.AlignedSegment() |
| 12 | read.set_tag('FZ', array.array('H', range(1000))) |
| 13 | return len(read.get_tag('FZ')) |
| 14 | |
| 15 | |
| 16 | def read_binary_tag(fn): |
| 17 | with pysam.AlignmentFile(fn) as inf: |
| 18 | read = next(inf.fetch()) |
| 19 | return len(read.get_tag('FZ')) |
| 20 | |
| 21 | |
| 22 | def test_set_binary_tag(benchmark): |
| 23 | result = benchmark(set_binary_tag) |
| 24 | assert result == 1000 |
| 25 | |
| 26 | |
| 27 | def test_read_binary_tag(benchmark): |
| 28 | result = benchmark(read_binary_tag, os.path.join( |
| 29 | BAM_DATADIR, "example_btag.bam")) |
| 30 | assert result == 260 |