首页 > 解决方案 > Snakemake:捕获名称无法更改的输出文件

问题描述

作为我正在构建的 Snakemake 管道的一部分,我必须使用一个不允许我指定输出文件的文件路径或名称的程序。

例如,在工作目录中运行程序时,workdir/它会产生以下输出: workdir/output.txt

我的蛇形规则看起来像这样:

rule NAME:
    input: "path/to/inputfile"
    output: "path/to/outputfile"
    shell: "somecommand {input} {output}"

因此,每次运行规则 NAME 时,我都会output.txt在 snakemake 工作目录中获得一个附加文件,如果规则 NAME 运行多次或并行运行,则该文件将被覆盖。

我知道影子规则,添加shadow: "full"允许我简单地忽略output.txt文件。但是,我想将其保留output.txt并保存在与outputfile. 有没有办法通过影子指令或其他方式实现这一目标?

我还想我可以在前面somecommand加上一个cd命令,但是当将其他规则连接到规则的输出时,我可能会在下游遇到其他问题NAME

标签: snakemake

解决方案


之后直接在外壳部分中直接移动它怎么样(前提是somecommand成功完成)?

rule NAME:
    input: "path/to/inputfile"
    output: "path/to/outputfile"
    params: 
        output_dir = "path/to/output_dir",
    shell: "somecommand {input} {output} && mv output.txt {params.output_dir}/output.txt"

编辑:对于 NAME 的多个并行执行,结合shadow: "full"可以工作:

rule NAME:
    input: "path/to/inputfile"
    output:
        output_file = "path/to/outputfile"
        output_txt = "path/to/output_dir/output.txt"
    shadow: "full"
    shell: "somecommand {input} {output.output_file} && mv output.txt {output.output_txt}"

这应该在其自己的临时目录中运行规则的每次执行,并且通过将移动的 output.txt 指定为输出 Snakemake 应该在规则运行完成后将其移动到真实的输出目录。


推荐阅读