Skip to content

Commit

Permalink
Standardize usage of Snakemake's "config" variable
Browse files Browse the repository at this point in the history
Retrieving config that is required should be done using the bracket
syntax.

Retrieving config with .get should always be done with a default value.
  • Loading branch information
victorlin committed Jul 24, 2023
1 parent 8ded562 commit c10fde8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ rule all:

rule rename:
input:
auspice_json=build_dir + f"/{config.get('build_name')}/tree.json",
root_sequence=build_dir + f"/{config.get('build_name')}/tree_root-sequence.json",
auspice_json=build_dir + f"/{config['build_name']}/tree.json",
root_sequence=build_dir + f"/{config['build_name']}/tree_root-sequence.json",
output:
auspice_json=auspice_dir + f"/{config.get('auspice_name','tree')}.json",
root_sequence_json=auspice_dir
Expand All @@ -63,7 +63,7 @@ include: "workflow/snakemake_rules/chores.smk"
include: "workflow/snakemake_rules/core.smk"


if config.get("deploy_url"):
if config.get("deploy_url", False):

include: "workflow/snakemake_rules/nextstrain_automation.smk"

Expand Down
6 changes: 3 additions & 3 deletions ingest/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _get_all_targets(wildcards):
]
)

if config.get("trigger_rebuild"):
if config.get("trigger_rebuild", False):
all_targets.append("data/trigger/rebuild.done")

return all_targets
Expand All @@ -73,7 +73,7 @@ include: "workflow/snakemake_rules/transform.smk"
include: "workflow/snakemake_rules/nextclade.smk"


if config.get("upload"):
if config.get("upload", False):

include: "workflow/snakemake_rules/upload.smk"

Expand All @@ -83,6 +83,6 @@ if send_slack_notifications:
include: "workflow/snakemake_rules/slack_notifications.smk"


if config.get("trigger_rebuild"):
if config.get("trigger_rebuild", False):

include: "workflow/snakemake_rules/trigger_rebuild.smk"
2 changes: 1 addition & 1 deletion workflow/snakemake_rules/chores.smk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rule update_example_data:
sequences="example_data/sequences.fasta",
metadata="example_data/metadata.tsv",
params:
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur filter \
Expand Down
12 changes: 6 additions & 6 deletions workflow/snakemake_rules/core.smk
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rule exclude_bad:
params:
min_date=config["min_date"],
min_length=config["min_length"],
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur filter \
Expand Down Expand Up @@ -81,7 +81,7 @@ rule filter:
group_by=config.get("group_by", "--group-by clade lineage"),
sequences_per_group=config["sequences_per_group"],
other_filters=config.get("filters", ""),
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur filter \
Expand Down Expand Up @@ -236,7 +236,7 @@ rule refine:
clock_std_dev=f"--clock-std-dev {config['clock_std_dev']}"
if "clock_std_dev" in config
else "",
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur refine \
Expand Down Expand Up @@ -312,7 +312,7 @@ rule traits:
params:
columns="country",
sampling_bias_correction=3,
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur traits \
Expand Down Expand Up @@ -444,7 +444,7 @@ rule export:
auspice_json=build_dir + "/{build_name}/raw_tree.json",
root_sequence=build_dir + "/{build_name}/raw_tree_root-sequence.json",
params:
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
shell:
"""
augur export v2 \
Expand All @@ -470,7 +470,7 @@ rule final_strain_name:
auspice_json=build_dir + "/{build_name}/tree.json",
root_sequence=build_dir + "/{build_name}/tree_root-sequence.json",
params:
strain_id=config.get("strain_id_field"),
strain_id=config["strain_id_field"],
display_strain_field=config.get("display_strain_field", "strain"),
shell:
"""
Expand Down

0 comments on commit c10fde8

Please sign in to comment.