Skip to content

Commit

Permalink
feat!: add / update to copy number methods from metaschema branch (#508)
Browse files Browse the repository at this point in the history
Close #450 , #458 , #465 , #444

Notes:
- feat: add parsed to copy number change endpoint (#453)
- fix!: /parsed_to_cn_var should accept number, definite range, and indefinite range (#455)
- feat: add do_liftover param in parsed to copy number endpoints (#459)
- refactor!: parsed to copy number should accept request body (#460)
- fix: Copy Number Count copies should be Number or Indef/Def Range (#468)
- fix: allow comparator to be set in start/end values (#469)
  • Loading branch information
korikuzma committed Sep 22, 2023
1 parent 40e18f2 commit 9b1c3ee
Show file tree
Hide file tree
Showing 8 changed files with 1,944 additions and 522 deletions.
1,076 changes: 959 additions & 117 deletions tests/to_copy_number_variation/test_parsed_to_abs_cnv.py

Large diffs are not rendered by default.

120 changes: 65 additions & 55 deletions variation/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main application for FastAPI."""
import traceback
from datetime import datetime
from enum import Enum
from typing import List, Literal, Optional, Union
Expand All @@ -17,6 +18,13 @@
from variation import logger
from variation.query import QueryHandler
from variation.schemas import NormalizeService, ServiceMeta, ToVRSService
from variation.schemas.copy_number_schema import (
AmplificationToCxVarService,
ParsedToCnVarQuery,
ParsedToCnVarService,
ParsedToCxVarQuery,
ParsedToCxVarService,
)
from variation.schemas.hgvs_to_copy_number_schema import (
HgvsToCopyNumberChangeService,
HgvsToCopyNumberCountService,
Expand All @@ -26,9 +34,7 @@
TranslateIdentifierService,
)
from variation.schemas.service_schema import (
AmplificationToCxVarService,
ClinVarAssembly,
ParsedToCnVarService,
ToCdnaService,
ToGenomicService,
)
Expand Down Expand Up @@ -567,66 +573,70 @@ async def hgvs_to_copy_number_change(
return resp


assembly_descr = (
"Assembly. If `accession` is set, will ignore `assembly` and `chr`. "
"If `accession` not set, must provide both `assembly` and `chr`."
)
chr_descr = "Chromosome. Must set when `assembly` is set."
accession_descr = (
"Accession. If `accession` is set, will ignore `assembly` and "
"`chr`. If `accession` not set, must provide both `assembly` and `chr`."
)
start_descr = "Start position as residue coordinate"
end_descr = "End position as residue coordinate"
total_copies_descr = "Total copies for Copy Number Count variation object"


@app.get(
@app.post(
"/variation/parsed_to_cn_var",
summary="Given parsed ClinVar Copy Number Gain/Loss components, return "
"VRS Copy Number Count Variation",
summary="Given parsed genomic components, return VRS Copy Number Count "
"Variation",
response_description="A response to a validly-formed query.",
description="Return VRS Copy Number Count Variation",
response_model=ParsedToCnVarService,
tags=[Tag.TO_COPY_NUMBER_VARIATION],
)
def parsed_to_cn_var(
assembly: Optional[ClinVarAssembly] = Query(None, description=assembly_descr),
chr: Optional[str] = Query(None, description=chr_descr),
accession: Optional[str] = Query(None, description=accession_descr),
start: int = Query(..., description=start_descr),
end: int = Query(..., description=end_descr),
total_copies: int = Query(..., description=total_copies_descr),
untranslatable_returns_text: bool = Query(False, description=untranslatable_descr),
) -> ParsedToCnVarService:
"""Given parsed ClinVar Copy Number Gain/Loss components, return Copy Number Count
Variation
:param int start: Start position as residue coordinate
:param int end: End position as residue coordinate
:param int total_copies: Total copies for Copy Number Count variation object
:param Optional[ClinVarAssembly] assembly: Assembly. If `accession` is set,
will ignore `assembly` and `chr`. If `accession` not set, must provide
both `assembly` and `chr`.
:param Optional[str] chr: Chromosome. Must set when `assembly` is set.
:param Optional[str] accession: Accession. If `accession` is set,
will ignore `assembly` and `chr`. If `accession` not set, must provide
both `assembly` and `chr`.
:param bool untranslatable_returns_text: `True` return VRS Text Object when
unable to translate or normalize query. `False` return `None` when
unable to translate or normalize query.
:return: Tuple containing Copy Number Count variation and list of warnings
def parsed_to_cn_var(request_body: ParsedToCnVarQuery) -> ParsedToCnVarService:
"""Given parsed genomic components, return Copy Number Count Variation.
:param request_body: Request body
:return: ParsedToCnVarService containing Copy Number Count variation and list of
warnings
"""
resp = query_handler.to_copy_number_handler.parsed_to_cn_var(
start,
end,
total_copies,
assembly,
chr,
accession,
untranslatable_returns_text=untranslatable_returns_text,
)
return resp
try:
resp = query_handler.to_copy_number_handler.parsed_to_copy_number(request_body)
except Exception:
traceback_resp = traceback.format_exc().splitlines()
logger.exception(traceback_resp)

return ParsedToCnVarService(
copy_number_count=None,
warnings=["Unhandled exception. See logs for more details."],
service_meta_=ServiceMeta(
version=__version__, response_datetime=datetime.now()
),
)
else:
return resp


@app.post(
"/variation/parsed_to_cx_var",
summary="Given parsed genomic components, return VRS Copy Number Change "
"Variation",
response_description="A response to a validly-formed query.",
description="Return VRS Copy Number Change Variation",
response_model=ParsedToCxVarService,
tags=[Tag.TO_COPY_NUMBER_VARIATION],
)
def parsed_to_cx_var(request_body: ParsedToCxVarQuery) -> ParsedToCxVarService:
"""Given parsed genomic components, return Copy Number Change Variation
:param request_body: Request body
:return: ParsedToCxVarService containing Copy Number Change variation and list of
warnings
"""
try:
resp = query_handler.to_copy_number_handler.parsed_to_copy_number(request_body)
except Exception:
traceback_resp = traceback.format_exc().splitlines()
logger.exception(traceback_resp)

return ParsedToCxVarService(
copy_number_count=None,
warnings=["Unhandled exception. See logs for more details."],
service_meta_=ServiceMeta(
version=__version__, response_datetime=datetime.now()
),
)
else:
return resp


amplification_to_cx_var_descr = (
Expand Down
2 changes: 1 addition & 1 deletion variation/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ def __init__(
*to_protein_params
)
self.to_copy_number_handler = ToCopyNumberVariation(
*to_vrs_params + [gene_query_handler]
*to_vrs_params + [gene_query_handler, uta_db]
)
Loading

0 comments on commit 9b1c3ee

Please sign in to comment.