5

In snakemake I would like to access keys from the config from within the shell: directive. I can use {input.foo}, {output.bar}, and {params.baz}, but {config.quux} is not supported. Is there a way to achieve this?

rule do_something:
    input: "source.txt"
    output: "target.txt"
    params:
        # access config[] here. parameter tracking is a side effect
        tmpdir = config['tmpdir']
    shell:
        # using {config.tmpdir} or {config['tmpdir']} here breaks the build
        "./scripts/do.sh --tmpdir {params.tmpdir} {input} > {output}; "

I could assign the parts of the config I want to a key under params, and then use a {param.x} replacement, but this has unwanted side effects (e.g. the parameter is saved in the snakemake metadata (i.e. .snakemake/params_tracking). Using run: instead of shell: would be another workaround, but accessing {config.tmpdir} directly from the shell block, would be most desirable.

init_js
  • 4,143
  • 2
  • 23
  • 53

1 Answers1

4

"./scripts/do.sh --tmpdir {config[tmpdir]} {input} > {output}; "

should work here.

It is stated in the documentation: http://snakemake.readthedocs.io/en/stable/snakefiles/configuration.html#standard-configuration

"For adding config placeholders into a shell command, Python string formatting syntax requires you to leave out the quotes around the key name, like so:"

shell:
    "mycommand {config[foo]} ..."
Eric C.
  • 3,310
  • 2
  • 22
  • 29
  • 1
    Baaah. *sigh*. missed that little documentation blurb . Thanks! I don't particularly like the asymmetry between `{params.foo}` and `{config[foo]}`, but at least there's a way. – init_js Mar 07 '18 at 19:09