Using Module in Snakemake. Define a rule after a use rule * from workflow throw an error

Question:

I’m using the version 7.23.1 of Snakemake.
I’m using the modularization in snakemake and I’m getting a strange behavior. I would like to ask for your help in order to understand a bit more in-depth how snakemake works.

I have the following programs:

workflow.smk

rule A:
    input: "init.txt"
    output: "A.txt"
    shell: "touch A.txt"

rule B:
    input: "init.txt"
    output: "B.txt"
    shell: "touch B.txt"

Snakefile

module workflow:
    snakefile:
        "workflow.smk"

use rule * from workflow

rule C:
    input: "A.txt", "B.txt"
    output: "C.txt"
    shell: "touch C.txt"

With this setup, if I’m running snakemake -j1 -F C, I will get the following error:

AttributeError in file /Users/cayssolm/Desktop/snakemake/Snakefile, line 7:
module 'snakemake.workflow' has no attribute 'rule'
  File "/Users/cayssolm/Desktop/snakemake/Snakefile", line 7, in <module>

The only solution I found is to define the rule C before the use rule * from workflow such as :

Snakefile

module workflow:
    snakefile:
        "workflow.smk"

rule C:
    input: "A.txt", "B.txt"
    output: "C.txt"
    shell: "touch C.txt"

use rule * from workflow

With this setup, it works.

Why such a behavior ? Why do we need to define rule C before the use rule * from worfklow statement ?

Thanks in advance for your help!

I would expect that this synthax would work:

Snakefile

module workflow:
    snakefile:
        "workflow.smk"

use rule * from workflow

rule C:
    input: "A.txt", "B.txt"
    output: "C.txt"
    shell: "touch C.txt"
Asked By: Mathieu Cayssol

||

Answers:

This does not appear to be documented explicitly anywhere (yet), but workflow is a reserved name. Changing the module name in Snakefile will lead to an executable file:

module my_workflow:
    snakefile:
        "workflow.smk"

use rule * from my_workflow

rule C:
    input: "A.txt", "B.txt"
    output: "C.txt"
    shell: "touch C.txt"

A relevant documentation note has been added via this PR.

Answered By: SultanOrazbayev