【问题标题】:Snakemake: output files in one output directorySnakemake:在一个输出目录中输出文件
【发布时间】:2021-04-21 22:42:18
【问题描述】:

我正在运行的程序只需要指定目录即可保存输出文件。如果我使用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


    【解决方案1】:

    通常,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}
            """
    

    【讨论】:

    • 谢谢,第二个脚本有效。我认为程序会像通常那样生成目录本身。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2022-12-17
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    相关资源
    最近更新 更多