File size: 824 Bytes
64eb751 19e03c6 2a448c1 20e7231 19e03c6 e5ff04a 19e03c6 64eb751 20e7231 e5ff04a 19e03c6 |
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 |
"""
cbio.py β cBioPortal REST helper (no API-key required for public portal).
Returns variant summary rows for a gene / profile.
"""
from functools import lru_cache
import httpx, asyncio
_BASE = "https://www.cbioportal.org/api/molecular-profiles/{profile}/genes/{gene}/mutations"
_HEADERS = {"Accept": "application/json"}
@lru_cache(maxsize=256)
async def fetch_cbio(
gene: str,
profile: str = "brca_tcga_pan_can_atlas_2018_mutations",
) -> list[dict]:
if not gene:
return []
url = _BASE.format(profile=profile, gene=gene)
params = {"projection": "SUMMARY"}
async with httpx.AsyncClient(timeout=10, headers=_HEADERS) as c:
r = await c.get(url, params=params)
if r.status_code >= 400:
return [] # swallow 4xx/5xx β empty list
return r.json()
|