From 1b4a4bf16b0c0df536a5dc1c9f89e935faa7634c Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 28 Aug 2024 19:11:06 -0400 Subject: [PATCH 1/5] Added support for multitype filtering. --- api/server.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/api/server.py b/api/server.py index d7c7cb92..4d6c1ed6 100755 --- a/api/server.py +++ b/api/server.py @@ -283,7 +283,7 @@ async def lookup(string: str, highlighting: bool = False, offset: int = 0, limit: conint(le=1000) = 10, - biolink_type: str = None, + biolink_types: List[str] = None, only_prefixes: str = "", exclude_prefixes: str = "", only_taxa: str = "" @@ -294,6 +294,9 @@ async def lookup(string: str, :param autocomplete: Should we do the lookup in autocomplete mode (in which we expect the final word to be incomplete) or not (in which the entire phrase is expected to be complete, i.e. as an entity linker)? :param highlighting: Return information on which labels and synonyms matched the search query. + :param biolink_types: A list of Biolink types to filter (with or without the `biolink:` prefix). Note that these are + additive, i.e. if this list is ['PhenotypicFeature', 'Disease'], then both phenotypic features AND diseases + will be returned, rather than filtering to concepts that are both PhenotypicFeature and Disease. """ # First, we lowercase the query since all our indexes are case-insensitive. @@ -316,12 +319,16 @@ async def lookup(string: str, query = f'"{string_lc_escape_groupings}" OR ({string_lc_escape_everything})' # Apply filters as needed. - # Biolink type filter filters = [] - if biolink_type: - if biolink_type.startswith('biolink:'): - biolink_type = biolink_type[8:] - filters.append(f"types:{biolink_type}") + + # Biolink type filter + if biolink_types: + biolink_types_filters = [] + for biolink_type in biolink_types: + if biolink_type.startswith('biolink:'): + biolink_type = biolink_type[8:] + biolink_types_filters.append(f"types:{biolink_type}") + filters.append(" OR ".join(biolink_types_filters)) # Prefix: only filter if only_prefixes: From 4e1eef521c4b942ecc95c10bcd80c6984d1e661b Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 28 Aug 2024 19:25:16 -0400 Subject: [PATCH 2/5] Updated API endpoints to include biolink_type as a list. --- api/server.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/api/server.py b/api/server.py index 4d6c1ed6..4777bb5e 100755 --- a/api/server.py +++ b/api/server.py @@ -195,11 +195,14 @@ async def lookup_curies_get( ge=0, le=1000 )] = 10, - biolink_type: Annotated[Union[str, None], Query( - description="The Biolink type to filter to (with or without the `biolink:` prefix), e.g. `biolink:Disease` or `Disease`.", + biolink_type: Annotated[Union[List[str], None], Query( + description="The Biolink types to filter to (with or without the `biolink:` prefix), " + "e.g. `biolink:Disease` or `Disease`. Multiple types will be combined with OR, i.e. filtering " + "for PhenotypicFeature and Disease will return concepts that are either PhenotypicFeatures OR " + "Disease, not concepts that are both PhenotypicFeature AND Disease.", # We can't use `example` here because otherwise it gets filled in when filling this in. - # example="biolink:Disease" - )] = None, + example=["biolink:Disease", "biolink:PhenotypicFeature"] + )] = [], only_prefixes: Annotated[Union[str, None], Query( description="Pipe-separated, case-sensitive list of prefixes to filter to, e.g. `MONDO|EFO`.", # We can't use `example` here because otherwise it gets filled in when filling this in. @@ -250,11 +253,14 @@ async def lookup_curies_post( ge=0, le=1000 )] = 10, - biolink_type: Annotated[Union[str, None], Query( - description="The Biolink type to filter to (with or without the `biolink:` prefix), e.g. `biolink:Disease` or `Disease`.", + biolink_type: Annotated[Union[List[str], None], Query( + description="The Biolink types to filter to (with or without the `biolink:` prefix), " + "e.g. `biolink:Disease` or `Disease`. Multiple types will be combined with OR, i.e. filtering " + "for PhenotypicFeature and Disease will return concepts that are either PhenotypicFeatures OR " + "Disease, not concepts that are both PhenotypicFeature AND Disease.", # We can't use `example` here because otherwise it gets filled in when filling this in. - # example="biolink:Disease" - )] = None, + example=["biolink:Disease", "biolink:PhenotypicFeature"] + )] = [], only_prefixes: Annotated[Union[str, None], Query( description="Pipe-separated, case-sensitive list of prefixes to filter to, e.g. `MONDO|EFO`.", # We can't use `example` here because otherwise it gets filled in when filling this in. From 9beac19f1892b8b209f1864ec553e9f27553e33a Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 28 Aug 2024 19:26:59 -0400 Subject: [PATCH 3/5] Filtered example. --- api/server.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/server.py b/api/server.py index 4777bb5e..3dcaab16 100755 --- a/api/server.py +++ b/api/server.py @@ -200,8 +200,9 @@ async def lookup_curies_get( "e.g. `biolink:Disease` or `Disease`. Multiple types will be combined with OR, i.e. filtering " "for PhenotypicFeature and Disease will return concepts that are either PhenotypicFeatures OR " "Disease, not concepts that are both PhenotypicFeature AND Disease.", - # We can't use `example` here because otherwise it gets filled in when filling this in. - example=["biolink:Disease", "biolink:PhenotypicFeature"] + # We can't use `example` here because otherwise it gets filled in when you click "Try it out", + # which is easy to overlook. + # example=["biolink:Disease", "biolink:PhenotypicFeature"] )] = [], only_prefixes: Annotated[Union[str, None], Query( description="Pipe-separated, case-sensitive list of prefixes to filter to, e.g. `MONDO|EFO`.", @@ -258,8 +259,9 @@ async def lookup_curies_post( "e.g. `biolink:Disease` or `Disease`. Multiple types will be combined with OR, i.e. filtering " "for PhenotypicFeature and Disease will return concepts that are either PhenotypicFeatures OR " "Disease, not concepts that are both PhenotypicFeature AND Disease.", - # We can't use `example` here because otherwise it gets filled in when filling this in. - example=["biolink:Disease", "biolink:PhenotypicFeature"] + # We can't use `example` here because otherwise it gets filled in when you click "Try it out", + # which is easy to overlook. + # example=["biolink:Disease", "biolink:PhenotypicFeature"] )] = [], only_prefixes: Annotated[Union[str, None], Query( description="Pipe-separated, case-sensitive list of prefixes to filter to, e.g. `MONDO|EFO`.", From 80afb41274e71620ee55f796592513336fdc75dc Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 28 Aug 2024 19:32:02 -0400 Subject: [PATCH 4/5] Added on:push trigger for testing. --- .github/workflows/release-name-resolution.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-name-resolution.yml b/.github/workflows/release-name-resolution.yml index e5773778..1b349b27 100644 --- a/.github/workflows/release-name-resolution.yml +++ b/.github/workflows/release-name-resolution.yml @@ -1,6 +1,7 @@ name: 'Release a new version of NameResolution to Github Packages' on: + push: release: types: [published] From ec1d8dd4eda8d715b129b42f06c053976bffc797 Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 28 Aug 2024 19:43:51 -0400 Subject: [PATCH 5/5] Removed on:push testing after development. --- .github/workflows/release-name-resolution.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release-name-resolution.yml b/.github/workflows/release-name-resolution.yml index 1b349b27..e5773778 100644 --- a/.github/workflows/release-name-resolution.yml +++ b/.github/workflows/release-name-resolution.yml @@ -1,7 +1,6 @@ name: 'Release a new version of NameResolution to Github Packages' on: - push: release: types: [published]