Download app/api/genes.py from OpenVar/backend: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/OpenVar/backend/resolve/main/app/api/genes.py
- Command line
-
hf download hf://spaces/OpenVar/backend/app/api/genes.py
-
curl -L -o genes.py https://huggingface.co/spaces/OpenVar/backend/resolve/main/app/api/genes.py
1.84 kB
| 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 | |
| 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] | |
| 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 | |