-
Notifications
You must be signed in to change notification settings - Fork 0
feat: build vlm response (issue #13) #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 30 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
11d1002
first pass at drafting stub api endpoint for vlm caf request
jennifer-bowser 41cf9a1
add enums for genomic reference assembly ids
jennifer-bowser 9df72df
add validation for 'referenceBases' and 'alternateBases'
jennifer-bowser ca011b1
refactor to use FastAPI's built-in validation
jennifer-bowser f8b307c
add validation for 'referenceName' param
jennifer-bowser 4d2121d
add TODOs with issue numbers for work to be completed in future tickets
jennifer-bowser 713f702
move endpoint from 'main.py' into 'restapi/vlm.py'
jennifer-bowser bfcf59a
refactor chromosome name validation to be more streamlined
jennifer-bowser 130c8c6
fix casing in function params
jennifer-bowser 355157f
add newline to end of file
jennifer-bowser ed637e3
update endpoint description
jennifer-bowser 34956bd
fix a 'vlm' string to make it 'anyvlm' - missed in original PR
jennifer-bowser 6ae34f2
first pass at creating the VlmResponse object and filling in default …
jennifer-bowser 4f51d08
added some descriptions to the vlm response schema objects
jennifer-bowser db131dd
adds more decriptions and clearer TODO messages
jennifer-bowser e2fef0f
move logic out of http endpoint handler into a reusable function
jennifer-bowser f479566
add validation for ResultSet ids + add extra info to TODOs
jennifer-bowser f354a34
update zygosity getter func to raise a NotImplementedError
jennifer-bowser be12487
just raise a 'NotImplementedError' for 'build_vlm_response_from_caf_d…
jennifer-bowser f1b851e
update comment for clairity
jennifer-bowser 56a8078
update 'get_caf' method signature with better typing
jennifer-bowser 1032e78
update a few names, types, and comments for clairity
jennifer-bowser 211a8f8
resolve merge conflict
jennifer-bowser 70cc545
add support for mitochondrial DNA
jennifer-bowser f54ced2
use a pydantic model for 'ReturnedSchema' in the 'Meta' class
jennifer-bowser a07517a
update 'Meta.apiVersion' to refer to the _VLM_ API version, not our _…
jennifer-bowser 65ed1d0
use correct casing for GREGoR
jennifer-bowser 1fec677
update TODOs re: configuratbility to reference new issue #27
jennifer-bowser b55f3e7
add descriptions for all Fields that didn't already have them
jennifer-bowser 8107044
adds tests for validation code in 'VlmResponse'
jennifer-bowser 630a4f5
use variable for error message matching instead of comparing raw strings
jennifer-bowser ccc70ad
fix typo: 'uscs' > 'ucsc'
jennifer-bowser c5ed5c4
use python's built-in 'removeprefix' function
jennifer-bowser 4994bc0
Update 'uscs' > 'ucsc' in all imports/usages
jennifer-bowser ebfffef
remove docstring from FastAPI endpoint since the info is duplicated b…
jennifer-bowser 4f573d1
streamline chromosome name validation
jennifer-bowser 80c1ad3
update one last instance of 'uscs' > 'ucsc'
jennifer-bowser 082a4d6
Expand the allowable values in the 'GenomicSequence' type
jennifer-bowser 051c9a1
rename 'GenomicSequence' to NucleotideSequence' for specificity
jennifer-bowser c13e2fe
use 'ConfigDict' instead of raw dictionary object
jennifer-bowser aece41d
Merge branch 'issue-17-stub-vlm-request-endpoint' into issue-13-build…
jennifer-bowser f3587de
Whoops update import to use 'ConfigDict'
jennifer-bowser 1b520b6
resolve merge conflicts
jennifer-bowser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """Craft a VlmResponse object from a list of CohortAlleleFrequencyStudyResults""" | ||
|
|
||
| from ga4gh.va_spec.base.core import CohortAlleleFrequencyStudyResult | ||
|
|
||
| from anyvlm.schemas.vlm import ( | ||
| VlmResponse, | ||
| ) | ||
|
|
||
|
|
||
| def build_vlm_response_from_caf_data( | ||
| caf_data: list[CohortAlleleFrequencyStudyResult], | ||
| ) -> VlmResponse: | ||
| """Craft a VlmResponse object from a list of CohortAlleleFrequencyStudyResults. | ||
|
|
||
| :param caf_data: A list of `CohortAlleleFrequencyStudyResult` objects that will be used to build the VlmResponse | ||
| :return: A `VlmResponse` object. | ||
| """ | ||
| raise NotImplementedError # TODO: Implement this during/after Issue #16 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jennifer-bowser marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,154 @@ | ||
| """Schemas relating to VLM API.""" | ||
|
|
||
| from typing import ClassVar, Literal, Self | ||
|
|
||
| from pydantic import BaseModel, Field, model_validator | ||
jennifer-bowser marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| from anyvlm.utils.types import Zygosity | ||
|
|
||
| # ruff: noqa: N815 (allows camelCase vars instead of snake_case to align with expected VLM protocol response) | ||
|
|
||
| RESULT_ENTITY_TYPE = "genomicVariant" | ||
|
|
||
|
|
||
| class HandoverType(BaseModel): | ||
| """The type of handover the parent `BeaconHandover` represents.""" | ||
|
|
||
| id: str = Field( | ||
| default="gregor", description="Node-specific identifier" | ||
| ) # TODO: enable configuration of this field. See Issue #27. | ||
| label: str = Field( | ||
| default="GREGoR AnVIL browser", description="Node-specific label" | ||
| ) # TODO: enable configuration of this field. See Issue #27. | ||
|
|
||
|
|
||
| class BeaconHandover(BaseModel): | ||
| """Describes how users can get more information about the results provided in the parent `VlmResponse`""" | ||
|
|
||
| handoverType: HandoverType = HandoverType() | ||
| url: str = Field( | ||
| default="https://anvil.terra.bio/#workspaces?filter=GREGoR", # TODO: enable configuration of this field. See Issue #27. | ||
| description="A url which directs users to more detailed information about the results tabulated by the API (ideally human-readable)", | ||
| ) | ||
|
|
||
|
|
||
| class ReturnedSchema(BaseModel): | ||
| """Fixed [Beacon Schema](https://github.com/ga4gh-beacon/beacon-v2/blob/c6558bf2e6494df3905f7b2df66e903dfe509500/framework/json/common/beaconCommonComponents.json#L241)""" | ||
|
|
||
| entityType: str = Field( | ||
| default=RESULT_ENTITY_TYPE, | ||
| description=f"The type of entity this response describes. Must always be set to '{RESULT_ENTITY_TYPE}'", | ||
| ) | ||
| schema_: str = Field( | ||
| default="ga4gh-beacon-variant-v2.0.0", | ||
| # Alias is required because 'schema' is reserved by Pydantic's BaseModel class, | ||
| # But VLM expects a field named 'schema' | ||
| alias="schema", | ||
| ) | ||
|
|
||
| model_config = {"populate_by_name": True} | ||
jennifer-bowser marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class Meta(BaseModel): | ||
| """Relevant metadata about the results provided in the parent `VlmResponse`""" | ||
|
|
||
| apiVersion: str = Field( | ||
| default="v1.0", | ||
| description="The version of the VLM API that this response conforms to", | ||
| ) | ||
| beaconId: str = Field( | ||
| default="org.gregor.beacon", # TODO: enable configuration of this field. See Issue #27. | ||
| description=""" | ||
| The Id of a Beacon. Usually a reversed domain string, but any URI is acceptable. The purpose of this attribute is, | ||
| in the context of a Beacon network, to disambiguate responses coming from different Beacons. See the beacon documentation | ||
| [here](https://github.com/ga4gh-beacon/beacon-v2/blob/c6558bf2e6494df3905f7b2df66e903dfe509500/framework/src/common/beaconCommonComponents.yaml#L26) | ||
| """, | ||
| ) | ||
| returnedSchemas: list[ReturnedSchema] = [ReturnedSchema()] | ||
|
|
||
|
|
||
| class ResponseSummary(BaseModel): | ||
| """A high-level summary of the results provided in the parent `VlmResponse""" | ||
|
|
||
| exists: bool = Field( | ||
| ..., description="Indicates whether the response contains any results." | ||
| ) | ||
| numTotalResults: int = Field( | ||
| ..., description="The total number of results found for the given query" | ||
| ) | ||
|
|
||
|
|
||
| class ResultSet(BaseModel): | ||
| """A set of cohort allele frequency results. The zygosity of the ResultSet is identified in the `id` field""" | ||
|
|
||
| exists: Literal[True] = Field( | ||
| default=True, | ||
| description="Indicates whether this ResultSet exists. This must always be `True`, even if `resultsCount` = `0`", | ||
| ) | ||
| id: str = Field( | ||
| ..., | ||
| description="id should be constructed of the `HandoverType.id` + the ResultSet's zygosity. See `validate_resultset_ids` validator in `VlmResponse` class.", | ||
| examples=["Geno2MP Homozygous", "MyGene2 Heterozygous"], | ||
| ) | ||
| results: list = Field( | ||
| default=[], | ||
| min_length=0, | ||
| max_length=0, | ||
| description="This must always be set to an empty array", | ||
| ) | ||
| resultsCount: int = Field( | ||
| ..., description="A count for the zygosity indicated by the ResultSet's `id`" | ||
| ) | ||
| setType: str = Field( | ||
| default=RESULT_ENTITY_TYPE, | ||
| description=f"The type of entity relevant to these results. Must always be set to '{RESULT_ENTITY_TYPE}'", | ||
| ) | ||
|
|
||
|
|
||
| class ResponseField(BaseModel): | ||
| """A list of ResultSets""" | ||
|
|
||
| resultSets: list[ResultSet] = Field( | ||
| ..., description="A list of ResultSets for the given query." | ||
| ) | ||
|
|
||
|
|
||
| class VlmResponse(BaseModel): | ||
| """Define response structure for the variant_counts endpoint.""" | ||
|
|
||
| beaconHandovers: list[BeaconHandover] = [BeaconHandover()] | ||
| meta: Meta = Meta() | ||
| responseSummary: ResponseSummary | ||
| response: ResponseField | ||
|
|
||
| resultset_id_error_message_base: ClassVar[str] = ( | ||
| "Invalid ResultSet id - ids must be in form '<node_id> <zygosity>'" | ||
| ) | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_resultset_ids(self) -> Self: | ||
jennifer-bowser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Ensure each ResultSet.id is correctly constructed.""" | ||
| handover_ids: list[str] = [ | ||
| beaconHandover.handoverType.id for beaconHandover in self.beaconHandovers | ||
| ] | ||
|
|
||
| for result_set in self.response.resultSets: | ||
jennifer-bowser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| node_id, zygosity = None, None | ||
| try: | ||
| node_id, zygosity = result_set.id.split(" ") | ||
| except ValueError as e: | ||
| error_message = f"{self.resultset_id_error_message_base}, but provided id of {result_set.id} contains invalid formatting" | ||
| raise ValueError(error_message) from e | ||
|
|
||
| if node_id not in handover_ids: | ||
| error_message = f"{self.resultset_id_error_message_base}, but provided node_id of {node_id} does not match any `handoverType.id` provided in `self.beaconHandovers`" | ||
| raise ValueError(error_message) | ||
|
|
||
| try: | ||
| Zygosity(zygosity) | ||
| except ValueError as e: | ||
| valid_zygosity_values = {zygosity.value for zygosity in Zygosity} | ||
| error_message = f"{self.resultset_id_error_message_base}, but provided zygosity of {zygosity} is not found in allowable value set of: {', '.join(valid_zygosity_values)}" | ||
| raise ValueError(error_message) from e | ||
|
|
||
| return self | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Provide utilities.""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated to this ticket but I found one last instance of
"vlm"that needed to be updated to"anyvlm"