|
""" |
|
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 [] |
|
return r.json() |
|
|