I have some different configurations and I need to get the combination of them all to run a python script
versions = ['lg', 'sm']
start_time = ['0', '1']
end_time = ['2']
What I want is snakemake to do this for me:
python my_script.py -v lg -s 0 -e 2 > lg_0_2.out
python my_script.py -v lg -s 1 -e 2 > lg_1_2.out
python my_script.py -v sm -s 0 -e 2 > sm_0_2.out
python my_script.py -v sm -s 1 -e 2 > sm_1_2.out
but I can't seem to figure out how to do this in snakemake. Any ideas?
Snakemake has an expand()
method that is shorthand for expanding by an outer product, which is the operation you are describing. Typically, this would be accomplished by generating the output file strings as the input
in the first rule (default rule), and then providing a rule (myrule
below) that parses such strings to generate the command you would use to generate the outputs. In code, it would go something like
Snakefile
versions = ['lg', 'sm']
start_time = ['0', '1']
end_time = ['2']
rule all:
input:
expand("{version}_{start}_{end}.out",
version=versions, start=start_time, end=end_time)
rule myrule:
output: "{version,[^_]+}_{start,[0-9]+}_{end,[0-9]+}.out"
shell:
"""
python my_script.py -v {wildcards.version} -s {wildcards.start} -e {wildcards.end} > {output}
"""
Running snakemake
in the directory where this Snakefile
resides would then generate the desired files.