Snakemake抱怨它无法在运行指令

时间:2016-12-02 16:09:52

标签: python file snakemake

考虑以下简单的snakefile,它试图在run指令中写入文件:

rule all:
    input:
        "test.txt"

rule make_test:
    output:
        filename = "test.txt"
    run:
        with open(output.filename) as f:
            f.write("test")

运行它会产生以下结果:

Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
    count   jobs
    1   all
    1   make_test
    2
rule make_test:
    output: test.txt
Error in job make_test while creating output file test.txt.
RuleException:
FileNotFoundError in line 10 of /tmp/Snakefile:
[Errno 2] No such file or directory: 'test.txt'
  File "/tmp/Snakefile", line 10, in __rule_make_test
Will exit after finishing currently running jobs.
Exiting because a job execution failed. Look above for error message

我对此FileNotFoundError感到惊讶。显然,我没有找到正确的方法来告诉snakemake这是我希望规则make_test创建的文件。

我还尝试了输出语法的以下修改:

rule all:
    input:
        "test.txt"

rule make_test:
    output:
        "test.txt"
    run:
        with open(output[0]) as f:
            f.write("test")

错误是一样的。

发生了什么?

1 个答案:

答案 0 :(得分:0)

我找到了错误的原因:我只是忘了以写模式打开文件:

统治所有:     输入:         "的test.txt"

以下作品:

rule make_test:
    output:
        "test.txt"
    run:
        with open(output[0], "w") as f:
            f.write("test")