MCP_Res / mcp /disgenet.py
mgbam's picture
Create disgenet.py
3925910 verified
raw
history blame contribute delete
701 Bytes
# mcp/disgenet.py
"""
DisGeNET disease–gene associations.
"""
import os, httpx
from typing import List, Dict
DISGENET_KEY = os.getenv("DISGENET_KEY")
HEADERS = {"Authorization": f"Bearer {DISGENET_KEY}"} if DISGENET_KEY else {}
BASE = "https://www.disgenet.org/api"
async def disease_to_genes(disease_name: str, limit: int = 10) -> List[Dict]:
"""
Return top gene associations for a disease.
"""
url = f"{BASE}/gda/disease/{disease_name.lower()}"
async with httpx.AsyncClient(timeout=20, headers=HEADERS) as client:
r = await client.get(url, params={"source": "ALL", "format": "json"})
r.raise_for_status()
data = r.json()
return data[:limit]