Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wildcards in params

Tags:

snakemake

Is it possible to use wildcards when defining parameters using config.yaml files in snakemake? I use a general R script to make the same basic heatmap but with different input matrices. I'd like to specify the configuration for the heatmap (such as number of K for K-means clustering) for each heatmap from my config.yaml file using wildcards.

For example:

rule heatmap:
    input: {condition}.mat
    output: {condition}.png
    params: clusters=config["heatmap-{condition}"][k]
    log: "logs/results/heatmap-{condition}.log" 

So that way I can define the number of k as 20 in my config.yaml file like this when {condition} = "development":

heatmap-development:
  k:
    - 20

Right now I get a KeyError for '{condition}'. Any help would be appreciated, thanks so much

like image 245
Asymptomatic Avatar asked Mar 19 '18 20:03

Asymptomatic


1 Answers

You need to use a function in the params directive for it to know the wildcards.

rule heatmap:
        input: {condition}.mat
        output: {condition}.png
        params: clusters = lambda w: config["heatmap-{}".format(w.condition)][k]
        log: "logs/results/heatmap-{condition}.log"

Read more here: http://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#non-file-parameters-for-rules

like image 76
The Unfun Cat Avatar answered Sep 27 '22 23:09

The Unfun Cat