No rule keywords allowed after run in snakefile
1
3
Entering edit mode
4.8 years ago
Assa Yeroslaviz ★ 1.9k

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 • 2.7k views
ADD COMMENT
0
Entering edit mode

under the run: indent the if statement.

ADD REPLY
0
Entering edit mode
4.8 years ago
Thibault D. ▴ 700

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
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1646 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6