Snakemake:在一个输出目录中输出文件

Snakemake: output files in one output directory

我正在 运行ning 的程序只需要指定目录即可保存输出文件。如果我 运行 这个和 snakemake 它给我错误:

IOError: [Errno 2] No such file or directory: 'BOB/call_images/chrX_194_1967_BOB_78.rpkm.png'

我的尝试:

rule all:
    input:
        "BOB/call_images/"

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output:
        directory("BOB/call_images/")
    shell:
        """
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {output[0]}
        """

此版本均无效:

output:
     outdir="BOB/call_images/"

正常情况下,snakemake 会为指定的输出文件创建输出目录。 snakemake directory() 声明告诉 snakemake 该目录是输出,因此它留给创建输出目录的规则。

如果您可以预测输出文件的名称(即使您没有在命令行中指定它们),您应该在 output: 字段中告诉 snakemake 输出文件名。例如:

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output:
        "BOB/call_images/chrX_194_1967_BOB_78.rpkm.png"
    params:
        outdir="BOB/call_images"
    shell:
        """
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {params.outdir}
        """

(使用参数定义输出目录而不是在 shell 命令中硬编码的优点是您可以在那里使用通配符)

如果您无法预测输出文件名,那么您必须手动 运行 mkdir -p {output} 作为 shell 命令的第一步。

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output: directory("BOB/call_images")
    shell:
        """
        mkdir -p {output}
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {output}
        """