Skip to content

Commit

Permalink
API
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Sep 12, 2024
1 parent 645e8e3 commit bc0f38d
Show file tree
Hide file tree
Showing 38 changed files with 365 additions and 143 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ help:
@echo " format Format source code"
@echo " lint Run lint checks"
@echo " example_run Run example"
@echo " run Run the application"
@echo " run Run the CLI application"
@echo " serve Run the API application"
@echo " test-remote Run remote tests"
@echo " test Run tests"
@echo " test-all Run all tests"
Expand Down Expand Up @@ -91,6 +92,10 @@ else
pipenv run python -m src.cli "$(VAR)"
endif

.PHONY: serve
serve:
pipenv run uvicorn src.main:app --host 0.0.0.0 --port 8080 --reload --workers 8

.PHONY: test-remote
test-remote:
pipenv run pytest \
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ seqrepo = "*"
pytabix = "*"
httpx = "*"
yoyo-migrations = "*"
fastapi = "*"
uvicorn = "*"

[dev-packages]
mypy = "*"
Expand Down
117 changes: 76 additions & 41 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/api/internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .api import router as internal_router

__all__ = ["internal_router"]
79 changes: 79 additions & 0 deletions src/api/internal/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from fastapi import APIRouter, HTTPException, Query

from src.auto_acmg import AutoACMG
from src.core.config import settings
from src.defs.api import (
ApiAutoACMGSeqVarData,
ApiAutoACMGSeqVarResult,
SeqVarPredictionResponse,
StrucVarPredictionResponse,
)
from src.defs.auto_acmg import AutoACMGSeqVarResult, AutoACMGStrucVarResult
from src.defs.exceptions import AutoAcmgBaseException
from src.defs.genome_builds import GenomeRelease

router = APIRouter()


@router.post("/predict/seqvar", response_model=SeqVarPredictionResponse)
async def predict_seqvar(
variant_name: str = Query(..., description="The name or identifier of the sequence variant"),
genome_release: str = Query(default="GRCh38", description="The genome release version"),
):
try:
genome_release_enum = GenomeRelease.from_string(genome_release)
if not genome_release_enum:
raise HTTPException(status_code=400, detail="Invalid genome release")

auto_acmg = AutoACMG(variant_name, genome_release_enum)
prediction = auto_acmg.predict()

if (
prediction is None
or not isinstance(prediction, AutoACMGSeqVarResult)
or prediction.seqvar is None
):
raise HTTPException(
status_code=400, detail="No valid sequence variant prediction was made"
)

# Convert AutoACMGSeqVarResult to ApiAutoACMGSeqVarResult
api_prediction = ApiAutoACMGSeqVarResult(
seqvar=prediction.seqvar,
data=ApiAutoACMGSeqVarData(**prediction.data.model_dump()),
criteria=prediction.criteria,
)

return SeqVarPredictionResponse(prediction=api_prediction)
except AutoAcmgBaseException as e:
raise HTTPException(status_code=400, detail=str(e))


@router.post("/predict/strucvar", response_model=StrucVarPredictionResponse)
async def predict_strucvar(
variant_name: str = Query(..., description="The name or identifier of the structural variant"),
genome_release: str = Query(default="GRCh38", description="The genome release version"),
duplication_tandem: bool = Query(
default=False,
description="The duplication is in tandem and disrupts reading frame and undergoes NMD",
),
):
try:
# Set default duplication tandem if provided
settings.DUPLICATION_TANDEM = duplication_tandem

genome_release_enum = GenomeRelease.from_string(genome_release)
if not genome_release_enum:
raise HTTPException(status_code=400, detail="Invalid genome release")

auto_acmg = AutoACMG(variant_name, genome_release_enum)
prediction = auto_acmg.predict()

if prediction is None or not isinstance(prediction, AutoACMGStrucVarResult):
raise HTTPException(
status_code=400, detail="No valid structural variant prediction was made"
)

return StrucVarPredictionResponse(prediction=prediction)
except AutoAcmgBaseException as e:
raise HTTPException(status_code=400, detail=str(e))
Empty file added src/api/reev/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added src/assets/favicon.ico
Binary file not shown.
Loading

0 comments on commit bc0f38d

Please sign in to comment.