Skip to content

Commit

Permalink
fix logging for ig format error & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fgrunewald committed Aug 16, 2023
1 parent 918cbdc commit 0914f41
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion polyply/src/simple_seq_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def parse_ig(filepath):
raise FileFormatError(msg)

DNA, RNA, AA = _identify_residues(comments)
if set(clean_lines[0]) == set(['A', 'C', 'G', 'T']):
if set(clean_lines[0]).issubset(set(['A', 'C', 'G', 'T'])):
LOGGER.warning("Found only the letters A, C, G, T on first line. Are you missing the title line in your .ig file?")

seq_graph = _parse_plain(clean_lines[1:], DNA=DNA, RNA=RNA, AA=AA)
Expand Down
4 changes: 4 additions & 0 deletions polyply/tests/test_data/simple_seq_files/test_ig_warning.ig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; here we have no title line
; here we say DNA
ATTAACACT
ATCGTACAT1
16 changes: 15 additions & 1 deletion polyply/tests/test_simple_seq_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Test that sequence files are properly read.
"""
from pathlib import Path
import logging
import pytest
import networkx as nx
from polyply import TEST_DATA
Expand Down Expand Up @@ -134,8 +135,21 @@ def test_sequence_parses_PROTEIN():
monomers = ["GLY", "ALA", "LYS", "TRP", "ASN", "VAL", "PHE", "PRO", "SER"]
ref_graph = _monomers_to_linear_nx_graph(monomers)
assert nx.is_isomorphic(seq_graph, ref_graph, node_match=_node_match)

def test_unkown_nucleotype_error():
with pytest.raises(IOError):
lines = ["AABBBCCTG"]
_parse_plain(lines, DNA=True, RNA=False)

def test_ig_warning(caplog):
ref_msg = ("Found only the letters A, C, G, T on first line."
" Are you missing the title line in your .ig file?")
filepath = Path(TEST_DATA + "/simple_seq_files/test_ig_warning.ig")
with caplog.at_level(logging.WARNING):
seq_graph = MetaMolecule.parsers["ig"](filepath)
for record in caplog.records:
assert str(record.msg) == ref_msg
assert record.levelname == "WARNING"
break
else:
assert False

0 comments on commit 0914f41

Please sign in to comment.