-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvlm.py
More file actions
70 lines (61 loc) · 2.76 KB
/
vlm.py
File metadata and controls
70 lines (61 loc) · 2.76 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Define route(s) for the variant-level matching (VLM) protocol"""
from pathlib import Path
from typing import Annotated
from fastapi import Query, Request
from ga4gh.va_spec.base.core import CohortAlleleFrequencyStudyResult
from anyvlm.anyvar.base_client import BaseAnyVarClient
from anyvlm.functions.build_vlm_response import build_vlm_response_from_caf_data
from anyvlm.functions.get_caf import get_caf
from anyvlm.main import app
from anyvlm.schemas.vlm import (
VlmResponse,
)
from anyvlm.utils.types import (
ChromosomeName,
EndpointTag,
GenomicSequence,
GrcAssemblyId,
UscsAssemblyBuild,
)
def ingest_vcf(vcf_path: Path) -> None:
"""Ingest variants and cohort allele frequency data from an input VCF
:param vcf_path: VCF file location
"""
raise NotImplementedError
@app.get(
"/variant_counts",
summary="Provides allele counts of a single sequence variant, broken down by zygosity",
description="Search for a single sequence variant and receive allele counts by zygosity, in accordance with the Variant-Level Matching protocol",
tags=[EndpointTag.SEARCH],
)
def variant_counts(
request: Request,
assemblyId: Annotated[ # noqa: N803
GrcAssemblyId | UscsAssemblyBuild,
Query(..., description="Genome reference assembly"),
],
referenceName: Annotated[ # noqa: N803
ChromosomeName, Query(..., description="Chromosome with optional 'chr' prefix")
],
start: Annotated[int, Query(..., description="Variant position")],
referenceBases: Annotated[ # noqa: N803
GenomicSequence, Query(..., description="Genomic bases ('T', 'AC', etc.)")
],
alternateBases: Annotated[ # noqa: N803
GenomicSequence, Query(..., description="Genomic bases ('T', 'AC', etc.)")
],
) -> VlmResponse:
"""Accept a Variant-Level Matching network request and return allele counts by zygosity.
:param request: FastAPI `Request` object
:param assemblyId: The genome reference assembly. Must be a GRC assembly identifier (e.g., "GRCh38) or a USCS assembly build (e.g., "hg38")
:param referenceName: The name of the reference chromosome, with optional 'chr' prefix
:param start: The start of the variant's position
:param referenceBases: Genomic bases ('T', 'AC', etc.)
:param alternateBases: Genomic bases ('T', 'AC', etc.)
:return: A VlmResponse object containing cohort allele frequency data. If no matches are found, endpoint will return a status code of 200 with an empty set of results.
"""
anyvar_client: BaseAnyVarClient = request.app.state.anyvar_client
caf_data: list[CohortAlleleFrequencyStudyResult] = get_caf(
anyvar_client, assemblyId, referenceName, start, referenceBases, alternateBases
)
return build_vlm_response_from_caf_data(caf_data)