You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Snakemake通配符识别失败求助:依赖关系无法解析

Snakemake依赖关系识别问题

我搞不懂为啥在这个简单示例里Snakemake识别不了依赖关系。我本来以为它能自动识别:main规则的输入是simulation规则生成的,而simulation规则的输入由setup规则生成——这个架构就是为了在simulation层实现并行。

我的Snakefile代码

root_path = 'a'
names = ['A', 'B', 'C']

rule main:
    input:
        "final.result"
    run:
        pass

rule setup:
    output:
        ABC = expand(root_path + "/{name}/prod.abc", name=names)
    run:
        pass

rule simulation:
    input:
        ABC = root_path + "/{name}/prod.abc"
    output:
        "final.result"
    run:
        pass

执行命令

snakemake --dag

返回错误

Building DAG of jobs...
WildcardError in rule simulation in file /Users/klimt/test/Snakefile, line 19:
Wildcards in input files cannot be determined from output files:
'name'

问题原因

核心问题出在simulation规则的设计:它的输出是单个文件final.result,但输入里带{name}通配符。Snakemake无法从单个输出文件反推出输入里的name通配符取值——因为一个输出文件对应多个可能的输入,Snakemake不知道该用哪个name来匹配。

另外,你的架构逻辑有矛盾:你想让simulation并行处理每个name对应的输入,但当前规则里每个simulation任务都会生成同一个final.result,这会导致任务冲突,而且也没法实现并行后合并结果的逻辑。

解决方法

要实现simulation层并行,需要先让每个并行任务生成独立的输出文件,再通过合并步骤得到最终的final.result。调整后的Snakefile如下:

root_path = 'a'
names = ['A', 'B', 'C']

rule main:
    input:
        "final.result"
    run:
        pass

rule setup:
    output:
        ABC = expand(root_path + "/{name}/prod.abc", name=names)
    run:
        pass

rule simulation:
    input:
        ABC = root_path + "/{name}/prod.abc"
    output:
        root_path + "/{name}/sim.result"  # 每个name对应独立输出
    run:
        # 这里写单个simulation的逻辑,比如处理prod.abc生成sim.result
        pass

rule merge_simulations:
    input:
        expand(root_path + "/{name}/sim.result", name=names)
    output:
        "final.result"
    run:
        # 这里写合并所有sim.result到final.result的逻辑
        pass

调整说明

  1. simulation规则现在为每个name生成独立的sim.result文件,通配符{name}可以从输出文件中确定,Snakemake能正确匹配到setup生成的对应输入文件,同时可以并行执行3个simulation任务。
  2. 新增merge_simulations规则,负责收集所有并行任务的结果,合并生成最终的final.result,这样main规则的输入就能正确关联到合并后的结果。

执行调整后的代码,再运行snakemake --dag就能正常生成依赖图了。


内容的提问来源于stack exchange,提问作者Alejandro Martinez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 23:10:14