簡體   English   中英

Snakemake 規則日志/基准通配符在檢查點后與輸出通配符不匹配

[英]Snakemake rule log/benchmark wildcards dont match output wildcards after checkpoint

我正在運行一個帶有檢查點的 Snakemake 工作流,在某個點上我收集了以前未知數量的輸出文件。 然后,Snakemake 應該使用下一條規則根據文件編號創建許多任務,使用收集的檢查點文件的某些部分作為該規則通配符的通配符。 一切正常,除非我希望該規則也創建日志和/或基准文件,此時拋出:

SyntaxError:
Not all output, log and benchmark files of rule plasmid_spades contain the same wildcards. This is crucial though, in order to avoid that two or more jobs write to the same file.
  File "/path/to/Snakefile", line N, in <module>

這些是工作流程的相關部分:

WCS = None

...

def gather_checkpoint_output(wildcards):
    ck_output = checkpoints.checkpoint_rule.get(**wildcards).output[0]
    global WCS
    WCS, = glob_wildcards(os.path.join(ck_output, "{wc}", "{wc}.file"))
    return expand(os.path.join(ck_output, "{wc}", "{wc}.file"), wc=WCS)


def gather_some_rule_after_checkpoint_out(wildcards):
    rule_output = checkpoints.checkpoint_rule.get(**wildcards).output[0]
    WCS2, = glob_wildcards(os.path.join(rule_output, "{wc}", "{wc}.file"))
    return expand(os.path.join("some", "{wc}", "path", "output.file"), wc=WCS2)

...

localrules: all
rule all:
    input:
        gather_checkpoint_output,
        gather_some_rule_after_checkpoint_out

...

rule some_rule_after_checkpoint:
    input:
        input = gather_checkpoint_output
    output:
        out_dir = directory(expand(os.path.join("some", "{wc}", "dir"), wc=WCS)),
        output = expand(os.path.join("some", "{wc}", "path", "output.file"), wc=WCS)
    log:
         os.path.join("logs", "some", "path", "{wc}_rule.log")
    benchmark:
         os.path.join("logs", "some", "path", "{wc}_rule_benchmark.tsv")
...

問題是它在開始時評估日志/基准通配符(WCS = None),而輸出將使用檢查點函數重新評估? 雖然,我認為規則通配符是基於輸出通配符的。 我嘗試了 lambda 函數、expand() 等,專門從(希望重新評估的 WCS)獲取日志的通配符,但這顯然是不允許的。 我是否在這里忽略了一些明顯的東西,或者整個結構在某種程度上是錯誤的?

您的問題可能是臭名昭著且非常常見的“錯誤使用擴展”一般問題的化身。

some_rule_after_checkpoint規則中, logbenchmark指令包含通配符,而output指令不包含。 實際上,您需要清楚地知道輸出文件名模式中的通配符被擴展,從而產生一個完全解析的文件名列表。

這讓 Snakemake 感到困惑:如果output文件名中沒有通配符,它​​應該使用什么通配符值來確定logbenchmark文件的名稱? 規則中的通配符值是通過將此規則的輸出文件名模式與下游規則中完全解析的輸入文件名匹配來確定的。

您可能不應該在some_rule_after_checkpoint的輸出中使用expand ,因為擴展已經在all規則的輸入中完成。

對於some_rule_after_checkpoint中的非擴展output文件名模式,規則的擴展輸入中的每個不同文件all將觸發some_rule_after_checkpoint規則的一個實例,通配符的值將根據輸出文件模式之間的模式匹配來確定在some_rule_after_checkpointall . 這個通配符將使 Snakemake 能夠生成相應的logbenchmark文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM