grep: now creating empty views instead of displaying an error when

selecting on an unexisting column/tag
This commit is contained in:
Celine Mercier
2020-06-10 16:57:42 +02:00
parent a17eb445c2
commit 36a8aaa92e

View File

@ -161,8 +161,7 @@ def obi_eval(compiled_expr, loc_env, line):
return obi_eval_result return obi_eval_result
def Filter_generator(options, tax_filter): def Filter_generator(options, tax_filter, i_view):
#taxfilter = taxonomyFilterGenerator(options)
# Initialize conditions # Initialize conditions
predicates = None predicates = None
@ -171,6 +170,9 @@ def Filter_generator(options, tax_filter):
attributes = None attributes = None
if "attributes" in options and len(options["attributes"]) > 0: if "attributes" in options and len(options["attributes"]) > 0:
attributes = options["attributes"] attributes = options["attributes"]
for attribute in attributes:
if attribute not in i_view:
return None
lmax = None lmax = None
if "lmax" in options: if "lmax" in options:
lmax = options["lmax"] lmax = options["lmax"]
@ -196,6 +198,8 @@ def Filter_generator(options, tax_filter):
if "attribute_patterns" in options and len(options["attribute_patterns"]) > 0: if "attribute_patterns" in options and len(options["attribute_patterns"]) > 0:
for p in options["attribute_patterns"]: for p in options["attribute_patterns"]:
attribute, pattern = p.split(":", 1) attribute, pattern = p.split(":", 1)
if attribute not in i_view:
return None
attribute_patterns[tobytes(attribute)] = re.compile(tobytes(pattern)) attribute_patterns[tobytes(attribute)] = re.compile(tobytes(pattern))
def filter(line, loc_env): def filter(line, loc_env):
@ -324,21 +328,29 @@ def run(config):
# Apply filter # Apply filter
tax_filter = Taxonomy_filter_generator(taxo, config["grep"]) tax_filter = Taxonomy_filter_generator(taxo, config["grep"])
filter = Filter_generator(config["grep"], tax_filter) filter = Filter_generator(config["grep"], tax_filter, i_view)
selection = Line_selection(i_view) selection = Line_selection(i_view)
for i in range(len(i_view)):
PyErr_CheckSignals()
pb(i)
line = i_view[i]
loc_env = {"sequence": line, "line": line, "taxonomy": taxo, "obi_eval_result": False} if filter is None and config["grep"]["invert_selection"]: # all sequences are selected: filter is None if no line will be selected because some columns don't exist
for i in range(len(i_view)):
good = filter(line, loc_env) PyErr_CheckSignals()
pb(i)
if good :
selection.append(i) selection.append(i)
pb(i, force=True) elif filter is not None : # filter is None if no line will be selected because some columns don't exist
for i in range(len(i_view)):
PyErr_CheckSignals()
pb(i)
line = i_view[i]
loc_env = {"sequence": line, "line": line, "taxonomy": taxo, "obi_eval_result": False}
good = filter(line, loc_env)
if good :
selection.append(i)
pb(len(i_view), force=True)
print("", file=sys.stderr) print("", file=sys.stderr)
# Create output view with the line selection # Create output view with the line selection