Skip to content

Commit

Permalink
Merge branch 'staging' into issue-222-coord-lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
katiestahl authored Nov 20, 2023
2 parents c86ace1 + 27a477f commit a3f2cf2
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 7 deletions.
13 changes: 12 additions & 1 deletion server/curfu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
from curfu.version import __version__ as curfu_version

fastapi_app = FastAPI(
title="Fusion Curation API",
description="Provide data functions to support [VICC Fusion Curation interface](fusion-builder.cancervariants.org/).",
contact={
"name": "Alex H. Wagner",
"email": "[email protected]",
"url": "https://www.nationwidechildrens.org/specialties/institute-for-genomic-medicine/research-labs/wagner-lab",
},
license={
"name": "MIT",
"url": "https://github.com/cancervariants/fusion-curation/blob/main/LICENSE",
},
version=curfu_version,
swagger_ui_parameters={"tryItOutEnabled": True},
docs_url="/docs",
Expand Down Expand Up @@ -63,7 +74,7 @@ def serve_react_app(app: FastAPI) -> FastAPI:
)
templates = Jinja2Templates(directory=BUILD_DIR.as_posix())

@app.get("/{full_path:path}")
@app.get("/{full_path:path}", include_in_schema=False)
async def serve_react_app(request: Request, full_path: str) -> TemplateResponse:
"""Add arbitrary path support to FastAPI service.
Expand Down
9 changes: 8 additions & 1 deletion server/curfu/routers/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from fastapi import APIRouter, Query, Request

from curfu import MAX_SUGGESTIONS, LookupServiceError
from curfu.schemas import AssociatedDomainResponse, ResponseDict, SuggestGeneResponse
from curfu.schemas import (
AssociatedDomainResponse,
ResponseDict,
RouteTag,
SuggestGeneResponse,
)

router = APIRouter()

Expand All @@ -14,6 +19,7 @@
operation_id="suggestGene",
response_model=SuggestGeneResponse,
response_model_exclude_none=True,
tags=[RouteTag.COMPLETION],
)
def suggest_gene(request: Request, term: str = Query("")) -> ResponseDict:
"""Provide completion suggestions for term provided by user.
Expand Down Expand Up @@ -52,6 +58,7 @@ def suggest_gene(request: Request, term: str = Query("")) -> ResponseDict:
operation_id="suggestDomain",
response_model=AssociatedDomainResponse,
response_model_exclude_none=True,
tags=[RouteTag.COMPLETION],
)
def suggest_domain(request: Request, gene_id: str = Query("")) -> ResponseDict:
"""Provide possible domains associated with a given gene to be selected by a user.
Expand Down
8 changes: 8 additions & 0 deletions server/curfu/routers/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
GetDomainResponse,
RegulatoryElementResponse,
ResponseDict,
RouteTag,
TemplatedSequenceElementResponse,
TxSegmentElementResponse,
)
Expand All @@ -25,6 +26,7 @@
operation_id="buildGeneElement",
response_model=GeneElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
def build_gene_element(request: Request, term: str = Query("")) -> GeneElementResponse:
"""Construct valid gene element given user-provided term.
Expand All @@ -48,6 +50,7 @@ def build_gene_element(request: Request, term: str = Query("")) -> GeneElementRe
operation_id="buildTranscriptSegmentElementECT",
response_model=TxSegmentElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
async def build_tx_segment_ect(
request: Request,
Expand Down Expand Up @@ -85,6 +88,7 @@ async def build_tx_segment_ect(
operation_id="buildTranscriptSegmentElementGCT",
response_model=TxSegmentElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
async def build_tx_segment_gct(
request: Request,
Expand Down Expand Up @@ -132,6 +136,7 @@ async def build_tx_segment_gct(
operation_id="buildTranscriptSegmentElementGCG",
response_model=TxSegmentElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
async def build_tx_segment_gcg(
request: Request,
Expand Down Expand Up @@ -179,6 +184,7 @@ async def build_tx_segment_gcg(
operation_id="buildTemplatedSequenceElement",
response_model=TemplatedSequenceElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
def build_templated_sequence_element(
request: Request, start: int, end: int, sequence_id: str, strand: str
Expand Down Expand Up @@ -215,6 +221,7 @@ def build_templated_sequence_element(
operation_id="getDomain",
response_model=GetDomainResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
def build_domain(
request: Request,
Expand Down Expand Up @@ -260,6 +267,7 @@ def build_domain(
operation_id="getRegulatoryElement",
response_model=RegulatoryElementResponse,
response_model_exclude_none=True,
tags=[RouteTag.CONSTRUCTORS],
)
def build_regulatory_element(
request: Request, element_class: RegulatoryClass, gene_name: str
Expand Down
7 changes: 7 additions & 0 deletions server/curfu/routers/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
GeneElement,
LinkerElement,
MultiplePossibleGenesElement,
RouteTag,
TemplatedSequenceElement,
TranscriptSegmentElement,
UnknownGeneElement,
Expand Down Expand Up @@ -156,6 +157,7 @@ def clientify_fusion(fusion: Fusion, fusor_instance: FUSOR) -> ClientFusion:
operation_id="alkDemo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_alk(request: Request) -> DemoResponse:
"""Retrieve ALK assayed fusion.
Expand All @@ -176,6 +178,7 @@ def get_alk(request: Request) -> DemoResponse:
operation_id="ewsr1Demo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_ewsr1(request: Request) -> DemoResponse:
"""Retrieve EWSR1 assayed fusion.
Expand All @@ -196,6 +199,7 @@ def get_ewsr1(request: Request) -> DemoResponse:
operation_id="bcrAbl1Demo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_bcr_abl1(request: Request) -> DemoResponse:
"""Retrieve BCR-ABL1 categorical fusion.
Expand All @@ -216,6 +220,7 @@ def get_bcr_abl1(request: Request) -> DemoResponse:
operation_id="tpm3Ntrk1Demo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_tpm3_ntrk1(request: Request) -> DemoResponse:
"""Retrieve TPM3-NTRK1 assayed fusion.
Expand All @@ -236,6 +241,7 @@ def get_tpm3_ntrk1(request: Request) -> DemoResponse:
operation_id="tpm3PdgfrbDemo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_tpm3_pdgfrb(request: Request) -> DemoResponse:
"""Retrieve TPM3-PDGFRB assayed fusion.
Expand All @@ -256,6 +262,7 @@ def get_tpm3_pdgfrb(request: Request) -> DemoResponse:
operation_id="ighMycDemo",
response_model=DemoResponse,
response_model_exclude_none=True,
tags=[RouteTag.DEMOS],
)
def get_igh_myc(request: Request) -> DemoResponse:
"""Retrieve IGH-MYC assayed fusion.
Expand Down
3 changes: 2 additions & 1 deletion server/curfu/routers/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from fastapi import APIRouter, Query, Request

from curfu import LookupServiceError
from curfu.schemas import NormalizeGeneResponse, ResponseDict
from curfu.schemas import NormalizeGeneResponse, ResponseDict, RouteTag

router = APIRouter()

Expand All @@ -12,6 +12,7 @@
operation_id="normalizeGene",
response_model=NormalizeGeneResponse,
response_model_exclude_none=True,
tags=[RouteTag.LOOKUP],
)
def normalize_gene(request: Request, term: str = Query("")) -> ResponseDict:
"""Normalize gene term provided by user.
Expand Down
7 changes: 5 additions & 2 deletions server/curfu/routers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
from fastapi import APIRouter
from fusor import __version__ as fusor_version

from curfu.schemas import ServiceInfoResponse
from curfu.schemas import RouteTag, ServiceInfoResponse
from curfu.version import __version__ as curfu_version

router = APIRouter()


@router.get(
"/api/service_info", operation_id="serviceInfo", response_model=ServiceInfoResponse
"/api/service_info",
operation_id="serviceInfo",
response_model=ServiceInfoResponse,
tags=[RouteTag.META],
)
def get_service_info() -> ServiceInfoResponse:
"""Return service info."""
Expand Down
7 changes: 6 additions & 1 deletion server/curfu/routers/nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pydantic import ValidationError

from curfu import logger
from curfu.schemas import NomenclatureResponse, ResponseDict
from curfu.schemas import NomenclatureResponse, ResponseDict, RouteTag

router = APIRouter()

Expand All @@ -28,6 +28,7 @@
operation_id="regulatoryElementNomenclature",
response_model=NomenclatureResponse,
response_model_exclude_none=True,
tags=[RouteTag.NOMENCLATURE],
)
def generate_regulatory_element_nomenclature(
request: Request, regulatory_element: Dict = Body()
Expand Down Expand Up @@ -69,6 +70,7 @@ def generate_regulatory_element_nomenclature(
operation_id="txSegmentNomenclature",
response_model=NomenclatureResponse,
response_model_exclude_none=True,
tags=[RouteTag.NOMENCLATURE],
)
def generate_tx_segment_nomenclature(tx_segment: Dict = Body()) -> ResponseDict:
"""Build transcript segment element nomenclature.
Expand Down Expand Up @@ -96,6 +98,7 @@ def generate_tx_segment_nomenclature(tx_segment: Dict = Body()) -> ResponseDict:
operation_id="templatedSequenceNomenclature",
response_model=NomenclatureResponse,
response_model_exclude_none=True,
tags=[RouteTag.NOMENCLATURE],
)
def generate_templated_seq_nomenclature(
request: Request, templated_sequence: Dict = Body()
Expand Down Expand Up @@ -136,6 +139,7 @@ def generate_templated_seq_nomenclature(
operation_id="geneNomenclature",
response_model=NomenclatureResponse,
response_model_exclude_none=True,
tags=[RouteTag.NOMENCLATURE],
)
def generate_gene_nomenclature(gene_element: Dict = Body()) -> ResponseDict:
"""Build gene element nomenclature.
Expand Down Expand Up @@ -170,6 +174,7 @@ def generate_gene_nomenclature(gene_element: Dict = Body()) -> ResponseDict:
operation_id="fusionNomenclature",
response_model=NomenclatureResponse,
response_model_exclude_none=True,
tags=[RouteTag.NOMENCLATURE],
)
def generate_fusion_nomenclature(
request: Request, fusion: Dict = Body()
Expand Down
6 changes: 6 additions & 0 deletions server/curfu/routers/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CoordsUtilsResponse,
GetTranscriptsResponse,
GetGeneTranscriptsResponse,
RouteTag,
SequenceIDResponse,
)
from curfu.sequence_services import InvalidInputError, get_strand
Expand All @@ -28,6 +29,7 @@
operation_id="getMANETranscripts",
response_model=GetTranscriptsResponse,
response_model_exclude_none=True,
tags=[RouteTag.UTILITIES],
)
def get_mane_transcripts(request: Request, term: str) -> Dict:
"""Get MANE transcripts for gene term.
Expand Down Expand Up @@ -83,6 +85,7 @@ async def get_transcripts_for_gene(request: Request, gene: str) -> Dict:
operation_id="getGenomicCoords",
response_model=CoordsUtilsResponse,
response_model_exclude_none=True,
tags=[RouteTag.UTILITIES],
)
async def get_genome_coords(
request: Request,
Expand Down Expand Up @@ -155,6 +158,7 @@ async def get_genome_coords(
operation_id="getExonCoords",
response_model=CoordsUtilsResponse,
response_model_exclude_none=True,
tags=[RouteTag.UTILITIES],
)
async def get_exon_coords(
request: Request,
Expand Down Expand Up @@ -214,6 +218,7 @@ async def get_exon_coords(
operation_id="getSequenceId",
response_model=SequenceIDResponse,
response_model_exclude_none=True,
tags=[RouteTag.UTILITIES],
)
async def get_sequence_id(request: Request, sequence: str) -> SequenceIDResponse:
"""Get GA4GH sequence ID and aliases given sequence sequence ID
Expand Down Expand Up @@ -263,6 +268,7 @@ async def get_sequence_id(request: Request, sequence: str) -> SequenceIDResponse
description="Given a known accession identifier, retrieve sequence data and return"
"as a FASTA file",
response_class=FileResponse,
tags=[RouteTag.UTILITIES],
)
async def get_sequence(
request: Request,
Expand Down
3 changes: 2 additions & 1 deletion server/curfu/routers/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import APIRouter, Body, Request
from fusor.exceptions import FUSORParametersException

from curfu.schemas import ResponseDict, ValidateFusionResponse
from curfu.schemas import ResponseDict, RouteTag, ValidateFusionResponse

router = APIRouter()

Expand All @@ -14,6 +14,7 @@
operation_id="validateFusion",
response_model=ValidateFusionResponse,
response_model_exclude_none=True,
tags=[RouteTag.VALIDATORS],
)
def validate_fusion(request: Request, fusion: Dict = Body()) -> ResponseDict:
"""Validate proposed Fusion object. Return warnings if invalid.
Expand Down
15 changes: 15 additions & 0 deletions server/curfu/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide schemas for FastAPI responses."""
from enum import Enum
from typing import Dict, List, Literal, Optional, Tuple, Union

from cool_seq_tool.schemas import GenomicData
Expand Down Expand Up @@ -323,3 +324,17 @@ class DemoResponse(Response):
"""Response model for demo fusion object retrieval endpoints."""

fusion: Union[ClientAssayedFusion, ClientCategoricalFusion]


class RouteTag(str, Enum):
"""Define tags for API routes."""

UTILITIES = "Utilities"
CONSTRUCTORS = "Constructors"
VALIDATORS = "Validators"
COMPLETION = "Completion"
NOMENCLATURE = "Nomenclature"
DEMOS = "Demos"
META = "Meta"
SERVICE = "Service"
LOOKUP = "Lookup"

0 comments on commit a3f2cf2

Please sign in to comment.