Rule template system

Create issue
Issue #1104 new
Travis Wrightsman created an issue

It would be nice if Snakemake supported a form of rule templating where I can define common patterns for things like benchmark, log, and conda environment paths.

For my workflows I seem to always type out rules with this boilerplate:

rule my_rule:
  """ my rule does things """
  conda:
    "../envs/my_rule.yaml"
  log:
    stdout = "logs/my_rule.{wildcards}.out",
    stderr = "logs/my_rule.{wildcards}.err"
  benchmark:
    "benchmarks/my_rule.{wildcards}.txt"
  shell:
    "mycommand 2> {logs.stderr} > {logs.stdout}"

This is highly related to #491 and I think could be augmented by #877 and #1068.

For example, one could image a general rule template like so (although maybe users could define multiple templates?):

template _default:
  """ description for {rule.name} """
  conda:
    "../envs/{rule.name}.yaml"
  log:
    stdout = "logs/{rule.name}.{wildcards}.out",
    stderr = "logs/{rule.name}.{wildcards}.err"
  benchmark:
    "benchmarks/{rule.name}.{wildcards}.txt"

Maybe a default template could be defined in a Snakefile and a template: rule parameter could override this to no template or a new template.

Additionally, any rule parameters set (e.g. benchmark:) in a rule following a template could be overridden or merged (e.g. rule has extra rule-specific log file paths but still wants the default stdout/stderr paths) if desired.

I also recognize that this is purely a convenience thing and is just a way to reduce boilerplate in large pipelines.

Comments (1)

  1. Christian Arnold

    I think something like this would be very good indeed, I also find that snakefiles contain a lot of repeated code that can be reduced by a templating system.

  2. Log in to comment