1
votes

I'm starting with snakemake. I managed to define some rules which I can run indepently, but not in a workflow. Maybe the issue is that they have unrelated inputs and outputs.

My current workflow is like this:

configfile: './config.yaml'

rule all:
    input: dynamic("task/{job}/taskOutput.tab")
rule split_input:
     input: "input_fasta/snp.fa"
     output: dynamic("task/{job}/taskInput.fa")
     shell:
     "rm -Rf tasktmp task; \
     mkdir tasktmp task; \
     split -l 200 -d {input} ./tasktmp/; \
     ls tasktmp | awk '{{print \"mkdir task/\"$0}}' | sh; \
     ls tasktmp | awk '{{print \"mv ./tasktmp/\"$0\" ./task/\"$0\"/taskInput.fa\"}}' | sh"
rule task:
     input: "task/{job}/taskInput.fa"
     output: "task/{job}/taskOutput.tab"
     shell: "cp {input} {output}"
rule make_parameter_file:
     output:
    "par/parameters.txt
     shell:
    "rm -Rf par;mkdir par; \
    echo \"\
minimumFlankLength=5\n\
maximumFlankLength=200\n\
alignmentLengthDifference=2\
allowedMismatch=4\n\
allowedProxyMismatch=2\n\
allowedIndel=3\n\
ambiguitiesAsMatch=1\n\" \
    > par/parameters.txt"
rule build_target:
    input:
       "./my_target"
    output:
       touch("build_target.done")
    shell:
       "build_target -template format_nt -source {input} -target my_target"

If I call this as such:

snakemake -p -s snakefile

The first three rules are being executed, the others not.

I can run the last rule by specifying it as an argument.

snakemake -p -s snakefile build_target

But I don't see how I can run all.

Thanks a lot for any suggestion on how to solve this.

1

1 Answers

3
votes

By default snakemake executes only the first rule of a snakefile. Here it is rule all. In order to produce rule all's input dynamic("task/{job}/taskOutput.tab"), it needs to run the following two rules task and split_input, and so it does.

If you want the other rules to be run as well, you should put their output in rule all, eg.:

rule all:
    input: 
        dynamic("task/{job}/taskOutput.tab"),
        "par/parameters.txt",
        "build_target.done"