【发布时间】:2021-09-07 17:13:35
【问题描述】:
我目前正在编写一个看起来像这样的管道(最小示例的代码如下,输入文件只是名称在示例中的 SAMPLES 列表中的空白文件)。
我想要的是,如果样本在前两个步骤之一中失败(最小示例设置为使 sample1 在规则 two 上失败),请继续执行所有后续步骤,就像它没有一样在那里(这意味着它只会在sample2 和sample3 上执行规则gather_and_do_something 和split_final)。
我已经在使用 --keep-going 选项继续独立作业,但我无法定义通用规则的输入并使其忽略位于失败路径中的文件。
SAMPLES = ["sample1", "sample2", "sample3"]
rule all:
input:
expand("{sample}_final", sample=SAMPLES)
rule one:
input:
"{sample}"
output:
"{sample}_ruleOne"
shell:
"touch {output}"
rule two:
input:
rules.one.output
output:
"{sample}_ruleTwo"
run:
if input[0] != 'sample1_ruleOne':
with open(output[0], 'w') as fh:
fh.write(f'written {output[0]}')
rule gather_and_do_something:
input:
expand(rules.two.output, sample=SAMPLES)
output:
'merged'
run:
words = []
for f in input:
with open(f, 'r') as fh:
words.append(next(fh))
if len(input):
with open(output[0], 'w') as fh:
fh.write('\n'.join(words))
rule split_final:
input:
rules.gather_and_do_something.output
output:
'{sample}_final'
shell:
'touch {output}'
我尝试编写一些自定义函数用作输入,但这似乎不起作用...
def get_files(wildcards):
import os
return [f for f in expand(rules.two.output, sample=SAMPLES) if f in os.listdir(os.getcwd())]
rule gather_and_do_something:
input:
unpack(get_files)
output:
'merged'
run:
words = []
for f in input:
with open(f, 'r') as fh:
words.append(next(fh))
if len(input):
with open(output[0], 'w') as fh:
fh.write('\n'.join(words))
【问题讨论】: