Skip to content

Commit 518a7ae

Browse files
deeenesclaude
andcommitted
Add identify and all_mappings client functions
- Add identify() to detect ID types of unknown identifiers - Add all_mappings() to get all mappings across all target types - Export new functions from utils __init__ - Add tests for both functions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c0d1bb1 commit 518a7ae

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

omnipath_client/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
from omnipath_client.utils._mapping import (
1616
id_types,
17+
identify,
1718
map_name,
1819
map_name0,
1920
map_names,
2021
translate,
22+
all_mappings,
2123
translate_column,
2224
translate_columns,
2325
)

omnipath_client/utils/_mapping.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,35 @@ def id_types() -> list[dict]:
243243
"""List all supported ID types."""
244244

245245
return _get('/mapping/id-types')
246+
247+
248+
def identify(
249+
identifiers: list[str],
250+
ncbi_tax_id: int = 9606,
251+
) -> dict[str, list[dict]]:
252+
"""Identify the type of given identifiers."""
253+
254+
return _get(
255+
'/mapping/identify',
256+
{
257+
'identifiers': ','.join(identifiers),
258+
'ncbi_tax_id': ncbi_tax_id,
259+
},
260+
).get('results', {})
261+
262+
263+
def all_mappings(
264+
identifiers: list[str],
265+
id_type: str,
266+
ncbi_tax_id: int = 9606,
267+
) -> dict[str, dict[str, list[str]]]:
268+
"""Get all known mappings for identifiers."""
269+
270+
return _get(
271+
'/mapping/all',
272+
{
273+
'identifiers': ','.join(identifiers),
274+
'id_type': id_type,
275+
'ncbi_tax_id': ncbi_tax_id,
276+
},
277+
).get('results', {})

tests/test_utils.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,65 @@ def test_translate_with_min_sources(self, mock_get):
283283
assert call_params.get('min_sources') == 3
284284

285285

286+
287+
class TestIdentify:
288+
289+
@patch('omnipath_client.utils._mapping._get')
290+
def test_identify(self, mock_get):
291+
mock_get.return_value = {
292+
'results': {
293+
'P04637': [
294+
{'id_type': 'uniprot', 'role': 'source', 'mappings_count': 5},
295+
],
296+
},
297+
'meta': {'ncbi_tax_id': 9606, 'total_input': 1},
298+
}
299+
from omnipath_client.utils import identify
300+
301+
result = identify(['P04637'])
302+
assert 'P04637' in result
303+
assert result['P04637'][0]['id_type'] == 'uniprot'
304+
305+
@patch('omnipath_client.utils._mapping._get')
306+
def test_identify_params(self, mock_get):
307+
mock_get.return_value = {'results': {}, 'meta': {}}
308+
from omnipath_client.utils import identify
309+
310+
identify(['P04637', 'HMDB0000001'], ncbi_tax_id=10090)
311+
call_params = mock_get.call_args[0][1]
312+
assert call_params['identifiers'] == 'P04637,HMDB0000001'
313+
assert call_params['ncbi_tax_id'] == 10090
314+
315+
316+
class TestAllMappings:
317+
318+
@patch('omnipath_client.utils._mapping._get')
319+
def test_all_mappings(self, mock_get):
320+
mock_get.return_value = {
321+
'results': {
322+
'P04637': {'genesymbol': ['TP53'], 'entrez': ['7157']},
323+
},
324+
'meta': {},
325+
}
326+
from omnipath_client.utils import all_mappings
327+
328+
result = all_mappings(['P04637'], 'uniprot')
329+
assert 'P04637' in result
330+
assert 'genesymbol' in result['P04637']
331+
assert result['P04637']['genesymbol'] == ['TP53']
332+
333+
@patch('omnipath_client.utils._mapping._get')
334+
def test_all_mappings_params(self, mock_get):
335+
mock_get.return_value = {'results': {}, 'meta': {}}
336+
from omnipath_client.utils import all_mappings
337+
338+
all_mappings(['P04637'], 'uniprot', ncbi_tax_id=10090)
339+
call_params = mock_get.call_args[0][1]
340+
assert call_params['identifiers'] == 'P04637'
341+
assert call_params['id_type'] == 'uniprot'
342+
assert call_params['ncbi_tax_id'] == 10090
343+
344+
286345
class TestDownloadImportFix:
287346
"""Verify the dlmachine import fix."""
288347

0 commit comments

Comments
 (0)