Skip to content

Commit

Permalink
Semantic Search UI (#514)
Browse files Browse the repository at this point in the history
Adds support for search back to the UI, using the new built-in phenogrid

---------

Co-authored-by: Vincent Rubinetti <[email protected]>
  • Loading branch information
kevinschaper and vincerubinetti authored Dec 19, 2023
1 parent 7a25f67 commit 4ac1886
Show file tree
Hide file tree
Showing 29 changed files with 2,433 additions and 1,888 deletions.
4 changes: 2 additions & 2 deletions backend/src/monarch_py/api/additional_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Config:
arbitrary_types_allowed = True


class SemsimSearchCategory(Enum):
class SemsimSearchGroup(Enum):
HGNC = "Human Genes"
MGI = "Mouse Genes"
RGD = "Rat Genes"
Expand All @@ -30,7 +30,7 @@ class SemsimCompareRequest(BaseModel):

class SemsimSearchRequest(BaseModel):
termset: List[str] = Field(..., title="Termset to search")
category: SemsimSearchCategory = Field(..., title="Category to search for")
group: SemsimSearchGroup = Field(..., title="Group of entities to search within (e.g. Human Genes)")
limit: Optional[int] = Field(10, title="Limit the number of results", ge=1, le=50)


Expand Down
14 changes: 7 additions & 7 deletions backend/src/monarch_py/api/semsim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import APIRouter, Path, Query

from monarch_py.api.additional_models import SemsimCompareRequest, SemsimSearchRequest, SemsimSearchCategory
from monarch_py.api.additional_models import SemsimCompareRequest, SemsimSearchRequest, SemsimSearchGroup
from monarch_py.api.config import semsimian
from monarch_py.api.utils.similarity_utils import parse_similarity_prefix

Expand Down Expand Up @@ -54,14 +54,14 @@ def _post_compare(request: SemsimCompareRequest):
@router.get("/search/{termset}/{category}")
def _search(
termset: str = Path(..., title="Termset to search"),
category: SemsimSearchCategory = Path(..., title="Category of entities to search for"),
group: SemsimSearchGroup = Path(..., title="Group of entities to search within (e.g. Human Genes)"),
limit: int = Query(default=10, ge=1, le=50),
):
"""Search for terms in a termset
<b>Args:</b> <br>
termset (str, optional): Comma separated list of term IDs to find matches for. <br>
category (str, optional): Category of entities to search for. <br>
group (str, optional): Group of entities to search within (e.g. Human Genes) <br>
limit (int, optional): Limit the number of results. Defaults to 10.
<b>Returns:</b> <br>
Expand All @@ -72,11 +72,11 @@ def _search(
f"""
Running semsim search:
termset: {termset}
category: {category}
group: {group}
"""
)

results = semsimian().search(termset=termset.split(","), prefix=parse_similarity_prefix(category), limit=limit)
results = semsimian().search(termset=termset.split(","), prefix=parse_similarity_prefix(group), limit=limit)
return results


Expand All @@ -89,9 +89,9 @@ def _post_search(request: SemsimSearchRequest):
<pre>
{
"termset": ["HP:0002104", "HP:0012378", "HP:0012378", "HP:0012378"],
"category": "Human Diseases",
"group": "Human Diseases",
"limit": 5
}
</pre>
"""
return semsimian().search(request.termset, parse_similarity_prefix(request.category.value), request.limit)
return semsimian().search(request.termset, parse_similarity_prefix(request.group.value), request.limit)
8 changes: 4 additions & 4 deletions backend/src/monarch_py/api/utils/similarity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from fastapi import HTTPException

from monarch_py.api.additional_models import SemsimSearchCategory
from monarch_py.api.additional_models import SemsimSearchGroup

IS_A = omd.slots.subClassOf.curie
HP_DB_URL = "https://s3.amazonaws.com/bbop-sqlite/hp.db.gz"
Expand All @@ -25,10 +25,10 @@ def compare_termsets(


def parse_similarity_prefix(prefix: str):
if prefix in SemsimSearchCategory._member_names_:
if prefix in SemsimSearchGroup._member_names_:
prefix = prefix
elif SemsimSearchCategory(prefix):
prefix = SemsimSearchCategory(prefix).name
elif SemsimSearchGroup(prefix):
prefix = SemsimSearchGroup(prefix).name
else:
raise HTTPException(status_code=404, detail="Prefix not found")
return prefix
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_counts_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_counts_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 2,
"params": {
"facet.query": [
'(category:"biolink:DiseaseToPhenotypicFeatureAssociation") AND (subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121")',
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_response():
return {
"responseHeader": {
"QTime": 1,
"QTime": 0,
"params": {
"mm": "100%",
"q": "*:*",
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_table_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_table_response():
return {
"responseHeader": {
"QTime": 0,
"QTime": 1,
"params": {
"mm": "100%",
"q": "*:*",
Expand Down
Loading

0 comments on commit 4ac1886

Please sign in to comment.