小编fei*_*ldt的帖子

如何在 Snakemake 中将 stderr 和 stdout 重定向全局设置到日志文件中?

我正在使用 Snakemake 来构建工作流程。我希望所有规则的 stderr 和 stdout 默认情况下分别重定向到文件logs/{rule}/{wildcards}.o 和logs/{rule}/{wildcards}.e 中。我怎样才能实现这个目标?

以下代码通过添加给定规则的 shell 命令来完成我想要的操作。但是,我不想将其添加到每个规则中。我尝试使用 shell.prefix(...),它为每个规则添加命令前缀,但我找不到访问规则名称或规则通配符的方法。

SAMPLES = ['A', 'B']

rule all:
    input:
        expand('test.{sample}',sample=SAMPLES)

rule test_rule:
    output: 'test.{sample}'
    shell:
        #These three lines need to be prepended for logging.
        'mkdir -p logs/{rule}; '
        'exec 2> logs/{rule}/{wildcards}.e; '
        'exec 1> logs/{rule}/{wildcards}.o; '
        #This is the actual code for the rule
        'touch {output}; '
        'echo "test for {wildcards.sample} created";'
        ' >&2 echo "error message"'
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了logs/{rule}/{wildcards}.o/e中带有stdout和stderr的日志文件的预期结果,但我想全局设置它而不是每个规则。

snakemake

5
推荐指数
1
解决办法
778
查看次数

标签 统计

snakemake ×1