Update mcp/cbio.py
Browse files- mcp/cbio.py +31 -17
mcp/cbio.py
CHANGED
@@ -1,22 +1,36 @@
|
|
1 |
-
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
async def
|
7 |
"""
|
8 |
-
|
9 |
-
|
10 |
"""
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
|
3 |
+
# Try to import the official pybioportal client; if it isn't installed, we'll disable cBio queries.
|
4 |
+
try:
|
5 |
+
from pybioportal import fetch_muts_in_multiple_mol_profs, fetch_molecular_profiles
|
6 |
+
_CBIO_ENABLED = True
|
7 |
+
except ImportError:
|
8 |
+
logging.warning("pybioportal package not available; disabling cBioPortal integration")
|
9 |
+
_CBIO_ENABLED = False
|
10 |
|
11 |
+
async def fetch_cbio(gene: str) -> list:
|
12 |
"""
|
13 |
+
Fetch cancer variant data for the given gene from cBioPortal.
|
14 |
+
Returns an empty list if pybioportal isn't installed or on any error.
|
15 |
"""
|
16 |
+
if not _CBIO_ENABLED:
|
17 |
+
return []
|
18 |
|
19 |
+
try:
|
20 |
+
# 1) Grab all molecular profiles (you can restrict to particular studies if you like)
|
21 |
+
profiles = fetch_molecular_profiles() # returns list of dicts with 'molecular_profile_id', etc.
|
22 |
+
|
23 |
+
# 2) For each profile, fetch the mutations for our gene
|
24 |
+
variants = []
|
25 |
+
for prof in profiles:
|
26 |
+
mpid = prof.get("molecular_profile_id")
|
27 |
+
if mpid:
|
28 |
+
# fetch_muts_in_multiple_mol_profs returns a list of mutation dicts
|
29 |
+
muts = fetch_muts_in_multiple_mol_profs([mpid], gene=gene)
|
30 |
+
variants.extend(muts or [])
|
31 |
+
|
32 |
+
return variants
|
33 |
+
|
34 |
+
except Exception as e:
|
35 |
+
logging.warning("cBioPortal variant fetch failed: %s", e)
|
36 |
+
return []
|