包括子Snakefile并生成其输出

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

问题

问题是,当我将其他子Snakefile include放入主Snakefile中时,将永远不会生成子Snakefile的输出。如果这有帮助,我认为这是在管道中具有可选的“分支”-有时我的客户想要特定分支的输出,而客户则不需要。我希望能够选择何时执行这些可选分支。我的snakemake版本是5.13.0

理想解决方案

我想要include子Snakefile,并生成这些子Snakefile的输出。以下是我的构想:

config.yaml

module2: "yes"

Snakefile(“主” snakefile)

# working dir
workdir: "path/to/dir/test"
configfile: "code/config.yaml"

# core rules. These rules are always run. 
include: "code/head.py"

if config["module2"] == "yes":
    include: "code/module2/Snakefile"

rule all:
    input:
        "data/output_head.txt"

[module2可以例如如果我的客户要求,则生成特定的图形。

[请注意,即使主Snakefile的规则未更改所有输入,我也想生成code/module2/Snakefile子Snakefile的输出。每个文件的内容在下一部分中显示。

我的(错误的)方法

可复制的示例

├── Snakefile
├── code
│   ├── config.yaml
│   ├── head.py
│   └── module2
│       ├── Snakefile
│       └── tail.py
├── data
└── inputs
    └── test_input.txt

Snakefile('master'snakefile创建核心工作流输出)

# working dir
workdir: "path/to/dir/test"
configfile: "code/config.yaml"

# core rules
include: "code/head.py"

# module 2 rules
include: "code/module2/Snakefile"

# core output
rule all:
    input:
        "data/output_head.txt"

test_input.txt

1
2
3
4
5
6
7
8
9
10

code / head.py

rule head:
    input:
        "inputs/test_input.txt"
    output:
        "data/output_head.txt"
    shell:
        "head -3 {input} > {output} " # we expect 1 2 3 in output_head.txt

代码/模块2 /蛇文件('下级'蛇文件创建可选的模块2输出文件)]]

include: "tail.py"

rule all:
    input:
        "data/output_tail.txt"

code / module2 / tail.py

rule tail:
        input:
                "inputs/test_input.txt"
        output:
                "data/output_tail.txt"
        shell:
                "tail -3 {input} > {output} " # we expect 8 9 10 in output_tail.txt

我遇到的实际错误是:

CreateRuleException in line 12 of path/to/dir/test/Snakefile:
The name all is already used by another rule

我相信这是因为子Snakefile的rule all与主Snakefile的rule all冲突。

可复制的示例

最后我查看了Modularization页面,在include下显示:

默认目标规则(通常称为全部规则)不会受到包含的影响。即无论您有多少个包含在第一个规则之上的内容,它始终是Snakefile中的第一个规则。

如果我翻译了此权利,则可以改写为:“将Snakefiles包含到您的主Snakefile中将不会添加新的输出文件,因为这由主Snakefile决定。”

如果是真的,那么如果我没有得到子Snakefiles的输出文件,那又有什么意义呢?

结论

设置条件管道以有条件include子Snakefile并生成其输出文件的最佳方法是什么?也许我在阅读文档时非常错误。如果我是,请启发我。

问题是,当我将其他子Snakefile文件包含到主Snakefile中时,将永远不会生成子Snakefile文件的输出。如果有帮助,我认为这是可选的“ ...

python include snakemake
1个回答
0
投票

不确定这是否是最好的,但这是我的解决方案。在配置中,我让用户指定要包括的“分支”:

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