From 3a7491d00f71023c366da1e6b3479d37ffac6c7f Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Thu, 11 Apr 2024 15:04:36 -0400 Subject: [PATCH 1/2] refact(utils): support new Katsu private overview response format --- bento_beacon/utils/beacon_response.py | 11 +++++++---- bento_beacon/utils/katsu_utils.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bento_beacon/utils/beacon_response.py b/bento_beacon/utils/beacon_response.py index c79cdbce..836d8d79 100644 --- a/bento_beacon/utils/beacon_response.py +++ b/bento_beacon/utils/beacon_response.py @@ -43,12 +43,15 @@ def add_overview_stats_to_response(): def package_biosample_and_experiment_stats(stats): - biosamples = stats.get("biosamples", {}) - experiments = stats.get("experiments", {}) + phenopacket_dts_stats = stats.get("phenopacket", {}).get("data_type_specific", {}) + experiment_stats = stats.get("experiment", {}) + + biosamples = phenopacket_dts_stats.get("biosamples", {}) biosamples_count = biosamples.get("count", 0) - experiments_count = experiments.get("count", 0) sampled_tissue = biosamples.get("sampled_tissue", {}) - experiment_type = experiments.get("experiment_type", {}) + + experiments_count = experiment_stats.get("count", 0) + experiment_type = experiment_stats.get("data_type_specific", {}).get("experiment_type", {}) # convert to bento_public response format sampled_tissue_data = [{"label": key, "value": value} for key, value in sampled_tissue.items()] diff --git a/bento_beacon/utils/katsu_utils.py b/bento_beacon/utils/katsu_utils.py index 6151e070..656d1f23 100644 --- a/bento_beacon/utils/katsu_utils.py +++ b/bento_beacon/utils/katsu_utils.py @@ -270,7 +270,7 @@ def search_summary_statistics(ids): def overview_statistics(): - return katsu_get(current_app.config["KATSU_PRIVATE_OVERVIEW"]).get("data_type_specific", {}) + return katsu_get(current_app.config["KATSU_PRIVATE_OVERVIEW"]) def katsu_censorship_settings() -> tuple[int | None, int | None]: From 40f4e6012916e9cd7af0df0433fa565d944a10c5 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Fri, 12 Apr 2024 15:57:33 -0400 Subject: [PATCH 2/2] fix(utils): correctly handle katsu experiment stats --- bento_beacon/utils/beacon_response.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bento_beacon/utils/beacon_response.py b/bento_beacon/utils/beacon_response.py index 836d8d79..4cc49d9f 100644 --- a/bento_beacon/utils/beacon_response.py +++ b/bento_beacon/utils/beacon_response.py @@ -44,14 +44,14 @@ def add_overview_stats_to_response(): def package_biosample_and_experiment_stats(stats): phenopacket_dts_stats = stats.get("phenopacket", {}).get("data_type_specific", {}) - experiment_stats = stats.get("experiment", {}) + experiment_stats = stats.get("experiment", {}).get("data_type_specific", {}).get("experiments", {}) biosamples = phenopacket_dts_stats.get("biosamples", {}) biosamples_count = biosamples.get("count", 0) sampled_tissue = biosamples.get("sampled_tissue", {}) experiments_count = experiment_stats.get("count", 0) - experiment_type = experiment_stats.get("data_type_specific", {}).get("experiment_type", {}) + experiment_type = experiment_stats.get("experiment_type", {}) # convert to bento_public response format sampled_tissue_data = [{"label": key, "value": value} for key, value in sampled_tissue.items()]