@@ -29,7 +29,7 @@ def normalise_info_missingness(info_dict, key):
29
29
return value
30
30
31
31
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 ):
33
33
"""Like :py:func:`numpy.testing.assert_allclose()`, but for VCF files.
34
34
35
35
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):
51
51
assert vcf1 .raw_header == vcf2 .raw_header
52
52
assert vcf1 .samples == vcf2 .samples
53
53
54
+ count = 0
54
55
for v1 , v2 in zip_longest (vcf1 , vcf2 ):
55
56
if v1 is None and v2 is not None :
56
57
raise AssertionError (f"Right contains extra variant: { v2 } " )
57
58
if v1 is not None and v2 is None :
58
59
raise AssertionError (f"Left contains extra variant: { v1 } " )
59
60
61
+ count += 1
62
+
60
63
assert v1 .CHROM == v2 .CHROM , f"CHROM not equal for variants\n { v1 } { v2 } "
61
64
assert v1 .POS == v2 .POS , f"POS not equal for variants\n { v1 } { v2 } "
62
65
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):
127
130
f"variants\n { v1 } { v2 } " ,
128
131
)
129
132
133
+ if not allow_zero_variants :
134
+ assert count > 0 , "No variants in file"
135
+
130
136
131
137
def vcz_path_cache (vcf_path ):
132
138
"""
0 commit comments