2
在snakemake中,推荐使用shell()函数执行多个命令的方式是什么?推荐使用shell执行多个shell命令的方法()
在snakemake中,推荐使用shell()函数执行多个命令的方式是什么?推荐使用shell执行多个shell命令的方法()
您可以在规则的run
块内调用shell()
多次(规则可以指定run:
而非shell:
):
rule processing_step:
input:
# [...]
output:
# [...]
run:
shell("somecommand {input} > tempfile")
shell("othercommand tempfile {output}")
否则,由于运行块接受Python代码,你可以建立一个列表命令字符串和遍历他们:
rule processing_step:
input:
# [...]
output:
# [...]
run:
commands = [
"somecommand {input} > tempfile",
"othercommand tempfile {output}"
]
for c in commands:
shell(c)
如果没有规则的执行过程中需要Python代码,你可以在中使用三引号字符串块,然后像在shell脚本中那样编写命令。这可以说是最可读纯壳规则:
rule processing_step:
input:
# [...]
output:
# [...]
shell:
"""
somecommand {input} > tempfile
othercommand tempfile {output}
"""
如果壳命令取决于成功/前面的命令的故障时,它们可以与通常的外壳脚本运营商如||
和&&
接合:
rule processing_step:
input:
# [...]
output:
# [...]
shell:
"command_one && echo 'command_one worked' || echo 'command_one failed'"
好,谢谢。人们在网站上展示这些例子会很有用。 – tedtoal