Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The project uses [Semantic Versioning](https://semver.org/): `MAJOR.MINOR.PATCH`
### Added
### Changed
### Fixed
- 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

Expand Down
27 changes: 22 additions & 5 deletions cancermuts/datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still primary accession?

this is different from the other two calls

else:
this_upid = upid

Expand Down Expand Up @@ -429,13 +434,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.")
Comment thread
mtiberti marked this conversation as resolved.
Expand Down