rhpvorderman / sequali

Fast sequencing data quality metrics
GNU Affero General Public License v3.0
11 stars 0 forks source link

sequali crashes when no adapters are found #159

Closed Redmar-van-den-Berg closed 4 months ago

Redmar-van-den-Berg commented 4 months ago

Sequali takes the last item from the list of found adapters, which crashes when the list is empty

Processing TestSample1-R2.fq.gz: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 419k/419k [00:00<00:00, 4.01MiB/s]
Processing TestSample1-R1.fq.gz: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 418k/418k [00:00<00:00, 3.91MiB/s]
Traceback (most recent call last):
  File "/data/micromamba/envs/sequali/bin/sequali", line 11, in <module>
    sys.exit(main())
  File "/data/micromamba/envs/sequali/lib/python3.10/site-packages/sequali/__main__.py", line 281, in main
    report_modules = calculate_stats(
  File "/data/micromamba/envs/sequali/lib/python3.10/site-packages/sequali/report_modules.py", line 2110, in calculate_stats
    AdapterFromOverlapReport.from_insert_size_metrics(insert_size_metrics))
  File "/data/micromamba/envs/sequali/lib/python3.10/site-packages/sequali/report_modules.py", line 1833, in from_insert_size_metrics
    longest_adapter_read1 = adapters_read1[-1][0]
IndexError: list index out of range

I've made a small workaround, but I'm not sure exactly where the empty string gets used further on, so use with caution:

        longest_adapter_read1 = adapters_read1[-1][0] if adapters_read1 else ""
        longest_adapter_read2 = adapters_read2[-1][0] if adapters_read2 else ""

The report looks like this with the workaround: image

rhpvorderman commented 4 months ago

Thanks for reporting. Let me see if I can create a reproducible test case.

Redmar-van-den-Berg commented 4 months ago

I encountered the bug with the R1.fq.gz and R2.fq.gz files from here: https://github.com/LUMC/HAMLET/tree/main/test/data/fastq

rhpvorderman commented 4 months ago

The issue is that it always crashes when there are no adapters. I fixed it in #160 . EDIT: The fix you provided works fine.