Update mcp/cbio.py
Browse files- mcp/cbio.py +20 -22
mcp/cbio.py
CHANGED
@@ -1,24 +1,22 @@
|
|
1 |
-
|
2 |
-
cbio.py – cBioPortal REST helper (no API-key required for public portal).
|
3 |
-
Returns variant summary rows for a gene / profile.
|
4 |
-
"""
|
5 |
-
from functools import lru_cache
|
6 |
-
import httpx, asyncio
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
gene
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
1 |
+
# mcp/cbio.py
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
from pybioportal import PyBioPortal
|
4 |
+
import asyncio
|
5 |
|
6 |
+
async def fetch_cbio_variants(gene_symbol: str) -> list[dict]:
|
7 |
+
"""
|
8 |
+
Fetches mutation/variant data for a specific gene symbol
|
9 |
+
from the default cBioPortal study (e.g. 'brca_mskcc_2020').
|
10 |
+
"""
|
11 |
+
base_url = "https://www.cbioportal.org"
|
12 |
+
client = PyBioPortal(base_url)
|
13 |
+
|
14 |
+
# Build the query path for mutations in the gene
|
15 |
+
query_path = f"/mutation?gene={gene_symbol}&studyId=brca_mskcc_2020"
|
16 |
+
loop = asyncio.get_event_loop()
|
17 |
+
df = await loop.run_in_executor(
|
18 |
+
None,
|
19 |
+
lambda: client.get_data_frame(query_path)
|
20 |
+
)
|
21 |
+
# Convert DataFrame rows to dicts for JSON serialization
|
22 |
+
return df.to_dict(orient="records")
|