4

I have created the following snakemake rule:

rule cutadapt:
    input:
        input
    output:
        output
    log:
        logs
    params:
        "-a 'A{100}' --nextseq-trim=20 -m 20"
    wrapper:
        "0.50.4/bio/cutadapt/se"

and I get the following error message:

Wildcards in params cannot be determined from output files.

Snakemake realizes -a 'A{100}' as a Wildcard due to the {}. I tried to escape the {} by -a 'A{{100}}' but it produces the same error.

Is there any chance to escape the parameter section in a snakemake rule?

Thanks

pat2402
  • 79
  • 7
  • How about escaping using backslash character? ie. `A\{100\}'`? – Manavalan Gajapathy Apr 13 '20 at 19:29
  • Thanks @ManavalanGajapathy. This helps to escape the `{}` for snakemake, but will end up in the final bash call like `cutadapt -a 'A\{100\}' --nextseq-trim=20` resulting in an error. What I need is `cutadapt -a 'A{100}' --nextseq-trim=20` – pat2402 Apr 13 '20 at 20:52
  • Makes sense but I am surprised double braces solution isn't working. It might be helpful be to identify if this is a snakemake wrapper issue. To debug, what happens if you try same params in `shell:` command instead of passing it to a `wrapper:`? – Manavalan Gajapathy Apr 13 '20 at 21:39
  • Thanks, but doesn't work either. Same problem. Only works when i move the arguments from the params section directly into the shell command. Here, double braces work. But I would like to keep it in the params section to keep it more flexible. – pat2402 Apr 14 '20 at 00:21

2 Answers2

3

It appears the fix is a bit ugly (see issue https://bitbucket.org/snakemake/snakemake/issues/584/unable-to-escape-curly-braces-in-params) - I don't know if a better solution has been implemented.

Basically, use a dummy lambda function:

lambda wc: "-a 'A{100}' --nextseq-trim=20 -m 20"
dariober
  • 8,240
  • 3
  • 30
  • 47
0

Snakemake uses the Python formatting, so you can escape curly brace with another curly brace:

"-a 'A{{100}}' --nextseq-trim=20 -m 20"
Maarten-vd-Sande
  • 3,413
  • 10
  • 27
  • Thanks @Maarten-vd-Sande. As pointed out in the question, I tried double curly braces already. Seems like the quotation marks interfere with the escape {}. – pat2402 Apr 13 '20 at 21:07
  • @pat2402, I didn't properly read your original question, sorry. Does using `-a 'A{{{{100}}}}'` work? – Maarten-vd-Sande Apr 14 '20 at 06:12
  • Tripple curly braces didnt help either. It's still recognized as wildcard. However, the suggestion by @dariober to wrap the parameters in a lambda function helped. Thanks – pat2402 Apr 14 '20 at 22:26
  • @pat2402 I believe 4 braces should work. But the solution of dariober is prettier :) – Maarten-vd-Sande Apr 15 '20 at 05:26
  • @Maarten-vd-Sande For the historical record: four braces yield the same error – alephreish Jan 24 '22 at 16:52