我对snakemake相对来说是个新手,而且我很难适应分散收集的DeepVariant工作流到snakemake规则。
在最初的Snakefile中,我想将第一步分散到集群中。DeepVariant使用*.00001-of-00256.*格式以中间文件格式跟踪碎片号,因此我需要使用字符串格式来提供input、output和shell字段中的碎片号和碎片总数,并在scatter规则的params中以通配符的形式提供碎片编号。expand()函数在gather规则的input字段中正确地生成预期的文件名,但是它无法找到由scatter步骤生成的输入文件路径。
我在下面生成了一个最小的可重复示例,以及运行该示例的输出(为了删除某些路径信息,可以稍加修改)。
N_SHARDS = 8
rule all:
input: "done.txt"
rule scatter:
input: "start.txt"
output: f"test_{{shard:05}}-of-{N_SHARDS:05}.txt"
params:
shard = range(N_SHARDS)
message: "scattering"
shell:
f"echo {{wildcards.shard}} {N_SHARDS} > {{output}}"
rule gather:
input: expand(f"test_{{shard:05}}-of-{N_SHARDS:05}.txt", shard=range(N_SHARDS))
output: touch("done.txt")
shell: "echo gathering"$ touch start.txt
$ snakemake -s example.smk -j 1
Building DAG of jobs...
MissingInputException in line 17 of /redacted/example.smk:
Missing input files for rule gather:
test_00002-of-00008.txt
test_00000-of-00008.txt
test_00006-of-00008.txt
test_00001-of-00008.txt
test_00004-of-00008.txt
test_00005-of-00008.txt
test_00007-of-00008.txt
test_00003-of-00008.txt我已经为其他分散收集的概念建立了非常相似的规则,这些概念不需要外卡的字符串格式,所以这是我唯一能想到的,在这种情况下是不同的。我会感谢你的任何见解!
UPDATE:一个有用的twitter用户注意到,我可以在scatter->output中删除:05,这个规则可以工作。这很好,它恰好解决了我原来的问题,但这只是因为DeepVariant容忍在命令行传递的shard参数的零填充。是否有允许我将格式应用于通配符的解决方案?
发布于 2020-07-14 08:33:12
我就是这样做的:
N_SHARDS = '00008'
shard = ['%05d' % x for x in range(int(N_SHARDS))]
wildcard_constraints:
shard= '|'.join([re.escape(x) for x in shard])
rule all:
input:
"done.txt",
rule scatter:
input:
"start.txt",
output:
"test_{shard}-of-%s.txt" % N_SHARDS,
shell:
r"""
echo {wildcards.shard} %s > {output}"
""" % N_SHARDS
rule gather:
input:
expand('test_{shard}-of-%s.txt' % N_SHARDS, shard= shard),
output:
touch("done.txt")
shell:
"echo gathering"wildcard_constraints位可能是多余的,但是如果我确切地知道通配符将要使用的值,我就会非常自由地使用它。
有一件事:您似乎事先就知道DeepVariant将生成多少碎片(示例中的N_SHARDS = 8)。真的是这样吗?如果不是,我认为您需要使用snakemake的检查点功能。
https://stackoverflow.com/questions/62853063
复制相似问题