|
import logging |
|
|
|
|
|
try: |
|
from pybioportal import fetch_muts_in_multiple_mol_profs, fetch_molecular_profiles |
|
_CBIO_ENABLED = True |
|
except ImportError: |
|
logging.warning("pybioportal package not available; disabling cBioPortal integration") |
|
_CBIO_ENABLED = False |
|
|
|
async def fetch_cbio(gene: str) -> list: |
|
""" |
|
Fetch cancer variant data for the given gene from cBioPortal. |
|
Returns an empty list if pybioportal isn't installed or on any error. |
|
""" |
|
if not _CBIO_ENABLED: |
|
return [] |
|
|
|
try: |
|
|
|
profiles = fetch_molecular_profiles() |
|
|
|
|
|
variants = [] |
|
for prof in profiles: |
|
mpid = prof.get("molecular_profile_id") |
|
if mpid: |
|
|
|
muts = fetch_muts_in_multiple_mol_profs([mpid], gene=gene) |
|
variants.extend(muts or []) |
|
|
|
return variants |
|
|
|
except Exception as e: |
|
logging.warning("cBioPortal variant fetch failed: %s", e) |
|
return [] |
|
|