nf-core / nf-core/crisprseq

ZeroDivisionError at alignment_summary.py stage due to low read number in input: mapped_reads_percentage = mapped_reads_count * 100 / total_reads_count

Open
#164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Nextflow
Stars
63
Forks
39
PR merge metrics
No merged PRs in 30d

Description

Description of the bug

Command executed [/Users/alantracey/.nextflow/assets/nf-core/crisprseq/templates/alignment_summary.py]:

#!/usr/bin/env python

############################

Summary of alignment
author: Júlia Mir @mirpedrol
Released under the MIT license. See git repository (https://github.com/nf-core/crisprseq) for full license text.

############################

import sys

import pysam

mapped_reads_count = int(pysam.view("-c", "-b", "-F", "4", "S01E1_BSM.bam"))
total_reads_count = int(pysam.view("-c", "-b", "S01E1_BSM.bam"))
mapped_reads_percentage = mapped_reads_count * 100 / total_reads_count

with open("S01E1_BSM_clustering_summary.csv", "r") as summary:
summary_lines = summary.readlines()

add_line = True
outname = "S01E1_BSM_clustering_summary.csv".replace("_clustering_summary.csv", "_alignment_summary.csv")
with open(outname, "w") as output_file:
for line in summary_lines:
if "aligned-reads" not in line:
output_file.write(line)
else:
output_file.write(f"aligned-reads, {mapped_reads_count} ({round(mapped_reads_percentage, 1)}%)\n")
add_line = False
if add_line:
output_file.write(f"aligned-reads, {mapped_reads_count} ({round(mapped_reads_percentage, 1)}%)\n")

with open("versions.yml", "w") as f:
f.write('"NFCORE_CRISPRSEQ:CRISPRSEQ_TARGETED:ALIGNMENT_SUMMARY":\n')
f.write(f' pysam: "{pysam.version}"\n')

Command exit status:
1

Command output:
(empty)

Command error:
Traceback (most recent call last):
File "/tmp/nxf.XXXXN0mHBp/.command.sh", line 15, in
mapped_reads_percentage = mapped_reads_count * 100 / total_reads_count
ZeroDivisionError: division by zero

Command used and terminal output

No response

Relevant files

No response

System information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with templates/alignment_summary.py and inspect the mapped_reads_percentage calculation when the BAM contains zero reads. Reproduce the reported command with an empty input and verify that the alignment summary is produced without ZeroDivisionError, with the zero-read behavior covered by a test if the repository provides one.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
bioinformatics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.