Snakemake alignment script
2
0
Entering edit mode
7 months ago

I have been trying to write a simple alignment pipeline with Snakemake. Unfortunately, I have a hard time understanding the error messages. In the example below, the message " 'str' object has no attribute 'name' " is a bit cryptic. Does it means that the expression {input.r1} is incorrect?

import os
import snakemake.io
import glob

    (SAMPLES,READS,) = glob_wildcards("{sample}_{read}.fastq.gz")
    READS=["1","2"]

    rule all:
        input: expand("{sample}.bam",sample=SAMPLES)

    rule bwa_map:
        input:
            ref="path/to/ref.fasta",
            r1="{sample}_1.fastq.gz",
            r2="{sample}_2.fastq.gz"

        output: "{sample}.bam"

        shell: "bwa mem {input.ref} {input.r1} {input.r2} | samtools view -Sbh - > {output}"
snakemake -n

Building DAG of jobs...
Traceback (most recent call last):
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/snakemake/__init__.py", line 701, in snakemake
    success = workflow.execute(
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/snakemake/workflow.py", line 1066, in execute
    logger.run_info("\n".join(dag.stats()))
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/snakemake/dag.py", line 2191, in stats
    yield tabulate(rows, headers="keys")
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/tabulate/__init__.py", line 2048, in tabulate
    list_of_lists, headers = _normalize_tabular_data(
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/tabulate/__init__.py", line 1471, in _normalize_tabular_data
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/tabulate/__init__.py", line 1471, in <lambda>
    rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/tabulate/__init__.py", line 107, in _is_separating_line
    (len(row) >= 1 and row[0] == SEPARATING_LINE)
  File "/mnt/shared/scratch/usr/apps/conda/lib/python3.8/site-packages/snakemake/rules.py", line 1138, in __eq__
    return self.name == other.name and self.output == other.output
AttributeError: 'str' object has no attribute 'name'
snakemake alignment • 852 views
ADD COMMENT
2
Entering edit mode
7 months ago
DBScan ▴ 300

Make sure you have proper indentation, when I run your code and fix the indentation it works fine.

import os
import snakemake.io
import glob

(SAMPLES,READS,) = glob_wildcards("{sample}_{read}.fastq.gz")
READS=["1","2"]

rule all:
        input: expand("{sample}.bam",sample=SAMPLES)

rule bwa_map:
        input:
                ref="path/to/ref.fasta",
                r1="{sample}_1.fastq.gz",
                r2="{sample}_2.fastq.gz"

output: "{sample}.bam"

shell: "bwa mem {input.ref} {input.r1} {input.r2} | samtools view -Sbh - > {output}"
ADD COMMENT
0
Entering edit mode

It is working, the same error did not show up. Another error show up ("Missing input files for rule all:"), but I think it is more linked to my dataset.

I don't understand the logic of it. The output: and shell: lines are included in the rule bwa_map:, why not indenting them??

ADD REPLY
2
Entering edit mode
7 months ago

You are probably hitting this issue https://github.com/snakemake/snakemake/issues/1899. Perhaps you are using an old version of snakemake with a recent version of the tabulate module. Try upgrading to the latest snakemake and if that doesn't fix it, post some details of your snakemake version and python.

ADD COMMENT
0
Entering edit mode

I am working with Python 3.8.12 and Snakemake 6.15.5, and try to update to 7.32.4, even though my conda/mamba is not working properly.

ADD REPLY
0
Entering edit mode

I have upgraded mamba and conda, then re-installed snakemake 7.32.4. It is now working well with the proper indentation.

import os
import snakemake.io
import glob

(SAMPLES,READS,) = glob_wildcards("{sample}_{read}.fastq.gz")
READS=["1","2"]

rule all:
        input: expand("{sample}.bam",sample=SAMPLES)

rule bwa_map:
        input:
                ref="path/to/ref.fasta",
                r1="{sample}_1.fastq.gz",
                r2="{sample}_2.fastq.gz"

        output: "{sample}.bam"

        shell: "bwa mem {input.ref} {input.r1} {input.r2} | samtools view -Sbh - > {output}"
ADD REPLY

Login before adding your answer.

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