Hi, I see to have hit a ZeroDivisionError: ```Comm...
# crisprseq
a
Hi, I see to have hit a ZeroDivisionError:
Copy code
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 <module>
      mapped_reads_percentage = mapped_reads_count * 100 / total_reads_count
  ZeroDivisionError: division by zero
j
does your sample have 0 reads? 🤔 maybe all of them are filtered out?
a
Indeed, in this case, there is only 1 read in the fastq file. I’m processing numerous samples, some have many reads, some have few. I could impose some minimum read number, but ideally I want the pipeline to accept whatever I send it and return zero results if the reads don’t map
j
ok I see, yes it makes sense to handle this and return 0 results
could you open an issue for this? it has to be implemented 🙂
a
Certainly, I’ll do that now. I really appreciate your rapid responses. Sorry for the trouble
👍🏻 1