Snakemake:如何记录由 script 指令执行的 python 脚本?

gre*_*uar 2 snakemake

有没有什么方法可以轻松保存来自snakemake规则使用script指令执行python脚本的日志?该脚本使用的库已经有一些集成的日志记录,我想存储它们的日志。我不想使用shellrun指令,因为在使用 python 脚本时它们都不太舒服。另外,我希望答案会要求对 python 脚本进行最小的更改,主要更改在文件中Snakemake。这是代码示例:

rule correcting_ids:
    input:
        "assembly_{type}/{sample}/{dataset}/final.fasta"
    output:
        "assembly_{type}/{sample}/{dataset}/final.corrected.fasta"
    log:
        "logs/{sample}/correct_{type}_ids_{dataset}.log"
    script:
        "scripts/correcting_ids.py"```
Run Code Online (Sandbox Code Playgroud)

Maa*_*nde 6

您可以将所有 stdout 和 stderr 重定向到日志文件

Python

import sys

with open(snakemake.log[0], "w") as f:
    sys.stderr = sys.stdout = f
    [rest of the script]
Run Code Online (Sandbox Code Playgroud)

:

log <- file(snakemake@log[[1]], open="wt")
sink(log)
[rest of script]
Run Code Online (Sandbox Code Playgroud)