Skip to content

Commit 105eeb7

Browse files
committed
* Fixed bug where automatic mapping of gene IDs would sometimes raise an exception. Solves #46
1 parent 1c887ad commit 105eeb7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Changed
1313
Fixed
1414
******
1515
* Fixed bug where kallisto quantification would sometimes fail to sum transcripts to genes properly.
16+
* Fixed bug where automatic mapping of gene IDs would sometimes raise an exception.
1617

1718
4.1.0 (2024-09-16)
1819
-------------------

rnalysis/utils/io.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ def __init__(self, map_from: str, map_to: str = 'UniProtKB AC', verbose: bool =
18281828
self.id_dicts = _get_id_abbreviation_dicts()
18291829

18301830
id_dict_to, id_dict_from = self.id_dicts
1831-
if id_dict_to[self.map_to] == id_dict_from[self.map_from]:
1831+
if id_dict_to.get(self.map_to, self.map_to) == id_dict_from.get(self.map_from, self.map_from):
18321832
self.to_from_identical = True
18331833
else:
18341834
self.to_from_identical = False
@@ -1854,11 +1854,16 @@ def run(self, ids: Union[str, Iterable[str]]) -> GeneIDDict:
18541854
to its matching gene ID in 'map_to' identifier type.
18551855
:rtype: GeneIDDict
18561856
"""
1857+
id_dict_to, id_dict_from = self.id_dicts
1858+
18571859
if len(ids) == 0:
18581860
if self.verbose:
18591861
warnings.warn('No IDs were given')
18601862
return GeneIDDict({})
1861-
1863+
if self.map_to not in id_dict_to or self.map_from not in id_dict_from:
1864+
if self.verbose:
1865+
warnings.warn(f"Cannot map from {self.map_from} to {self.map_to}.")
1866+
return GeneIDDict({})
18621867
# if self.map_from and self.map_to are the same, return an empty GeneIDTranslator (which will map any given gene ID to itself)
18631868
if self.to_from_identical:
18641869
return GeneIDDict()
@@ -1872,7 +1877,6 @@ def run(self, ids: Union[str, Iterable[str]]) -> GeneIDDict:
18721877
if self.verbose:
18731878
print(f"Mapping {n_queries} entries from '{self.map_from}' to '{self.map_to}'...")
18741879

1875-
id_dict_to, id_dict_from = self.id_dicts
18761880
if id_dict_to[self.map_to] != id_dict_to[self.UNIPROTKB_TO] and \
18771881
id_dict_from[self.map_from] != id_dict_from[self.UNIPROTKB_FROM]:
18781882

0 commit comments

Comments
 (0)