微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决Snakemake:在一个输出目录中输出文件

我正在运行的程序只需要指定目录即可保存输出文件。如果我用 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 会为指定的输出文件创建输出目录。蛇形directory()声明告诉蛇形该目录是输出,因此它留给规则来创建输出目录。

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

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}
        """

(使用 params 定义输出目录而不是在 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}
        """

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。