Skip to content

Commit f25bfe2

Browse files
tomwhitejeromekelleher
authored andcommitted
Add more error types for unsupported features
1 parent 3c6a7ce commit f25bfe2

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

tests/test_filter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def test_invalid_expressions(self, parser, expression):
3535
# generic string issue. Can fix this later when we've gotten
3636
# some partial string handling implemented
3737
("INFO/HAYSTACK ~ 0", filter_mod.UnsupportedRegexError),
38-
('CHROM="1"', filter_mod.UnsupportedStringsError),
39-
('FILTER="PASS"', filter_mod.UnsupportedStringsError),
38+
('CHROM="1"', filter_mod.UnsupportedChromFieldError),
39+
('DP="."', filter_mod.UnsupportedMissingDataError),
40+
('FILTER="PASS"', filter_mod.UnsupportedFilterFieldError),
4041
("ID!=@~/file", filter_mod.UnsupportedFileReferenceError),
4142
("INFO/TAG=@file", filter_mod.UnsupportedFileReferenceError),
4243
("INFO/X[0] == 1", filter_mod.UnsupportedArraySubscriptError),

vcztools/filter.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,46 @@ def __init__(self):
2727
)
2828

2929

30-
class UnsupportedRegexError(UnsupportedFilteringFeatureError):
31-
issue = "174"
32-
feature = "Regular expressions"
30+
class UnsupportedMissingDataError(UnsupportedFilteringFeatureError):
31+
issue = "163"
32+
feature = "Missing data"
33+
34+
35+
class UnsupportedFilterFieldError(UnsupportedFilteringFeatureError):
36+
issue = "164"
37+
feature = "FILTER field"
38+
39+
40+
class UnsupportedGenotypeValuesError(UnsupportedFilteringFeatureError):
41+
issue = "165"
42+
feature = "Genotype values"
3343

3444

3545
class UnsupportedArraySubscriptError(UnsupportedFilteringFeatureError):
3646
issue = "167"
3747
feature = "Array subscripts"
3848

3949

40-
class UnsupportedStringsError(UnsupportedFilteringFeatureError):
41-
issue = "189"
42-
feature = "String values temporarily removed"
50+
class UnsupportedRegexError(UnsupportedFilteringFeatureError):
51+
issue = "174"
52+
feature = "Regular expressions"
4353

4454

4555
class UnsupportedFileReferenceError(UnsupportedFilteringFeatureError):
4656
issue = "175"
4757
feature = "File references"
4858

4959

60+
class UnsupportedChromFieldError(UnsupportedFilteringFeatureError):
61+
issue = "178"
62+
feature = "CHROM field"
63+
64+
65+
class UnsupportedStringsError(UnsupportedFilteringFeatureError):
66+
issue = "189"
67+
feature = "String values temporarily removed"
68+
69+
5070
class UnsupportedFunctionsError(UnsupportedFilteringFeatureError):
5171
issue = "190"
5272
feature = "Function evaluation"
@@ -89,7 +109,11 @@ class Number(Constant):
89109

90110
class String(Constant):
91111
def __init__(self, tokens):
92-
raise UnsupportedStringsError()
112+
super().__init__(tokens)
113+
if self.tokens == ".":
114+
raise UnsupportedMissingDataError()
115+
else:
116+
raise UnsupportedStringsError()
93117

94118

95119
class FileReference(Constant):
@@ -104,8 +128,15 @@ def __init__(self, tokens):
104128

105129
class Identifier(EvaluationNode):
106130
def __init__(self, mapper, tokens):
107-
self.field_name = mapper(tokens[0])
108-
logger.debug(f"Mapped {tokens[0]} to {self.field_name}")
131+
token = tokens[0]
132+
if token == "CHROM":
133+
raise UnsupportedChromFieldError()
134+
elif token == "FILTER":
135+
raise UnsupportedFilterFieldError()
136+
elif token == "GT":
137+
raise UnsupportedGenotypeValuesError()
138+
self.field_name = mapper(token)
139+
logger.debug(f"Mapped {token} to {self.field_name}")
109140

110141
def eval(self, data):
111142
value = np.asarray(data[self.field_name])

0 commit comments

Comments
 (0)