| 1 |
"""Benchmarking module for AlignmentFile functionality""" |
| 2 |
import pytest |
| 3 |
|
| 4 |
|
| 5 |
from VariantFileFetchTestUtils import * |
| 6 |
|
| 7 |
|
| 8 |
GENOMES_URL = "ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr{chrom}.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz" |
| 9 |
|
| 10 |
CHROM = 22 |
| 11 |
|
| 12 |
|
| 13 |
@pytest.fixture |
| 14 |
def genomes_data(): |
| 15 |
url = GENOMES_URL.format(chrom=CHROM) |
| 16 |
fn = os.path.basename(url) |
| 17 |
print(fn) |
| 18 |
if not os.path.exists(fn): |
| 19 |
os.system("wget {}".format(url)) |
| 20 |
if not os.path.exists(fn + ".tbi"): |
| 21 |
os.system("wget {}".format(url + ".tbi")) |
| 22 |
|
| 23 |
fn_small = "small.vcf.gz" |
| 24 |
if not os.path.exists(fn_small): |
| 25 |
os.system("bcftools view {} | head -n 10000 | bgzip > {}".format(fn, fn_small)) |
| 26 |
os.system("tabix -f -p vcf {}".format(fn_small)) |
| 27 |
|
| 28 |
return fn_small |
| 29 |
|
| 30 |
|
| 31 |
@pytest.mark.benchmark(min_rounds=1) |
| 32 |
def test_build_filter_from_vcf_with_bcftoolsshell(benchmark, genomes_data): |
| 33 |
result = benchmark(build_filter_from_vcf_with_samtoolsshell, genomes_data) |
| 34 |
assert result == 9120 |
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.benchmark(min_rounds=1) |
| 38 |
def test_build_filter_from_vcf_with_bcftoolpipe(benchmark, genomes_data): |
| 39 |
result = benchmark(build_filter_from_vcf_with_bcftoolspipe, genomes_data) |
| 40 |
assert result == 9120 |
| 41 |
|
| 42 |
|
| 43 |
@pytest.mark.benchmark(min_rounds=1) |
| 44 |
def test_build_filter_from_vcf_with_cyvcf2(benchmark, genomes_data): |
| 45 |
result = benchmark(build_filter_from_vcf_with_cyvcf2, genomes_data) |
| 46 |
|
| 47 |
assert result == 9114 |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.benchmark(min_rounds=1) |
| 51 |
def test_build_filter_from_vcf_with_pysam(benchmark, genomes_data): |
| 52 |
result = benchmark(build_filter_from_vcf_with_pysam, genomes_data) |
| 53 |
|
| 54 |
assert result == 9114 |
| 55 |
|
| 56 |
|
| 57 |
|