Skip to content

Commit

Permalink
chore: ignore error for invalid rules
Browse files Browse the repository at this point in the history
  • Loading branch information
matinnuhamunada committed Jul 12, 2023
1 parent 9918fa6 commit 765d622
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ custom_resource_dir()

##### Target rules #####

final_outputs = get_final_output(DF_SAMPLES, PEP_PROJECTS, rule_dict_path="workflow/rules.yaml")
final_outputs = get_final_output(DF_SAMPLES, PEP_PROJECTS, rule_dict_path="workflow/rules.yaml", ignore_missing=True)

rule all:
input:
Expand Down
16 changes: 12 additions & 4 deletions workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ print(f"", file=sys.stderr)


def get_project_outputs(
config, PROJECT_IDS, df_samples, rule_dict_path
config, PROJECT_IDS, df_samples, rule_dict_path, ignore_missing=False
):
"""
Generate outputs of a project given a TRUE value in config["rules"]
Expand Down Expand Up @@ -751,13 +751,21 @@ def get_project_outputs(
else:
print(rule_dict.keys(), file=sys.stderr)
value = rule_dict[k]["final_output"]
print(f"WARNING: {k} is not in the rule dictionary", file=sys.stderr)
print(f" - WARNING: {k} is not in the rule dictionary ({rule_dict_path})", file=sys.stderr)
project_dict[k] = value

# get keys from config
opt_rules = config.keys()

# if values are TRUE add output files to rule all
for r in opt_rules:
if r not in project_dict.keys():
print(f" - WARNING: {r} is not in the rule dictionary ({rule_dict_path})", file=sys.stderr)

if ignore_missing:
print(f" - WARNING: ignoring errors in rule_dictionary", file=sys.stderr)
opt_rules = [r for r in opt_rules if r in project_dict.keys()]

final_output = [project_dict[r] for r in opt_rules if config[r]]

if NCBI == []:
Expand All @@ -770,7 +778,7 @@ def get_project_outputs(
return final_output


def get_final_output(df_samples, peppy_objects, rule_dict_path):
def get_final_output(df_samples, peppy_objects, rule_dict_path, ignore_missing=False):
"""
Generate outputs of for all projects
Expand All @@ -786,7 +794,7 @@ def get_final_output(df_samples, peppy_objects, rule_dict_path):
final_output = []
for p in peppy_objects.values():
sys.stderr.write(f" - Getting outputs for project: {p.name}\n")
final_output.extend(get_project_outputs(p.config["rules"], p.name, df_samples, rule_dict_path))
final_output.extend(get_project_outputs(p.config["rules"], p.name, df_samples, rule_dict_path, ignore_missing=ignore_missing))
sys.stderr.write(f" - Ready to generate all outputs.\n\n")
return final_output

Expand Down

0 comments on commit 765d622

Please sign in to comment.