Skip to content

Commit cb89ed5

Browse files
Raise an error on file references
1 parent 88809c2 commit cb89ed5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/test_filter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def test_invalid_expressions(self, parser, expression):
3737
("INFO/HAYSTACK ~ 0", filter_mod.UnsupportedRegexError),
3838
('CHROM="1"', filter_mod.UnsupportedStringsError),
3939
('FILTER="PASS"', filter_mod.UnsupportedStringsError),
40+
("ID!=@~/file", filter_mod.UnsupportedFileReferenceError),
41+
("INFO/TAG=@file", filter_mod.UnsupportedFileReferenceError),
4042
("INFO/X[0] == 1", filter_mod.UnsupportedArraySubscriptError),
4143
("INFO/AF[0] > 0.3", filter_mod.UnsupportedArraySubscriptError),
4244
("FORMAT/AD[0:0] > 30", filter_mod.UnsupportedArraySubscriptError),

vcztools/filter.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ class UnsupportedArraySubscriptError(UnsupportedFilteringFeatureError):
3939

4040
class UnsupportedStringsError(UnsupportedFilteringFeatureError):
4141
issue = "189"
42-
feature = "String values currently not supported"
42+
feature = "String values temporarily removed"
43+
44+
45+
class UnsupportedFileReferenceError(UnsupportedFilteringFeatureError):
46+
issue = "175"
47+
feature = "File references"
4348

4449

4550
# The parser and evaluation model here are based on the eval_arith example
@@ -77,6 +82,11 @@ def __init__(self, tokens):
7782
raise UnsupportedStringsError()
7883

7984

85+
class FileReference(Constant):
86+
def __init__(self, tokens):
87+
raise UnsupportedFileReferenceError()
88+
89+
8090
class Identifier(EvaluationNode):
8191
def __init__(self, mapper, tokens):
8292
self.field_name = mapper(tokens[0])
@@ -207,6 +217,10 @@ def make_bcftools_filter_parser(all_fields=None, map_vcf_identifiers=True):
207217
string = pp.QuotedString('"').set_parse_action(String)
208218
constant = number | string
209219

220+
file_expr = (pp.Literal("@") + pp.Word(pp.printables)).set_parse_action(
221+
FileReference
222+
)
223+
210224
identifier = pp.common.identifier()
211225
vcf_prefixes = pp.Literal("INFO/") | pp.Literal("FORMAT/") | pp.Literal("FMT/")
212226
vcf_identifier = pp.Combine(vcf_prefixes + identifier) | identifier
@@ -235,7 +249,7 @@ def make_bcftools_filter_parser(all_fields=None, map_vcf_identifiers=True):
235249
)
236250
comp_op = pp.oneOf("< = == > >= <= !=")
237251
filter_expression = pp.infix_notation(
238-
constant | indexed_identifier | identifier,
252+
constant | indexed_identifier | identifier | file_expr,
239253
[
240254
("-", 1, pp.OpAssoc.RIGHT, UnaryMinus),
241255
(pp.one_of("* /"), 2, pp.OpAssoc.LEFT, BinaryOperator),

0 commit comments

Comments
 (0)