0

考虑以下简单的蛇文件,它尝试在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")

错误是一样的。

发生了什么?

4

1 回答 1

0

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

规则全部:输入:“test.txt”

以下作品:

rule make_test:
    output:
        "test.txt"
    run:
        with open(output[0], "w") as f:
            f.write("test")
于 2016-12-02T17:00:29.733 回答