Skip to content

Instantly share code, notes, and snippets.

@jgte
Created August 13, 2020 15:30
Show Gist options
  • Save jgte/5e25022fb4a5ce79873622fac34790f7 to your computer and use it in GitHub Desktop.
Save jgte/5e25022fb4a5ce79873622fac34790f7 to your computer and use it in GitHub Desktop.
snakemake workflow broken by a rule that produces multiple files
shell.prefix('set -eu pipefail; ')
rule clean:
shell: "rm -fr in out pc *lock process.sh"
rule build_process:
output: "process.sh"
shell: """
echo "#!/bin/bash
PROCESS_COUNTER=pc
(
#getting lock
flock 200
#this is the "processing" step
for i in \$@
do
cat \$i | sed 's:0:A:g' > out/\$(basename \${{i/old/new}} )
done
#counting the number of time the processing was called
echo \$(( \$(cat \$PROCESS_COUNTER 2> /dev/null || echo 0)+1 ))> \$PROCESS_COUNTER
) 200>lock
" > {output}
chmod u+x {output}
"""
PAR={
"id_list": range(1,10),
}
rule stage:
output: "in/{id}.old"
shell: "echo $RANDOM > {output}"
def get_all_dat(wildcards):
out=[]
for i in PAR["id_list"]:
dat=rules.stage.output[0].format(id=i)
out.append(dat)
return out
rule stage_all:
input: get_all_dat
output: "in/staged.list"
shell: "for i in {input}; do echo $i; done > {output}"
rule process:
input:
list="in/staged.list",
util="process.sh"
output: "out/{id}.new",
shell: "./{input.util} $(cat {input.list})"
rule plot:
input: "out/{id}.new"
output: "out/{id}.plot"
shell: "echo \"plot of $(cat {input})\" > {output}"
def get_all_plot(wildcards):
out=[]
for i in PAR["id_list"]:
dat=rules.plot.output[0].format(id=i)
out.append(dat)
return out
rule plot_all:
input: get_all_plot
output: "out/plotted.list"
shell: "for i in {input}; do echo $i; done > {output}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment