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 1 commit
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
4 changes: 4 additions & 0 deletions app/api/models/genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ 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)
10 changes: 10 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,12 @@ 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, assembly_accession_id: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that you are looking up genome id specifically by assembly accession id. If so, you probably shouldn't say by_specific_keyword in the function name, and in the class name in models/genome.py.

Both thoas and the grpc service allow various fields to be used as a "keyword"; but here you are only using a specific one.

# Create request
request_class = self.reflector.message_class(
"ensembl_metadata.GenomeBySpecificKeywordRequest"
)
request = request_class(assembly_accession_id=assembly_accession_id)
response = self.stub.GetGenomesBySpecificKeyword(request)
return response
19 changes: 18 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,19 @@ async def get_genome_dataset_attributes(
except Exception as ex:
logging.error(ex)
return response_error_handler({"status": 500})

@router.get("/genomeid/{assembly_accession_id}", name="genome_id")
Copy link
Contributor

@azangru azangru Dec 9, 2024

Choose a reason for hiding this comment

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

This does not look like a great pathname. Something like /assembly/{assembly_accession_id}/genome_id/ would be closer to what is happening here. We may want to discuss this collectively.

async def get_uuid(request: Request, assembly_accession_id: str):
try:
genome_array = grpc_client.get_genome_by_specific_keyword(assembly_accession_id)
latest_genome_by_keyword_object = GenomeByKeyword()
for arr in genome_array:
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})
return response_data