-
Notifications
You must be signed in to change notification settings - Fork 163
Open
Description
Description
The ols_get_term_ancestors tool from OLS (and perhaps others) returns an empty terms array even when total_items indicates ancestors exist. This appears to be caused by incorrect IRI encoding when calling the OLS4 API.
Steps to Reproduce
from tooluniverse import ToolUniverse
tu = ToolUniverse()
tu.load_tools()
result = tu.run({
'name': 'ols_get_term_ancestors',
'arguments': {
'operation': 'get_term_ancestors',
'term_iri': 'http://purl.obolibrary.org/obo/CL_0000084',
'ontology': 'cl',
'size': 50
}
})
print(result)Actual Result
{
'terms': [], # Empty!
'total_items': 15, # But 15 items exist
'showing': 0,
'term_iri': 'http://purl.obolibrary.org/obo/CL_0000084',
'ontology': 'cl',
'filters': {'include_obsolete': False}
}Expected Result
The terms array should contain 15 ancestor terms (lymphocyte, leukocyte, cell, etc.)
Root Cause
The OLS4 API requires double URL encoding of the IRI. When calling directly with proper encoding, it works:
from urllib.parse import quote
import requests
term_iri = 'http://purl.obolibrary.org/obo/CL_0000084'
# Double encode the IRI
encoded_iri = quote(quote(term_iri, safe=''), safe='')
url = f'https://www.ebi.ac.uk/ols4/api/ontologies/cl/terms/{encoded_iri}/ancestors'
response = requests.get(url)
data = response.json()
print(len(data['_embedded']['terms'])) # Returns 15Environment
- ToolUniverse version: (latest as of Dec 2024)
- Python: 3.11
- OLS API: OLS4 (https://www.ebi.ac.uk/ols4/)
Workaround
Use direct HTTP calls to the OLS4 API with double-encoded IRIs instead of the ols_get_term_ancestors tool.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels