在下标中访问snakemake变量

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

我有一个Snakemake工作流程,其中一个python文件中的函数在另一个python文件中被调用,类似于以下内容:

### Snakefile
rule test:
    input:
        "input.file"
    output:
        "output.file"
    script:
        "test_script.py"

### script.py
from test_subscript import run_test

if __name__ == "__main__":
    input_file = snakemake.input[0]
    run_test()

### subscript.py
def run_test():
    out_file = snakemake.output[0]
    with open(out_file, "w") as f:
        f.write("Test")

[现在,当我执行工作流程时,可以从snakemake.input内部访问script.py变量,但是无法访问snakemake.output中的subscript.py变量。一种解决方法是将所有必需的snakemake变量传递给run_test()函数,但这很快就会变得复杂。

是否有更方便的方法?

python snakemake
1个回答
0
投票
方便的方法是使脚本与Snakemake无关。这些脚本应从任何外壳程序中调用。在这种情况下,您需要提供文件名作为命令行参数:

### Snakefile rule test: input: "input.file" output: "output.file" shell: "test_script.py {input} {output}"

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