如何解决AmbiguousRuleException 当没有歧义时
在这个 Snakemake 脚本中,rule all
定义了一个目标,还有其他三个规则将该目标声明为输出:
rule all:
input:
"target.txt"
rule from_non_existing_file:
input:
"non_existing_file.txt"
output:
"target.txt"
rule broad_input:
output:
"target.txt"
rule narrow_input:
input:
"optional_input.txt"
output:
"target.txt"
ruleorder: narrow_input > broad_input
文件non_existing_file.txt 不存在,所以rule from_non_existing_file
不应该被Snakemake 视为。 rule broad_input
没有输入文件,所以它总是可以产生输出,而只要文件 optional_input.txt 存在,rule narrow_input
就可以产生输出。为了解决宽输入和窄输入之间的歧义,定义了规则顺序。
只要文件 optional_input.txt 存在,脚本就会首选 rule narrow_input
:
Job counts:
count jobs
1 all
1 narrow_input
2
这个脚本大部分时间都可以运行,但有时会失败:
AmbiguousRuleException:
Rules narrow_input and broad_input are ambiguous for the file target.txt.
Consider starting rule output with a unique prefix,constrain your wildcards,or use the ruleorder directive.
Wildcards:
narrow_input:
broad_input:
Expected input files:
narrow_input: optional_input.txt
broad_input: Expected output files:
narrow_input: target.txt
broad_input: target.txt
这里 Snakemake 忽略了 ruleorder
指令已定义的事实,并建议重新定义它。
为了确认这种行为,我设计了以下测试脚本:
import os
def test_snakemake():
for i in range(100):
rcode = os.system("snakemake --cores=1 --printshellcmds --forceall --dry-run")
assert(rcode == 0)
此测试在前 20 次迭代中以高置信度失败。
我进行了一些实验并得到了令人惊讶的结果:
- 如果optional_input.txt 不存在,则测试通过
- 如果删除了三个规则中的任何一个,则测试通过
这个问题在两台不同的 Windows 机器上得到了确认,它们的 Snakemake 版本是 5.7.4 和 6.5.3。
我的问题是这是否是 Snakemake 错误。这种行为还有其他解释吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。