Skip to content

Commit 405c08d

Browse files
tomwhitejeromekelleher
authored andcommitted
Ensure VCFs are not empty when comparing with bcftools
1 parent 428a1f1 commit 405c08d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def normalise_info_missingness(info_dict, key):
2929
return value
3030

3131

32-
def assert_vcfs_close(f1, f2, *, rtol=1e-05, atol=1e-03):
32+
def assert_vcfs_close(f1, f2, *, rtol=1e-05, atol=1e-03, allow_zero_variants=False):
3333
"""Like :py:func:`numpy.testing.assert_allclose()`, but for VCF files.
3434
3535
Raises an `AssertionError` if two VCF files are not equal to one another.
@@ -51,12 +51,15 @@ def assert_vcfs_close(f1, f2, *, rtol=1e-05, atol=1e-03):
5151
assert vcf1.raw_header == vcf2.raw_header
5252
assert vcf1.samples == vcf2.samples
5353

54+
count = 0
5455
for v1, v2 in zip_longest(vcf1, vcf2):
5556
if v1 is None and v2 is not None:
5657
raise AssertionError(f"Right contains extra variant: {v2}")
5758
if v1 is not None and v2 is None:
5859
raise AssertionError(f"Left contains extra variant: {v1}")
5960

61+
count += 1
62+
6063
assert v1.CHROM == v2.CHROM, f"CHROM not equal for variants\n{v1}{v2}"
6164
assert v1.POS == v2.POS, f"POS not equal for variants\n{v1}{v2}"
6265
assert v1.ID == v2.ID, f"ID not equal for variants\n{v1}{v2}"
@@ -127,6 +130,9 @@ def assert_vcfs_close(f1, f2, *, rtol=1e-05, atol=1e-03):
127130
f"variants\n{v1}{v2}",
128131
)
129132

133+
if not allow_zero_variants:
134+
assert count > 0, "No variants in file"
135+
130136

131137
def vcz_path_cache(vcf_path):
132138
"""

0 commit comments

Comments
 (0)