为了理解Snakemake,我想将一个传统的 Makefile 示例与 Snakemake 进行比较。有一个很好的介绍页面,其中包含先决条件的教育示例:
# source: http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html
# Declaration of a variable
clothes = coat shoes mobile sweater socks\
trousers shirt pants undershirt
all: $(clothes)
# An explicit rule assigns the commands for several targets
$(clothes):
@echo put on $@; touch $@
# Implicit rules state the prerequisites
coat: shoes mobile sweater
shoes: socks trousers
mobile: trousers
sweater: shirt
trousers: pants shirt
shirt: undershirt
# Additional feature
.PHONY: naked
naked: ; @-rm $(clothes)
我试图把它翻译成一个 Snakemake 文件,见这篇文章的结尾。它有效,但我必须touch
为每篇文章重复该命令。我试图通过区分显式和隐式规则(使用通配符)来复制 make 的方法,但没有成功。有没有比我现在更优雅的方式?
# Snakemake version of http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html#ToC6
CLOTHES = ["coat", "shoes", "mobile", "sweater", "socks", "trousers", "shirt", "pants", "undershirt"]
rule all:
input: CLOTHES
rule coat:
input: "shoes", "mobile", "sweater"
output: "coat"
shell: "touch coat"
rule shoes:
input: "socks", "trousers"
output: "shoes"
shell: "touch shoes"
rule mobile:
input: "trousers"
output: "mobile"
shell: "touch mobile"
rule sweater:
input: "shirt"
output: "sweater"
shell: "touch sweater"
rule trousers:
input: "pants", "shirt"
output: "trousers"
shell: "touch trousers"
rule shirt:
input: "undershirt"
output: "shirt"
shell: "touch shirt"
rule undershirt:
output: "undershirt"
shell: "touch undershirt"
rule pants:
output: "pants"
shell: "touch pants"
rule socks:
output: "socks"
shell: "touch socks"
### Additional feature
rule naked:
run:
for ds in CLOTHES:
shell("rm -f {}".format(ds))