Elusive syntax error in Snakefile
1
1
Entering edit mode
14 months ago

Hi,

I'm quite new to snakemake and was trying to write a little workflow to analyze some nanopore data. However, it keeps returning an invalid syntax error caused by this rule

rule alignment:
    input:
        "{base_out}/2.TRIMMING/{sample}.trimmed_and_clean.fastq.gz"
    output:
        "{base_out}/3.ALIGNMENT/{sample}.ngmlr.bam",
        "{base_out}/3.ALIGNMENT/{sample}.ngmlr.bai"
    resources:
        partition: "EPYC"
        runtime: 5760
        mem_mb: 200000
        cpus_per_task: 20
    conda:
        "{env_file}"
    params:
        ngmlr_args="-t 20 -r /fast/burlo/fcrudele/resources/hgRef/GRCh38.p13/no_alt/GCA_000001405.15_GRCh38_no_alt_analysis_set.fna -x ont"
    message: """ ngmlr Alignment """
    shell:
        """
        ngmlr {params.ngmlr_args} -q {input}  | samtools view -b /dev/stdin |  samtools sort -@ 20 -o {output[0]} &&
        samtools index -@ 20 -b -o {output[1]}
        """

The syntax error is caused by the first line after the "output:" directive, but I'm unable to see it. What would be the problem here ?

Thanks in advance!

snakemake • 1.5k views
ADD COMMENT
1
Entering edit mode

EDIT: Maybe the lack of commas in the resources part is the problem.


What is the exact error being shown?

Can you also pass the above rule text though cat -A to show all invisible characters please?

ADD REPLY
0
Entering edit mode

Thank you for the suggestions! I've added the commas in the resources section, but it returns the same error as before:

SyntaxError in file /orfeo/cephfs/home/burlo/nardone/pipelines/minION_workflow/Snakefile, line 91: invalid syntax (Snakefile, line 91)

Using cat -A as suggested shows this:

rule alignment:$
    input:$
        "{base_out}/2.TRIMMING/{sample}.trimmed_and_clean.fastq.gz"$
    output:$
        "{base_out}/3.ALIGNMENT/{sample}.ngmlr.bam",$
        "{base_out}/3.ALIGNMENT/{sample}.ngmlr.bai"$
    resources:$
        partition: "EPYC",$
        runtime: 5760,$
        mem_mb: 200000,$
        cpus_per_task: 20$
    conda:$
        "{env_file}"$
    params:$
        ngmlr_args="-t 20 -r /fast/burlo/fcrudele/resources/hgRef/GRCh38.p13/no_alt/GCA_000001405.15_GRCh38_no_alt_analysis_set.fna -x ont"$
    message: """ ngmlr Alignment """$
    shell:$
        """$
        ngmlr {params.ngmlr_args} -q {input}  | samtools view -b /dev/stdin |  samtools sort -@ 20 -o {output[0]} &&$
        samtools index -@ 20 -b -o {output[1]}$
        """$

Line 91 is the first line after the output directive in my snakefile

ADD REPLY
0
Entering edit mode

Don't you need commas after each resource in resources?

ADD REPLY
0
Entering edit mode

Thanks for the advice!

I've tried to add the commas in the resources section but it returns the same error as before:

SyntaxError in file /orfeo/cephfs/home/burlo/nardone/pipelines/minION_workflow/Snakefile, line 91: invalid syntax (Snakefile, line 91)

with line 91 being the first line after the output directive

ADD REPLY
0
Entering edit mode

Maybe "{env_file}" should be something like f"{env_file}" but I doubt that would be a syntax error anyway. In some old versions of snakemake there was a bug in reporting the line number of errors. If possible, post the snakefile at least up to rule alignment.

ADD REPLY
3
Entering edit mode
14 months ago

I've finally been able to spot what is the problem. In the documentation there's this example:

rule:
input: ...
output: ...
resources:
    partition: <partition name>
    runtime: <some number>

However, apart from the missing commas, resources need to be specified with the resource=<resource> format. So, I've just corrected the resources part as:

resources:
        partition="EPYC",
        runtime=5760,
        mem_mb=200000,
        cpus_per_task=20

And like this it seems to work. Thanks everyone for their responses and suggestions!

ADD COMMENT
0
Entering edit mode

Wonderful that you figured it out! Please accept your answer to provide closure to the post.

ADD REPLY

Login before adding your answer.

Traffic: 1420 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