Skip to content
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
7 changes: 5 additions & 2 deletions app/db/queries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List, Tuple

import rich

import re
from app.db.database import Database
from app.models.clean_data import CLEANColumn
from app.models.query_params import CLEANECLookupQueryParams, CLEANSearchQueryParams, CLEANTypeaheadQueryParams
Expand Down Expand Up @@ -53,7 +53,7 @@ async def build_conditions(
# for EC numbers, we allow a terminal dash as a wildcard, which is the convention used in the ec_class_names table
Comment thread
matthewberry marked this conversation as resolved.
Outdated
if value.endswith("-"):
column_conditions.append(f"clean_ec_number LIKE ${param_idx}")
query_params[param_name] = value.replace("-", "%")
query_params[param_name] = re.sub(r'-.*$', '%', value)
else:
column_conditions.append(f"clean_ec_number = ${param_idx}")
query_params[param_name] = value
Expand Down Expand Up @@ -169,6 +169,9 @@ async def get_typeahead_suggestions(db: Database, params: CLEANTypeaheadQueryPar
# match any part of the string (note we have gene names that start with an apostrophe, for example, which the user might not expect)
search = '%' + search + '%'
query = f"""SELECT DISTINCT gene_name FROM cleandb.predictions_uniprot_annot WHERE LOWER(gene_name) LIKE LOWER($1) ORDER BY 1 ASC"""
elif params.field_name == 'uniprot_id':
search = '%' + search + '%'
query = f"""SELECT DISTINCT uniprot_id FROM cleandb.predictions_uniprot_annot WHERE LOWER(uniprot_id) LIKE LOWER($1) ORDER BY 1 ASC"""
else:
raise ValueError(f"Invalid field name: {params.field_name}")

Expand Down
2 changes: 1 addition & 1 deletion app/models/clean_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CLEANSearchResponse(BaseModel):

class CLEANTypeaheadResponse(BaseModel):
"""Model for the response of a CLEAN typeahead query."""
field_name: Literal['accession', 'organism', 'protein_name', 'gene_name'] = Field(
field_name: Literal['accession', 'organism', 'protein_name', 'gene_name', 'uniprot_id'] = Field(
'organism',
description="Which field to search in",
),
Expand Down
2 changes: 1 addition & 1 deletion app/models/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CLEANSearchQueryParams(BaseModel):
class CLEANTypeaheadQueryParams(BaseModel):
"""Query parameters for CLEAN typeahead suggestions."""

field_name: Literal['accession', 'organism', 'protein_name', 'gene_name'] = Field(
field_name: Literal['accession', 'organism', 'protein_name', 'gene_name', 'uniprot_id'] = Field(
'organism',
description="Which field to search in",
)
Expand Down
2 changes: 1 addition & 1 deletion app/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async def get_data(
raise HTTPException(status_code=500, detail=f"Error retrieving data: {str(e)}")

def parse_typeahead_params(
field_name: Literal['accession', 'organism', 'protein_name', 'gene_name'] = Query(
field_name: Literal['accession', 'organism', 'protein_name', 'gene_name', 'uniprot_id'] = Query(
'organism',
description="Which field to search in",
),
Expand Down