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 """
    stdout = "logs/my_rule.{wildcards}.out",
    stderr = "logs/my_rule.{wildcards}.err"
    "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 {} """
    stdout = "logs/{}.{wildcards}.out",
    stderr = "logs/{}.{wildcards}.err"

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