How to express explicit and implicit rules in Snakemake? -


in order understand snakemake, want compare traditional makefile example snakemake. there nice introduction page make educational example prerequisites:

# source: http://www.jfranken.de/homepages/johannes/vortraege/make_inhalt.en.html  # declaration of variable clothes = coat shoes mobile sweater socks\         trousers shirt pants undershirt  all: $(clothes)  # explicit rule assigns commands several targets $(clothes):     @echo put on $@; touch $@  # implicit rules state prerequisites coat:      shoes mobile sweater shoes:     socks trousers mobile:    trousers sweater:   shirt trousers:  pants shirt shirt:     undershirt  # additional feature .phony: naked naked:      ; @-rm $(clothes) 

i tried translate snakemake file, see end of post. works, have repeat touch command every article. tried copy make's approach distinguishung between explicit , implicit rules (using wildcards), didn't succeed. there more elegant way current one?

# 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:         ds in clothes:             shell("rm -f {}".format(ds))  

in snakemake, 1 use input functions , config file varying dependencies, e.g.:

configfile: "config.yaml"   def get_prereqs(wildcards):     """lookup prerequisites in config file."""     # return prereqs list of strings     return config["clothes"][wildcards.type]   # target rule creating desired files rule all:     input:         config["clothes"]   rule clothes:     input:         # refer function called inferred wildcards single argument         get_prereqs     output:         # in general, rule output should more specific in example         "{type}"     shell:         "touch {output}" 

and config.yaml:

clothes:   coat:     - shoes     - mobile     - sweater   shoes:     - socks     - trousers   mobile:     - trousers   sweater:     - shirt   trousers:     - pants     - shirt   shirt:     - undershirt   pants: []   undershirt: []   socks: [] 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -