Skip to content
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

Add new grpc endpoint to get genome id from accession id #63

Merged
merged 9 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/api/models/genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@ class DatasetAttribute(BaseModel):
class DatasetAttributes(BaseModel):
attributes: list[DatasetAttribute]
release_version: float = Field(alias="releaseVersion")

class GenomeByKeyword(BaseModel):
genome_uuid: str = Field(alias="genomeUuid", default="")
release_version: float = Field(alias=AliasPath("release", "releaseVersion"), default=0)
genome_tag: str = Field(alias=AliasPath("assembly", "urlName"), default="")
9 changes: 9 additions & 0 deletions app/api/resources/grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
limitations under the License.
"""

import logging
import grpc
from google.protobuf.json_format import MessageToDict
from yagrc import reflector as yagrc_reflector
Expand Down Expand Up @@ -148,3 +149,11 @@ def get_dataset_attributes(
genome_uuid=genome_uuid, dataset_type=dataset_type
)
return self.stub.GetAttributesValuesByUUID(dataset_attributes)

def get_genome_by_specific_keyword(self, **kwargs):
request_class = self.reflector.message_class(
"ensembl_metadata.GenomeBySpecificKeywordRequest"
)
request = request_class(**kwargs)
response = self.stub.GetGenomesBySpecificKeyword(request)
return response
21 changes: 20 additions & 1 deletion app/api/resources/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import json
import logging
from typing import Annotated

Expand All @@ -25,7 +26,7 @@
from api.models.statistics import GenomeStatistics, ExampleObjectList
from api.models.popular_species import PopularSpeciesGroup
from api.models.karyotype import Karyotype
from api.models.genome import BriefGenomeDetails, GenomeDetails, DatasetAttributes
from api.models.genome import BriefGenomeDetails, GenomeDetails, DatasetAttributes, GenomeByKeyword
from api.models.ftplinks import FTPLinks

from core.config import GRPC_HOST, GRPC_PORT
Expand Down Expand Up @@ -238,3 +239,21 @@ async def get_genome_dataset_attributes(
except Exception as ex:
logging.error(ex)
return response_error_handler({"status": 500})

@router.get("/genome")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say that since genome in other routes has a different shape, this route should be called something other than genome?

async def get_genome_by_keyword(request: Request, assembly_accession_id: str):
if (assembly_accession_id == ""):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if assembly accession ID doesn’t exist in the response?

not_found_response = {"message": "missing assembly_accession_id"}
return responses.JSONResponse(not_found_response, status_code=404)
try:
genome_response = grpc_client.get_genome_by_specific_keyword(assembly_accession_id=assembly_accession_id)
latest_genome_by_keyword_object = GenomeByKeyword()
for arr in genome_response:
arr = MessageToDict(arr)
genome_by_keyword_object = GenomeByKeyword(**arr)
if (genome_by_keyword_object.release_version > latest_genome_by_keyword_object.release_version):
latest_genome_by_keyword_object = genome_by_keyword_object
return latest_genome_by_keyword_object
except Exception as ex:
logging.error(ex)
return response_error_handler({"status": 500})