Skip to content

Commit

Permalink
first pass at creating filtering terms from katsu public config
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Jun 18, 2024
1 parent 1341709 commit 90cc386
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
4 changes: 1 addition & 3 deletions bento_beacon/endpoints/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,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
43 changes: 27 additions & 16 deletions bento_beacon/utils/katsu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,34 @@ 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
# filtering terms for katsu public config search only
# possible TODOs:
# - ontology term filters (needs better ontology support)
# - filters for general phenopacket / experiment search
# - 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
fields_nested = get_katsu_config_search_fields().get("sections", [])
fields = []
for f in fields_nested:
fields.extend(f["fields"])

filtering_terms = []
for f in fields:
filtering_term = {
"type": "alphanumeric",
"id": f["id"],
"label": f["title"],
"options": f["options"], # unimplemented proposal: https://github.com/ga4gh-beacon/beacon-v2/issues/79
"description": f.get("description", ""),
# "modelPath": f["mapping"] 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
#
# "scopes": scope for us is always all queryable entities in this beacon, but that can vary per beacon
# we can infer this from the endpoints / blueprints that are active
}
filtering_terms.append(filtering_term)

return filtering_terms


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

0 comments on commit 90cc386

Please sign in to comment.