5

I am using snakemake to build a workflow. I want that stderr and stdout of all rules are by default redirected into files logs/{rule}/{wildcards}.o and logs/{rule}/{wildcards}.e, respectively. How can I achieve this?

The following code does what I want by prepending to the shell command of a given rule. However, I do not want to add this to each rule. I tried to use shell.prefix(...), which prefixes commands to each rule, but I cannot find a way to access the rule name or the rule wildcards there.

SAMPLES = ['A', 'B']

rule all:
    input:
        expand('test.{sample}',sample=SAMPLES)

rule test_rule:
    output: 'test.{sample}'
    shell:
        #These three lines need to be prepended for logging.
        'mkdir -p logs/{rule}; '
        'exec 2> logs/{rule}/{wildcards}.e; '
        'exec 1> logs/{rule}/{wildcards}.o; '
        #This is the actual code for the rule
        'touch {output}; '
        'echo "test for {wildcards.sample} created";'
        ' >&2 echo "error message"'

The above code gives the expected result of log files with stdout and stderr in logs/{rule}/{wildcards}.o/e, but I want to set this globally and not for each rule.

0 Answers0