From 94b529e8abdb5d1c7894bc2d4a8aece611aff7ca Mon Sep 17 00:00:00 2001 From: Ruibin Liu Date: Thu, 14 Dec 2023 19:31:47 -0500 Subject: [PATCH] < or > in res range --- pyuniprot/Uniprot.py | 18 +++++++++++++----- tests/test_uniprot.py | 3 --- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pyuniprot/Uniprot.py b/pyuniprot/Uniprot.py index 35a1ba1..c8e0a07 100644 --- a/pyuniprot/Uniprot.py +++ b/pyuniprot/Uniprot.py @@ -575,7 +575,7 @@ def _get_category_lines(self) -> None: record_name: str = line[2:20].strip() if record_name != "": one_record: dict[str, str | int | SeqRange | None] = {} - site_or_range: int | SeqRange | None = None + site_or_range: str | int | SeqRange | None = None seq_ids: list[str] = [ seq_id for seq_id in line[20:].strip().split("..") ] @@ -584,16 +584,24 @@ def _get_category_lines(self) -> None: isoform = seq_ids[0].split(":")[0] if len(seq_ids) == 1: name: str = "at_site" - site_or_range = int(seq_ids[0].split(":")[-1]) - + try: + site_or_range = int(seq_ids[0].split(":")[-1]) + except ValueError: + site_or_range = seq_ids[0].split(":")[-1] else: name = "in_range" seq_start: int | str = "?" seq_end: int | str = "?" if "?" not in seq_ids[0]: - seq_start = int(seq_ids[0].split(":")[-1]) + try: + seq_start = int(seq_ids[0].split(":")[-1]) + except ValueError: + seq_start = seq_ids[0].split(":")[-1] if "?" not in seq_ids[1]: - seq_end = int(seq_ids[1].split(":")[-1]) + try: + seq_end = int(seq_ids[1].split(":")[-1]) + except ValueError: + seq_end = seq_ids[1].split(":")[-1] site_or_range = SeqRange(seq_start, seq_end) one_record[name] = site_or_range one_record["isoform"] = isoform diff --git a/tests/test_uniprot.py b/tests/test_uniprot.py index 52a51d2..0ba7d5f 100644 --- a/tests/test_uniprot.py +++ b/tests/test_uniprot.py @@ -95,6 +95,3 @@ def test_empty_resid(): .seq_begin == "" ), "Q9NPA5 first PDB resids are not ''." - - -test_empty_resid()