在 Snakemake 中使用模块。在工作流中的使用规则 * 抛出错误后定义规则

问题描述 投票:0回答:1

我使用的是Snakemake 7.23.1版本。 我在 snakemake 中使用模块化,但出现了奇怪的行为。我想寻求您的帮助,以便更深入地了解 snakemake 的工作原理。

我有以下程序:

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"

有了这个设置,如果我运行

snakemake -j1 -F C
,我会得到以下错误:

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>

我找到的唯一解决方案是在

rule C
之前定义
use rule * from workflow
,例如:

Snakefile

module workflow:
    snakefile:
        "workflow.smk"

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

use rule * from workflow

有了这个设置,就可以了。

为什么会有这样的行为?为什么我们需要在

rule C
语句之前定义
use rule * from worfklow

提前感谢您的帮助!

我希望这个合成器能工作:

Snakefile

module workflow:
    snakefile:
        "workflow.smk"

use rule * from workflow

rule C:
    input: "A.txt", "B.txt"
    output: "C.txt"
    shell: "touch C.txt"
python module attributeerror snakemake modularization
1个回答
0
投票

这似乎没有在任何地方(还)明确记录,但

workflow
是保留名称。在
Snakefile
中更改模块名称将导致可执行文件:

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"

已通过this PR添加了相关文档注释。

© www.soinside.com 2019 - 2024. All rights reserved.