File size: 721 Bytes
6fe33f5
e5ff04a
6fe33f5
 
64eb751
6fe33f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# mcp/cbio.py

from pybioportal import PyBioPortal
import asyncio

async def fetch_cbio_variants(gene_symbol: str) -> list[dict]:
    """
    Fetches mutation/variant data for a specific gene symbol
    from the default cBioPortal study (e.g. 'brca_mskcc_2020').
    """
    base_url = "https://www.cbioportal.org"
    client = PyBioPortal(base_url)

    # Build the query path for mutations in the gene
    query_path = f"/mutation?gene={gene_symbol}&studyId=brca_mskcc_2020"
    loop = asyncio.get_event_loop()
    df = await loop.run_in_executor(
        None,
        lambda: client.get_data_frame(query_path)
    )
    # Convert DataFrame rows to dicts for JSON serialization
    return df.to_dict(orient="records")