Snakemake使用检查点结束工作流



这个问题与我之前发布的Snakemake在执行过程中退出规则有关。基本上,对于我的工作流来说,可能会在其中一个规则中生成一个空文件,我想退出工作流并返回一条有用的消息。有人建议使用检查点功能,下面是我的:

def readFile(file):
with open(file) as f:
line = f.readline()
return(line.strip())
def isFileEmpty():
with checkpoints.step1.output[0].open() as f:
line = f.readline()
if line.strip() != '':
return "output/final.txt"
else:
return "out.txt"
rule all:
input: isFileEmpty()
checkpoint step1:
input: "input.txt"
output: "out.txt"
run:
if readFile(input[0]) == 'a':
shell("echo 'a' > out.txt")
else:
shell("echo '' > out.txt")
print("Out.txt is empty")
rule step2:
input: "out.txt"
output: "output/out2.txt"
run:
shell("echo 'out2' > output/out2.txt")

rule step3:
input: "output/out2.txt"
output: "output/final.txt"
run: shell("echo 'final' > output/final.txt")

在检查点步骤1中,我正在读取input.txt的文件内容,如果不包含字母"a",则会生成一个空的out.txt。如果out.txt不为空,则执行第2步和第3步,最后给出out/out2.txt和out/final.txt。如果它为空,则工作流应在检查点步骤1结束,只生成out.txt。现在,当我运行工作流时,会出现以下错误:

AttributeError in line 7 of Snakefile:
'Checkpoints' object has no attribute 'step1'

我的checkpoints.step1.output[0].open((语法错误吗?在checkpoint文档中,它被写为checkpoints.somestep.get(sample=通配符.sample(.output[0],但我的snakemake输出中没有任何通配符。任何建议都很好。

谢谢!

我终于开始工作了,只对语法进行了一些小的修改:

def readFile(file):
with open(file) as f:
line = f.readline()
return(line.strip())
def isFileEmpty(wildcards):
with checkpoints.step1.get(**wildcards).output[0].open() as f:
line = f.readline()
if line.strip() != '':
return "output/final.txt"
else:
return "out.txt"
rule all:
input: isFileEmpty
checkpoint step1:
input: "input.txt"
output: "out.txt"
run:
if readFile(input[0]) == 'a':
shell("echo 'a' > out.txt")
else:
shell("echo '' > out.txt")
print("Out.txt is empty")
rule step2:
input: "out.txt"
output: "output/out2.txt"
run:
shell("echo 'out2' > output/out2.txt")

rule step3:
input: "output/out2.txt"
output: "output/final.txt"
run: shell("echo 'final' > output/final.txt")

最新更新