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

first pass at creating filtering terms from katsu public config #95

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 4 deletions bento_beacon/endpoints/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ..utils.beacon_response import beacon_info_response
from ..utils.katsu_utils import (
get_filtering_terms,
get_filtering_term_resources,
katsu_total_individuals_count,
katsu_get,
katsu_datasets,
Expand Down Expand Up @@ -48,11 +47,9 @@ def beacon_info_with_overview():

@info.route("/filtering_terms")
@authz_middleware.deco_public_endpoint
# TODO
def filtering_terms():
resources = get_filtering_term_resources()
filtering_terms = get_filtering_terms()
return beacon_info_response({"resources": resources, "filteringTerms": filtering_terms})
return beacon_info_response({"resources": [], "filteringTerms": filtering_terms})


# distinct from "BEACON_CONFIG"
Expand Down
53 changes: 37 additions & 16 deletions bento_beacon/utils/katsu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,44 @@ def katsu_resources_to_beacon_resource(r):
return {key: value for (key, value) in r.items() if key != "created" and key != "updated"}


# construct filtering terms collection from katsu autocomplete endpoints
# note: katsu autocomplete endpoints are paginated
# TODO: these could be memoized, either at startup or the first time they're requested
def katsu_config_filtering_terms():
filtering_terms = []
sections = get_katsu_config_search_fields().get("sections", [])
for section in sections:
for field in section["fields"]:
filtering_term = {
"type": "alphanumeric",
"id": field["id"],
"label": field["title"],
#
# longer lablel / helptext
"description": field.get("description", ""),
#
# bento internal use fields, more to come
"bento": {"section": section["section_title"]},
#
# unimplemented proposal: https://github.com/ga4gh-beacon/beacon-v2/pull/160
# optionally move to "bento" field if never adopted
"values": field["options"],
#
# another unimplemented proposal: https://github.com/ga4gh-beacon/beacon-v2/issues/115
# proposal is for path in beacon spec, so our mapping does not match exactly
# "target": f["mapping"]
#
# TODO: scopes
# filter scope for us is always all queryable entities in this beacon, but that can vary per beacon
# we can infer this from the queryable endpoints / blueprints that are active
}
filtering_terms.append(filtering_term)

return filtering_terms


# memoize?
def get_filtering_terms():
c = current_app.config
pheno_features = katsu_autocomplete_terms(c["KATSU_PHENOTYPIC_FEATURE_TERMS_ENDPOINT"])
disease_terms = katsu_autocomplete_terms(c["KATSU_DISEASES_TERMS_ENDPOINT"])
sampled_tissue_terms = katsu_autocomplete_terms(c["KATSU_SAMPLED_TISSUES_TERMS_ENDPOINT"])
filtering_terms = pheno_features + disease_terms + sampled_tissue_terms
return list(map(katsu_autocomplete_to_beacon_filter, filtering_terms))


def get_filtering_term_resources():
r = katsu_get(current_app.config["KATSU_RESOURCES_ENDPOINT"])
resources = r.get("results", [])
resources = list(map(katsu_resources_to_beacon_resource, resources))
return resources
# add ontology filters here when we start supporting ontologies
# could also add filters for phenopacket and experiment queries
return katsu_config_filtering_terms()


# -------------------------------------------------------
Expand Down