Skip to content

Commit

Permalink
beacon query handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Dec 13, 2024
1 parent a6648c5 commit 6d36444
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
9 changes: 5 additions & 4 deletions bento_beacon/endpoints/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@

@route_with_optional_project_id("/individuals", methods=["GET", "POST"])
async def get_individuals(project_id=None):
variants_query = g.beacon_query_parameters["variants_query"]
phenopacket_filters = g.beacon_query_parameters["phenopacket_filters"]
experiment_filters = g.beacon_query_parameters["experiment_filters"]
config_filters = g.beacon_query_parameters["config_filters"]
variants_query = g.beacon_query["variants_query"]
phenopacket_filters = g.beacon_query["phenopacket_filters"]
experiment_filters = g.beacon_query["experiment_filters"]
config_filters = g.beacon_query["config_filters"]
dataset_ids = g.beacon_query["dataset_ids"]

no_query = not (variants_query or phenopacket_filters or experiment_filters or config_filters)
search_sample_ids = variants_query or experiment_filters
Expand Down
8 changes: 4 additions & 4 deletions bento_beacon/endpoints/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
@variants.route("/g_variants", methods=["GET", "POST"])
@authz_middleware.deco_public_endpoint # TODO: for now. eventually, return more depending on permissions
async def get_variants():
variants_query = g.beacon_query_parameters["variants_query"]
phenopacket_filters = g.beacon_query_parameters["phenopacket_filters"]
experiment_filters = g.beacon_query_parameters["experiment_filters"]
config_filters = g.beacon_query_parameters["config_filters"]
variants_query = g.beacon_query["variants_query"]
phenopacket_filters = g.beacon_query["phenopacket_filters"]
experiment_filters = g.beacon_query["experiment_filters"]
config_filters = g.beacon_query["config_filters"]
has_filters = phenopacket_filters or experiment_filters or config_filters

# if no query, return total count of variants
Expand Down
6 changes: 3 additions & 3 deletions bento_beacon/utils/beacon_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse_query_params(request_data):
phenopacket_filters = list(filter(lambda f: f["id"].startswith("phenopacket."), filters))
experiment_filters = list(filter(lambda f: f["id"].startswith("experiment."), filters))
config_filters = [f for f in filters if f not in phenopacket_filters and f not in experiment_filters]
datasetIds = request_data.get("datasets", {}).get("datasetIds") or []
dataset_ids = request_data.get("datasets", {}).get("datasetIds") or []

# strip filter prefixes and convert remaining ids to bento format
phenopacket_filters = list(
Expand Down Expand Up @@ -55,7 +55,7 @@ def parse_query_params(request_data):
"phenopacket_filters": phenopacket_filters,
"experiment_filters": experiment_filters,
"config_filters": config_filters,
"datasetIds": datasetIds,
"dataset_ids": dataset_ids,
}


Expand Down Expand Up @@ -146,7 +146,7 @@ async def save_request_data():
g.request_data = request_data

# parsed query components
g.beacon_query_parameters = parse_query_params(request_data)
g.beacon_query = parse_query_params(request_data)


def validate_request():
Expand Down
6 changes: 3 additions & 3 deletions bento_beacon/utils/censorship.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def censorship_settings_lookup() -> tuple[int, int]:
# we're "before request" but view args are available from request object
view_args = request.view_args if request.view_args else {}
project_id = view_args.get("project_id")
dataset_id = view_args.get("dataset_id")
dataset_id = request.args.get("datasetIds")

max_filters, count_threshold = await katsu_censorship_settings(project_id=project_id, dataset_id=dataset_id)
if max_filters is None or count_threshold is None:
Expand Down Expand Up @@ -82,11 +82,11 @@ async def censored_chart_data(data) -> list[dict[str, int]]:


def query_has_phenopacket_filter() -> bool:
return bool(g.beacon_query_parameters["phenopacket_filters"])
return bool(g.beacon_query["phenopacket_filters"])


def query_has_experiment_filter() -> bool:
return bool(g.beacon_query_parameters["experiment_filters"])
return bool(g.beacon_query["experiment_filters"])


# some anonymous queries are not permitted
Expand Down

0 comments on commit 6d36444

Please sign in to comment.