This is a test version of Biostars. For the public version, visit https://www.biostars.org.
No rule keywords allowed after run in snakefile

In my workflow I would like to have the option to choose which mapper to use. in my config file I have this statement

mapper: "bowtie2"

In the Snakefile I then have a mapping rule as such:

mapper = config['mapper']
...
rule Mapping:
    input:
        R1='{IDS}.conc.R1.fastq.gz',
        R2='{IDS}.conc.R2.fastq.gz',
    output:
        bam='{project}/{organism}/{mapper}/{IDS}.sorted.bam',
    params:
      mapper = {mapper}
    run:
    if params.mapper == "bowtie2":
        shell("bowtie2 --threads {config[threads]} --dovetail --very-sensitive-local --no-unal --no-mixed --no-discodant -X 2000 -x {params.index} -1 {input.R1} -2 {input.R2} 2> {log} | samtools view -Sbhu -q 7 -@8 - | samtools sort -@8 - -o {output.bam}")
    elif params.mapper == "bwa":
        shell("bwa -t {config[threads]} -M {params.index} {input.R1} {input.R2} | samtools view -Sbhu -q 7 -@8 - | samtools sort -@8 - -o {output.bam}")  
    elif params.mapper == "segemehl":
        shell("segemehl.x -i  {params.index} -d {params.ref} -S -t {config[threads]} -q {input.R1} -p {input.R2} | samtools view -Sbhu -q 7 -@8 - | samtools sort -@8 - -o {output.bam}")

But I keep getting an error message telling me I am not allow to use keywords within a run statement.

I don't understand this error. I have seen enough examples (here, or here) where this should work.

I would appreciate any corrections or suggestion.

thanks Assa

snakemake run python

under the run: indent the if statement.

1 answer

Hi,

Within the run section, you should use snakemake.input["R1"] instead of using wildcards. Or, use snakemake.wildcards[...].

If you do not mind, here are some unrelated advices:

  • Use the "threads" keyword to handle threading within Snakemake
  • input and output sections should have the same wildcards

thanks for the advices. I have found it easier to handle the number of threads used, when I inout it once in the config file and not each time in every rule. Why is it better to set separately?

The input and output have the same wildcard- {IDS}. The rest of the path point to where the data should be saved.

Log in to answer this question.