File size: 966 Bytes
5b6700c
 
67ef408
5b6700c
 
67ef408
 
 
 
 
 
 
 
 
5b6700c
67ef408
 
 
 
 
 
 
 
 
5b6700c
67ef408
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# genesis/api_clients/bioportal_api.py
import os
import requests

BIOPORTAL_API_KEY = os.getenv("BIOPORTAL_API_KEY")
BIOPORTAL_BASE = "https://data.bioontology.org"

def search_bioportal(term: str, max_results: int = 10):
    """
    Search BioPortal for ontology terms related to the given term.
    Returns a list of related concept labels + IDs.
    """
    if not BIOPORTAL_API_KEY:
        raise ValueError("BIOPORTAL_API_KEY is missing in environment variables")

    url = f"{BIOPORTAL_BASE}/search"
    params = {
        "q": term,
        "apikey": BIOPORTAL_API_KEY,
        "pagesize": max_results
    }
    res = requests.get(url, params=params)
    res.raise_for_status()
    data = res.json()

    results = []
    for item in data.get("collection", []):
        results.append({
            "label": item.get("prefLabel"),
            "id": item.get("@id"),
            "ontology": item.get("links", {}).get("ontology")
        })
    return results