I wish to do be able to write a workflow so that I can choose which optional rules to run in the config.json file. For example if I have a Snakefile with 2 rules, rule_a and rule_b, each with the same input but different outputs:
rule_a:
input: input.txt
output: out_a.txt
run: ...
rule_b:
input: input.txt
output: out_b.txt
run: ...
And I have the following configurations in the json file:
{
"run_a": "T",
"run_b": "F"
}
How do I write the Snakefile so that in this case only rule_a will be run while rule_b will be ignored?
As python can be used in snakemake scripts, you could use python code to identify which files need to be created.
Configfile config.json:
{
"run_a": true,
"run_b": false
}
Snakefile:
configfile: "config.json"
if config['run_a']:
target = 'out_a.txt'
elif config['run_b']:
target = 'out_b.txt'
rule all:
input:
target
rule a:
input: 'input.txt'
output: 'out_a.txt'
shell:
"touch {output}"
rule b:
input: 'input.txt'
output: 'out_b.txt'
shell:
"touch {output}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With