Skip to content

Commit 6c4685c

Browse files
CopilotAdamtaranto
andcommitted
Add warning messages for empty alignment files and tests
Co-authored-by: Adamtaranto <2160099+Adamtaranto@users.noreply.github.com>
1 parent cb51cba commit 6c4685c

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/flexidot/utils/alignments.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ def parse_blast6(
133133
}
134134
)
135135

136-
logging.info(f'Parsed {len(alignments)} alignments from BLAST6 file: {filepath}')
136+
if len(alignments) == 0:
137+
logging.warning(
138+
f'No alignments found in BLAST6 file: {filepath}. '
139+
'Plot will be generated without alignment overlays.'
140+
)
141+
else:
142+
logging.info(f'Parsed {len(alignments)} alignments from BLAST6 file: {filepath}')
137143
return alignments
138144

139145

@@ -260,7 +266,13 @@ def parse_paf(
260266
}
261267
)
262268

263-
logging.info(f'Parsed {len(alignments)} alignments from PAF file: {filepath}')
269+
if len(alignments) == 0:
270+
logging.warning(
271+
f'No alignments found in PAF file: {filepath}. '
272+
'Plot will be generated without alignment overlays.'
273+
)
274+
else:
275+
logging.info(f'Parsed {len(alignments)} alignments from PAF file: {filepath}')
264276
return alignments
265277

266278

tests/test_gff_handling.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55

6+
from flexidot.utils.alignments import load_alignments
67
from flexidot.utils.file_handling import read_gffs
78

89
# Test data paths
@@ -66,3 +67,39 @@ def test_read_multiple_gffs_with_empty(self):
6667
# Should still work and return data from the non-empty file
6768
assert len(feat_dict) > 0
6869
assert 'Seq2' in feat_dict
70+
71+
72+
class TestEmptyAlignments:
73+
"""Tests for empty alignment file handling."""
74+
75+
def test_empty_blast6_file(self, tmp_path):
76+
"""Test reading an empty BLAST6 file."""
77+
empty_file = tmp_path / 'empty.blast6'
78+
empty_file.write_text('')
79+
80+
alignments = load_alignments(str(empty_file), file_format='blast6')
81+
assert alignments == []
82+
83+
def test_empty_paf_file(self, tmp_path):
84+
"""Test reading an empty PAF file."""
85+
empty_file = tmp_path / 'empty.paf'
86+
empty_file.write_text('')
87+
88+
alignments = load_alignments(str(empty_file), file_format='paf')
89+
assert alignments == []
90+
91+
def test_blast6_file_with_only_comments(self, tmp_path):
92+
"""Test reading a BLAST6 file with only comments."""
93+
comment_file = tmp_path / 'comments.blast6'
94+
comment_file.write_text('# This is a comment\n# Another comment\n')
95+
96+
alignments = load_alignments(str(comment_file), file_format='blast6')
97+
assert alignments == []
98+
99+
def test_paf_file_with_only_comments(self, tmp_path):
100+
"""Test reading a PAF file with only comments."""
101+
comment_file = tmp_path / 'comments.paf'
102+
comment_file.write_text('# This is a comment\n# Another comment\n')
103+
104+
alignments = load_alignments(str(comment_file), file_format='paf')
105+
assert alignments == []

0 commit comments

Comments
 (0)