import logging # Try to import the official pybioportal client; if it isn't installed, we'll disable cBio queries. 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: # 1) Grab all molecular profiles (you can restrict to particular studies if you like) profiles = fetch_molecular_profiles() # returns list of dicts with 'molecular_profile_id', etc. # 2) For each profile, fetch the mutations for our gene variants = [] for prof in profiles: mpid = prof.get("molecular_profile_id") if mpid: # fetch_muts_in_multiple_mol_profs returns a list of mutation dicts 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 []