Home > database >  Snakemake bash strict mode how to fix "_([^_] )_"?
Snakemake bash strict mode how to fix "_([^_] )_"?

Time:06-29

Hi I want to use this "_([^_] )_" expression in my command, I am wondering how to make it fit for Snakemake?

Thank you very much!

CodePudding user response:

I commonly will put awk scripts into params to prevent any formatting by snakemake in the shell directive.

rule one:
    params:
        regex=r'_([^_] )_'  # note the r
    shell:
        "grep '{params.regex}' "

But in this case I think the raw string would be ok without this trick. It's really useful for scripts like {sum = $1} END {print sum} that would otherwise need to have double curly braces {{sum = $1}} END {{print sum}}.

CodePudding user response:

You should explain what you mean by make it fit and show some code for context... My guess is that you want to use python raw-string formatting to avoid unexpected interpretation? Like (note the r before """):

rule one:
   ...
   shell:
       r"""
       grep '_([^_] )_' ...
       """
  • Related