| 1 |
"""Benchmarking module for AlignmentFile functionality""" |
| 2 |
from TestUtils import BAM_DATADIR, flatten_nested_list |
| 3 |
from PileupTestUtils import * |
| 4 |
|
| 5 |
|
| 6 |
def test_build_pileup_from_bam_with_samtoolsshell(benchmark): |
| 7 |
result = benchmark(build_pileup_with_samtoolsshell, |
| 8 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 9 |
assert result == 2998 |
| 10 |
|
| 11 |
|
| 12 |
def test_build_pileup_from_bam_with_samtoolspipe(benchmark): |
| 13 |
result = benchmark(build_pileup_with_samtoolspipe, |
| 14 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 15 |
assert result == 2998 |
| 16 |
|
| 17 |
|
| 18 |
def test_build_pileup_from_bam_with_pysam(benchmark): |
| 19 |
result = benchmark(build_pileup_with_pysam, |
| 20 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 21 |
assert result == 2998 |
| 22 |
|
| 23 |
|
| 24 |
def test_build_depth_from_bam_with_samtoolsshell(benchmark): |
| 25 |
result = benchmark(build_depth_with_samtoolsshell, |
| 26 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 27 |
assert result == 107241 |
| 28 |
|
| 29 |
|
| 30 |
def test_build_depth_from_bam_with_samtoolspipe(benchmark): |
| 31 |
result = benchmark(build_depth_with_samtoolspipe, |
| 32 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 33 |
assert sum(result) == 107241 |
| 34 |
|
| 35 |
|
| 36 |
def test_build_depth_from_bam_with_pysam(benchmark): |
| 37 |
result = benchmark(build_depth_with_pysam, |
| 38 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 39 |
|
| 40 |
|
| 41 |
assert sum(result) == 110015 |
| 42 |
|
| 43 |
|
| 44 |
def test_build_depth_with_filter_from_bam_with_pysam(benchmark): |
| 45 |
result = benchmark(build_depth_with_filter_with_pysam, |
| 46 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 47 |
assert sum(result) == 107241 |
| 48 |
|
| 49 |
|
| 50 |
def test_build_query_bases_from_bam_with_samtoolsshell(benchmark): |
| 51 |
result = benchmark(build_query_bases_with_samtoolsshell, |
| 52 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 53 |
assert result == 116308 |
| 54 |
|
| 55 |
|
| 56 |
def test_build_query_bases_from_bam_with_samtoolspysam(benchmark): |
| 57 |
result = benchmark(build_query_bases_with_samtoolspysam, |
| 58 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 59 |
assert len("".join(flatten_nested_list(result))) == 116308 |
| 60 |
|
| 61 |
|
| 62 |
def test_build_query_bases_from_bam_with_samtoolspipe(benchmark): |
| 63 |
result = benchmark(build_query_bases_with_samtoolspipe, |
| 64 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 65 |
assert len("".join(flatten_nested_list(result))) == 116308 |
| 66 |
|
| 67 |
|
| 68 |
def test_build_query_bases_from_bam_with_pysam_pileups(benchmark): |
| 69 |
|
| 70 |
result = benchmark(build_query_bases_with_pysam_pileups, |
| 71 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 72 |
assert len("".join(flatten_nested_list(result))) == 107241 |
| 73 |
|
| 74 |
|
| 75 |
def test_build_query_bases_from_bam_with_pysam(benchmark): |
| 76 |
result = benchmark(build_query_bases_with_pysam, |
| 77 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 78 |
assert len("".join(flatten_nested_list(result))) == 116308 |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
def test_build_query_bases_with_reference_from_bam_with_samtoolspipe(benchmark): |
| 84 |
result = benchmark(build_query_bases_with_samtoolspipe, |
| 85 |
os.path.join(BAM_DATADIR, "ex2.bam"), |
| 86 |
"-f", os.path.join(BAM_DATADIR, "ex1.fa")) |
| 87 |
assert len("".join(flatten_nested_list(result))) == 115924 |
| 88 |
|
| 89 |
|
| 90 |
def test_build_query_bases_with_reference_from_bam_with_pysam(benchmark): |
| 91 |
with pysam.FastaFile(os.path.join(BAM_DATADIR, "ex1.fa")) as fasta: |
| 92 |
result = benchmark(build_query_bases_with_pysam, |
| 93 |
os.path.join(BAM_DATADIR, "ex2.bam"), |
| 94 |
fastafile=fasta) |
| 95 |
assert len("".join(flatten_nested_list(result))) == 115924 |
| 96 |
|
| 97 |
|
| 98 |
def test_build_query_bases_with_reference_from_bam_with_samtoolspysam(benchmark): |
| 99 |
result = benchmark(build_query_bases_with_samtoolspysam, |
| 100 |
os.path.join(BAM_DATADIR, "ex2.bam"), |
| 101 |
"-f", os.path.join(BAM_DATADIR, "ex1.fa")) |
| 102 |
assert len("".join(flatten_nested_list(result))) == 115924 |
| 103 |
|
| 104 |
|
| 105 |
def test_build_query_qualities_from_bam_with_samtoolspipe(benchmark): |
| 106 |
result = benchmark(build_query_qualities_with_samtoolspipe, |
| 107 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 108 |
assert len("".join(result)) == 107241 |
| 109 |
|
| 110 |
|
| 111 |
def test_build_query_qualities_from_bam_with_pysam(benchmark): |
| 112 |
result = benchmark(build_query_qualities_with_pysam, |
| 113 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 114 |
assert sum([len(x) for x in result]) == 107241 |
| 115 |
|
| 116 |
|
| 117 |
def test_build_query_names_from_bam_with_pysam(benchmark): |
| 118 |
result = benchmark(build_query_names_with_pysam, |
| 119 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 120 |
assert len("".join([x for column in result for x in column])) == 2307343 |
| 121 |
|
| 122 |
|
| 123 |
def test_build_mapping_qualities_from_bam_with_samtoolspipe(benchmark): |
| 124 |
result = benchmark(build_mapping_qualities_with_samtoolspipe, |
| 125 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 126 |
assert len("".join(result)) == 107241 |
| 127 |
|
| 128 |
|
| 129 |
def test_build_mapping_qualities_from_bam_with_pysam(benchmark): |
| 130 |
result = benchmark(build_mapping_qualities_with_pysam, |
| 131 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 132 |
assert sum([len(x) for x in result]) == 107241 |
| 133 |
|
| 134 |
|
| 135 |
def test_build_query_positions_from_bam_with_samtoolspipe(benchmark): |
| 136 |
result = benchmark(build_query_positions_with_samtoolspipe, |
| 137 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 138 |
|
| 139 |
assert sum([sum(x) - len(x) for x in result]) == 1841699 |
| 140 |
|
| 141 |
|
| 142 |
def test_build_query_positions_from_bam_with_pysam(benchmark): |
| 143 |
result = benchmark(build_query_positions_with_pysam, |
| 144 |
os.path.join(BAM_DATADIR, "ex2.bam")) |
| 145 |
assert sum([sum(x) for x in result]) == 1841699 |