@@ -1828,7 +1828,7 @@ def __init__(self, map_from: str, map_to: str = 'UniProtKB AC', verbose: bool =
1828
1828
self .id_dicts = _get_id_abbreviation_dicts ()
1829
1829
1830
1830
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 ) :
1832
1832
self .to_from_identical = True
1833
1833
else :
1834
1834
self .to_from_identical = False
@@ -1854,11 +1854,16 @@ def run(self, ids: Union[str, Iterable[str]]) -> GeneIDDict:
1854
1854
to its matching gene ID in 'map_to' identifier type.
1855
1855
:rtype: GeneIDDict
1856
1856
"""
1857
+ id_dict_to , id_dict_from = self .id_dicts
1858
+
1857
1859
if len (ids ) == 0 :
1858
1860
if self .verbose :
1859
1861
warnings .warn ('No IDs were given' )
1860
1862
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 ({})
1862
1867
# if self.map_from and self.map_to are the same, return an empty GeneIDTranslator (which will map any given gene ID to itself)
1863
1868
if self .to_from_identical :
1864
1869
return GeneIDDict ()
@@ -1872,7 +1877,6 @@ def run(self, ids: Union[str, Iterable[str]]) -> GeneIDDict:
1872
1877
if self .verbose :
1873
1878
print (f"Mapping { n_queries } entries from '{ self .map_from } ' to '{ self .map_to } '..." )
1874
1879
1875
- id_dict_to , id_dict_from = self .id_dicts
1876
1880
if id_dict_to [self .map_to ] != id_dict_to [self .UNIPROTKB_TO ] and \
1877
1881
id_dict_from [self .map_from ] != id_dict_from [self .UNIPROTKB_FROM ]:
1878
1882
0 commit comments