From 6769499cbc1c8375d5db909d7fa3c3fa3641dad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20S=C3=A1nchez-Izquierdo=20Besora?= Date: Thu, 30 Jul 2026 11:50:24 +0200 Subject: [PATCH 1/4] Fix UniProt alias error handling --- CHANGELOG.md | 1 + cancermuts/datasources.py | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc1d9f1..2670dff5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The project uses [Semantic Versioning](https://semver.org/): `MAJOR.MINOR.PATCH` ### Added ### Changed ### Fixed +- Improve error handling in `UniProt._get_aliases()` so unresolved aliases are returned as `None` entries instead of causing the entire function to return `None`. ## [2.1.0] - 2026-07-16 diff --git a/cancermuts/datasources.py b/cancermuts/datasources.py index 9f2c6b93..9f8ab3f9 100644 --- a/cancermuts/datasources.py +++ b/cancermuts/datasources.py @@ -429,13 +429,25 @@ def _get_aliases(self, gene_id, to, fr='UniProtKB_AC-ID'): t_keyword = None t_query = t self.log.info("fetching alias, fr=%s, to=%s, query=%s" % (fr, t_query, gene_id)) - responses = self._uniprot_service.mapping( fr = fr, - to = t_query, - query = gene_id )['results'] + + mapping_result = self._uniprot_service.mapping( + fr=fr, + to=t_query, + query=gene_id) + + if mapping_result is None: + self.log.warning( + f"UniProt mapping returned no response for {gene_id} " + f"when requesting {t}") + out[t] = None + continue + + responses = mapping_result.get('results', []) if len(responses) == 0: self.log.warning(f"No {t} found for {gene_id}") - return None + out[t] = None + continue if len(responses) > 1: self.log.warning(f"Multiple {t} found for {gene_id}. Found {t}: {', '.join(response['to'] for response in responses)}. No {t} will be assigned.") @@ -446,7 +458,7 @@ def _get_aliases(self, gene_id, to, fr='UniProtKB_AC-ID'): if t_keyword is not None: self.log.info('using extracted keyword %s to parse results' % t_keyword) - out[t] = results['to'][t_keyword] + out[t] = results['to'].get(t_keyword) else: out[t] = results['to'] From 449f5525ba3a046072caa1ce0daf18d18da95a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20S=C3=A1nchez-Izquierdo=20Besora?= Date: Thu, 30 Jul 2026 13:16:19 +0200 Subject: [PATCH 2/4] Add error handling in get_sequence --- cancermuts/datasources.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cancermuts/datasources.py b/cancermuts/datasources.py index 9f8ab3f9..6e5b3692 100644 --- a/cancermuts/datasources.py +++ b/cancermuts/datasources.py @@ -247,6 +247,8 @@ def get_sequence(self, gene_id, upid=None, upac=None, isoform=None): elif upid is not None: self.log.info("UniProt AC will be mapped from UniProt ID") this_upac = self._get_aliases(upid, ['UniProtKB_primaryAccession'])['UniProtKB_primaryAccession'] + if this_upac is None: + raise ValueError(f"Could not resolve UniProt primary accession for {upid}") else: self.log.info("retrieving UniProt ID for human gene %s" % gene_id) try: @@ -264,9 +266,12 @@ def get_sequence(self, gene_id, upid=None, upac=None, isoform=None): self.log.info("will use Uniprot ID %s" % this_upid) this_upac = self._get_aliases(this_upid, ['UniProtKB_primaryAccession'])['UniProtKB_primaryAccession'] - + if this_upac is None: + raise ValueError(f"Could not resolve UniProt primary accession for {this_upid}") if upid is None: this_upid = self._get_aliases(this_upac, ['UniProtKB_uniProtkbId'])['UniProtKB_uniProtkbId'] + if this_upid is None: + raise ValueError(f"Could not resolve UniProt primary accession for {this_upac}") else: this_upid = upid From f8d1ab65ebec12f0c82a745a38eedcdbb60f0a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20S=C3=A1nchez-Izquierdo=20Besora?= Date: Thu, 30 Jul 2026 13:24:56 +0200 Subject: [PATCH 3/4] Small fixes in get_aliases+updated changelog --- CHANGELOG.md | 2 +- cancermuts/datasources.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2670dff5..d456b783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ The project uses [Semantic Versioning](https://semver.org/): `MAJOR.MINOR.PATCH` ### Added ### Changed ### Fixed -- Improve error handling in `UniProt._get_aliases()` so unresolved aliases are returned as `None` entries instead of causing the entire function to return `None`. +- Improve UniProt alias error handling by returning unresolved aliases as `None` entries and raising a `ValueError` when required alias conversions cannot be resolved. ## [2.1.0] - 2026-07-16 diff --git a/cancermuts/datasources.py b/cancermuts/datasources.py index 6e5b3692..310571aa 100644 --- a/cancermuts/datasources.py +++ b/cancermuts/datasources.py @@ -463,7 +463,7 @@ def _get_aliases(self, gene_id, to, fr='UniProtKB_AC-ID'): if t_keyword is not None: self.log.info('using extracted keyword %s to parse results' % t_keyword) - out[t] = results['to'].get(t_keyword) + out[t] = results['to'][t_keyword] else: out[t] = results['to'] From e0a8f204c8dcdcea26e3ecf1816732960bdb0925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20S=C3=A1nchez-Izquierdo=20Besora?= Date: Fri, 31 Jul 2026 10:45:59 +0200 Subject: [PATCH 4/4] Correction of error definition --- cancermuts/datasources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cancermuts/datasources.py b/cancermuts/datasources.py index 310571aa..1554e7e4 100644 --- a/cancermuts/datasources.py +++ b/cancermuts/datasources.py @@ -271,7 +271,7 @@ def get_sequence(self, gene_id, upid=None, upac=None, isoform=None): if upid is None: this_upid = self._get_aliases(this_upac, ['UniProtKB_uniProtkbId'])['UniProtKB_uniProtkbId'] if this_upid is None: - raise ValueError(f"Could not resolve UniProt primary accession for {this_upac}") + raise ValueError(f"Could not resolve UniProt ID for accession {this_upac}") else: this_upid = upid