File size: 1,351 Bytes
70ede12
e5ff04a
70ede12
 
 
 
 
 
 
64eb751
70ede12
6fe33f5
70ede12
 
6fe33f5
70ede12
 
6fe33f5
70ede12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
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 []