我希望即使在某些规则失败的情况下,我的snakemake工作流也能继续运行。
例如,我正在使用各种工具来执行ChIP-seq数据的峰值调用。但是,当某些程序不能识别峰值时,它们会发出错误。我更喜欢在这种情况下创建一个空的输出文件,而不是让snakemake失败(就像一些峰值调用者已经做的那样)。
有没有一种使用"shell“和"run”关键字的类似蛇的方式来处理这种情况?
谢谢
发布于 2017-08-11 00:47:50
对于shell命令,您始终可以利用条件"or“、||
rule some_rule:
output:
"outfile"
shell:
"""
command_that_errors || true
"""
# or...
rule some_rule:
output:
"outfile"
run:
shell("command_that_errors || true")通常,退出代码为零(0)表示成功,任何非零都表示失败。包含|| true可确保在命令以非零退出代码退出时成功退出(true始终返回0)。
如果您需要允许特定的非零退出代码,您可以使用shell或Python来检查代码。对于Python,它将类似于以下内容。由于使用了shlex.split()模块,因此外壳命令不需要作为参数数组传递。
import shlex
rule some_rule:
output:
"outfile"
run:
try:
proc_output = subprocess.check_output(shlex.split("command_that_errors {output}"), shell=True)
# an exception is raised by check_output() for non-zero exit codes (usually returned to indicate failure)
except subprocess.CalledProcessError as exc:
if exc.returncode == 2: # 2 is an allowed exit code
# this exit code is OK
pass
else:
# for all others, re-raise the exception
raise在shell脚本中:
rule some_rule:
output:
"outfile"
run:
shell("command_that_errors {output} || rc=$?; if [[ $rc == 2 ]]; then exit 0; else exit $?; fi")https://stackoverflow.com/questions/45613881
复制相似问题