Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with FASTQ files without adapters causing crashes for the insert size metrics module. #160

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Changelog
.. This document is user facing. Please word the changes in such a way
.. that users understand how the changes affect the new version.

version 0.9.1
-----------------
+ Fix an issue where the insert size metrics module would crash when no
adapters where present.

version 0.9.0
-----------------
+ MultiQC support since MultiQC version 1.22
Expand Down
4 changes: 2 additions & 2 deletions src/sequali/report_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,8 @@ def from_insert_size_metrics(cls, metrics: InsertSizeMetrics):
metrics.adapters_read1())
adapters_read2 = AdapterFromOverlapReport.select_relevant_adapters(
metrics.adapters_read2())
longest_adapter_read1 = adapters_read1[-1][0]
longest_adapter_read2 = adapters_read2[-1][0]
longest_adapter_read1 = adapters_read1[-1][0] if adapters_read1 else ""
longest_adapter_read2 = adapters_read2[-1][0] if adapters_read2 else ""
longest_adapter_read1_match = identify_sequence_builtin(
longest_adapter_read1)[2]
longest_adapter_read2_match = identify_sequence_builtin(
Expand Down
27 changes: 27 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def test_empty_file(tmp_path):
assert result["summary"]["total_bases"] == 0


def test_empty_file_paired(tmp_path):
empty_fastq = TEST_DATA / "empty.fastq"
sys.argv = ["", "--dir", str(tmp_path), str(empty_fastq), str(empty_fastq)]
main()
simple_fastq_json = tmp_path / "empty.fastq.json"
assert simple_fastq_json.exists()
result = json.loads(simple_fastq_json.read_text())
assert result["summary_read2"]["maximum_length"] == 0
assert result["summary_read2"]["minimum_length"] == 0
assert result["summary_read2"]["total_gc_bases"] == 0
assert result["summary_read2"]["total_bases"] == 0


def test_empty_read(tmp_path):
empty_read_fastq = TEST_DATA / "empty_read.fastq"
sys.argv = ["", "--dir", str(tmp_path), str(empty_read_fastq)]
Expand All @@ -64,6 +77,20 @@ def test_empty_read(tmp_path):
assert result["summary"]["total_bases"] == 0


def test_empty_read_paired(tmp_path):
empty_read_fastq = TEST_DATA / "empty_read.fastq"
sys.argv = ["", "--dir", str(tmp_path), str(empty_read_fastq),
str(empty_read_fastq)]
main()
simple_fastq_json = tmp_path / "empty_read.fastq.json"
assert simple_fastq_json.exists()
result = json.loads(simple_fastq_json.read_text())
assert result["summary_read2"]["maximum_length"] == 0
assert result["summary_read2"]["minimum_length"] == 0
assert result["summary_read2"]["total_gc_bases"] == 0
assert result["summary_read2"]["total_bases"] == 0


def test_adapters_only(tmp_path):
adapters_fastq = TEST_DATA / "100_illumina_adapters.fastq"
sys.argv = ["", "--dir", str(tmp_path),
Expand Down
Loading