Skip to content

Commit 50fedf9

Browse files
Add some validation tests on bcftools arithmetic
1 parent 2069889 commit 50fedf9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_bcftools_validation.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ def test_vcf_output_with_output_option(tmp_path, args, vcf_file):
162162
r"query -f '[%POS %QUAL\n]' -i'(QUAL > 10 && POS > 100000)'",
163163
"sample.vcf.gz",
164164
),
165+
# Check arithmetic evaluation in filter queries. All these should
166+
# result to POS=112, which exists.
167+
(r"query -f '%POS\n' -i 'POS=(112 + 1)'", "sample.vcf.gz"),
168+
(r"query -f '%POS\n' -i 'POS =(224 / 2)'", "sample.vcf.gz"),
169+
(r"query -f '%POS\n' -i 'POS= (112 * 3) / 3'", "sample.vcf.gz"),
170+
(r"query -f '%POS\n' -i 'POS=(112 * 3 / 3 )'", "sample.vcf.gz"),
171+
(r"query -f '%POS\n' -i 'POS=25 * 4 + 24 / 2'", "sample.vcf.gz"),
172+
(r"query -f '%POS\n' -i 'POS=112 * -1 * -1'", "sample.vcf.gz"),
173+
(r"query -f '%POS\n' -i '-POS=-112'", "sample.vcf.gz"),
165174
],
166175
)
167176
def test_output(tmp_path, args, vcf_name):
@@ -174,6 +183,35 @@ def test_output(tmp_path, args, vcf_name):
174183
assert vcztools_output == bcftools_output
175184

176185

186+
@pytest.mark.parametrize(
187+
"expr",
188+
[
189+
# Check arithmetic evaluation in filter queries. All these should
190+
# result to POS=112, which exists.
191+
"POS=(111 + 1)",
192+
"POS =(224 / 2)",
193+
"POS= (112 * 3) / 3",
194+
"POS=(112 * 3 / 3 )",
195+
"POS=25 * 4 + 24 / 2",
196+
"POS=112 * -1 * -1",
197+
# "-POS=-112",
198+
],
199+
)
200+
def test_query_arithmethic(tmp_path, expr):
201+
202+
args = r"query -f '%POS\n'" + f" -i '{expr}'"
203+
vcf_name = "sample.vcf.gz"
204+
vcf_path = pathlib.Path("tests/data/vcf") / vcf_name
205+
vcz_path = vcz_path_cache(vcf_path)
206+
207+
bcftools_output, _ = run_bcftools(f"{args} {vcf_path}")
208+
vcztools_output, _ = run_vcztools(f"{args} {vcz_path}")
209+
210+
assert vcztools_output == bcftools_output
211+
assert vcztools_output == "112\n"
212+
213+
214+
177215
@pytest.mark.parametrize(
178216
("args", "vcf_name"),
179217
[

0 commit comments

Comments
 (0)