我有一个带有高度冗余输出的 Snakemake 规则(此处已简化):
rule redundant:
output:
a_x = "prefix_a_x.ext"
b_x = "prefix_b_x.ext"
a_y = "prefix_a_y.ext"
b_y = "prefix_b_y.ext"
run:
process_1(output.a_x)
process_2(output.a_y)
process_3(output.b_x)
process_4(output.b_y)
我可以以可读性为代价删除冗余:
rule less_readable:
output:
[f"prefix_{a}_{b}.ext"
for a in ["a", "b"]
for b in ["x", "y"]]
run:
process_1(output[0])
process_2(output[1])
process_3(output[2])
process_4(output[3])
(我不想冒险使用
expand("prefix_{a}_{b}.ext", a=["a", "b"], b=["x", "y"])
因为输出的顺序很重要,我担心它可能会改变
在未来的 Snakemake 版本中。)
我想要两全其美,比如:
rule more_readable:
output:
{f"{a}_{b}": f"prefix_{a}_{b}.ext"
for a in ["a", "b"]
for b in ["x", "y"]}
run:
process_1(output.a_x)
process_2(output.a_y)
process_3(output.b_x)
process_4(output.b_y)
可悲的是,这不起作用:
$ snakemake -j 1 prefix_a_x.ext
Building DAG of jobs...
MissingRuleException:
No rule to produce prefix_a_x.ext (if you use input functions make sure that they don't raise unexpected exceptions).
如何为自动生成的目标分配标签?
我用
$ snakemake --version
7.14.2
你最后的片段几乎是正确的,确保使用字典扩展(
**
):
rule more_readable:
output:
**{f"{a}_{b}": f"prefix_{a}_{b}.ext"
for a in ["a", "b"]
for b in ["x", "y"]}