This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Elusive syntax error in Snakefile

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

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?

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

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

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

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.

1 answer

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!

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

Log in to answer this question.