Skip to content

Non file rule parameters

Romain Feron edited this page Nov 20, 2019 · 2 revisions

As we have seen, Snakemake's execution is based around inputs and outputs of each step of the workflow. However, a lot of software relies on additional non-file parameters. Values for these parameters can be hard-coded in the shell command, but it is often preferable to be able to easily change the value of these parameters. The params directive was designed for this purpose: this directive works exactly like input and output, but the values can be of any type (integer, string, list ...). These values can then be accessed in the shell directive.

The following example shows the most basic use of params to specify a parameter:

rule first_step:
    input:
        'data/first_step.tsv'
    output:
        'results/first_step.txt'
    params:
        5
    shell:
        'head -n {params} {input} > {output}'

In practice, this syntax is unexplicit and easily confusing, and parameters should always be named:

rule first_step:
    input:
        'data/first_step.tsv'
    output:
        'results/first_step.txt'
    params:
        lines = 5
    shell:
        'head -n {params.lines} {input} > {output}'

Just like for input and output, you can define several parameters. In this case, do not forget the comma between each entry! It is the source of many unintuitive error messages.

Clone this wiki locally