@@ -47,6 +47,11 @@ class UnsupportedFileReferenceError(UnsupportedFilteringFeatureError):
47
47
feature = "File references"
48
48
49
49
50
+ class UnsupportedSampleFilteringError (UnsupportedFilteringFeatureError ):
51
+ issue = "180"
52
+ feature = "Per-sample filter expressions"
53
+
54
+
50
55
# The parser and evaluation model here are based on the eval_arith example
51
56
# in the pyparsing docs:
52
57
# https://github.com/pyparsing/pyparsing/blob/master/examples/eval_arith.py
@@ -90,6 +95,8 @@ def __init__(self, tokens):
90
95
class Identifier (EvaluationNode ):
91
96
def __init__ (self , mapper , tokens ):
92
97
self .field_name = mapper (tokens [0 ])
98
+ if self .field_name .startswith ("call_" ):
99
+ raise UnsupportedSampleFilteringError ()
93
100
logger .debug (f"Mapped { tokens [0 ]} to { self .field_name } " )
94
101
# TODO add errors for unsupported things like call_ fields etc.
95
102
@@ -103,12 +110,10 @@ def referenced_fields(self):
103
110
return frozenset ([self .field_name ])
104
111
105
112
106
- class IndexedIdentifier (Identifier ):
107
- def __init__ (self , mapper , tokens ):
108
- super ().__init__ (mapper , tokens [0 ])
109
- # Only literal integers are supported as indexes in bcftools
110
- # assert isinstance(self.index, str)
111
- self .index = tokens [0 ][1 ]
113
+ class IndexedIdentifier (EvaluationNode ):
114
+ def __init__ (self , tokens ):
115
+ # The tokens here are the already resolved idenfitier
116
+ # and the index
112
117
raise UnsupportedArraySubscriptError ()
113
118
114
119
@@ -244,9 +249,7 @@ def make_bcftools_filter_parser(all_fields=None, map_vcf_identifiers=True):
244
249
identifier = vcf_identifier .set_parse_action (
245
250
functools .partial (Identifier , name_mapper )
246
251
)
247
- indexed_identifier = indexed_identifier .set_parse_action (
248
- functools .partial (IndexedIdentifier , name_mapper )
249
- )
252
+ indexed_identifier = indexed_identifier .set_parse_action (IndexedIdentifier )
250
253
comp_op = pp .oneOf ("< = == > >= <= !=" )
251
254
filter_expression = pp .infix_notation (
252
255
constant | indexed_identifier | identifier | file_expr ,
0 commit comments