File size: 1,839 Bytes
af567cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import APIRouter, HTTPException, Query
from typing import Optional
from pydantic import BaseModel

router = APIRouter()


class GeneInfo(BaseModel):
    symbol: str
    name: Optional[str] = None
    chromosome: Optional[str] = None
    variant_count: int = 0


@router.get("", response_model=list[GeneInfo])
async def list_genes(
    query: Optional[str] = None,
    limit: int = Query(default=50, ge=1, le=200),
):
    """List genes, optionally filtered by query"""
    genes = [
        {"symbol": "BRCA1", "name": "BRCA1 DNA repair associated", "chromosome": "17", "variant_count": 1250},
        {"symbol": "BRCA2", "name": "BRCA2 DNA repair associated", "chromosome": "13", "variant_count": 980},
        {"symbol": "TP53", "name": "Tumor protein p53", "chromosome": "17", "variant_count": 2100},
        {"symbol": "EGFR", "name": "Epidermal growth factor receptor", "chromosome": "7", "variant_count": 1850},
        {"symbol": "KRAS", "name": "KRAS proto-oncogene GTPase", "chromosome": "12", "variant_count": 720},
    ]
    
    if query:
        genes = [g for g in genes if query.upper() in g["symbol"].upper()]
    
    return genes[:limit]


@router.get("/{gene_symbol}", response_model=GeneInfo)
async def get_gene(gene_symbol: str):
    """Get information about a specific gene"""
    genes_db = {
        "BRCA1": {"symbol": "BRCA1", "name": "BRCA1 DNA repair associated", "chromosome": "17", "variant_count": 1250},
        "BRCA2": {"symbol": "BRCA2", "name": "BRCA2 DNA repair associated", "chromosome": "13", "variant_count": 980},
        "TP53": {"symbol": "TP53", "name": "Tumor protein p53", "chromosome": "17", "variant_count": 2100},
    }
    
    gene = genes_db.get(gene_symbol.upper())
    if not gene:
        raise HTTPException(status_code=404, detail="Gene not found")
    
    return gene