@@ -162,6 +162,15 @@ def test_vcf_output_with_output_option(tmp_path, args, vcf_file):
162
162
r"query -f '[%POS %QUAL\n]' -i'(QUAL > 10 && POS > 100000)'" ,
163
163
"sample.vcf.gz" ,
164
164
),
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" ),
165
174
],
166
175
)
167
176
def test_output (tmp_path , args , vcf_name ):
@@ -174,6 +183,35 @@ def test_output(tmp_path, args, vcf_name):
174
183
assert vcztools_output == bcftools_output
175
184
176
185
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
+
177
215
@pytest .mark .parametrize (
178
216
("args" , "vcf_name" ),
179
217
[
0 commit comments