aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-09-20 06:36:00 +0300
committerFrederick Muriuki Muriithi2021-09-20 06:36:00 +0300
commitb7fb10586b956a8b0389e7925e4c0cff28cde82f (patch)
tree42fd08f811e7fdc36a4b3c6decf0f649dd552211 /gn3
parent1e2357049adc72808fbf8eaac3da9411d3c78c66 (diff)
downloadgenenetwork3-b7fb10586b956a8b0389e7925e4c0cff28cde82f.tar.gz
Return only the data
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/api/heatmaps.py: Parse incoming data to build up correct trait names and respond with only the computed heatmap data. * gn3/heatmaps.py: Return only the computed data for heatmaps and clustering. Since GN3 is supposed to handle only the data, and db-access, this commit ensures that GN3 responds to the client with only the computed heatmap data, and does not try to generate the heatmaps themselves. The generation of the heatmaps will be delegated to the UI clients, such as GeneNetwork2.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/api/heatmaps.py18
-rw-r--r--gn3/heatmaps.py25
2 files changed, 23 insertions, 20 deletions
diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py
index f053241..eea3ebe 100644
--- a/gn3/api/heatmaps.py
+++ b/gn3/api/heatmaps.py
@@ -15,15 +15,9 @@ def clustered_heatmaps():
"message": "You need to provide at least one trait name."
}), 400
conn, _cursor = database_connector()
- _heatmap_file, heatmap_fig = build_heatmap(traits_names, conn)
-
- # stream the heatmap data somehow here.
- # Can plotly actually stream the figure data in a way that can be used on
- # remote end to display the image without necessarily being html?
- # return jsonify(
- # {
- # "query": heatmap_request,
- # "output_png": heatmap_fig.to_image(format="png"),
- # "output_svg": heatmap_fig.to_image(format="svg")
- # }), 200
- return jsonify({"output_filename": _heatmap_file}), 200
+ def setup_trait_fullname(trait):
+ name_parts = trait.split(":")
+ return "{dataset_name}::{trait_name}".format(
+ dataset_name=trait[1], trait_name=trait[0])
+ traits_fullnames = [parse_trait_fullname(trait) for trait in traits_names]
+ return jsonify(build_heatmap(traits_fullnames, conn)), 200
diff --git a/gn3/heatmaps.py b/gn3/heatmaps.py
index c4fc67d..205a3b3 100644
--- a/gn3/heatmaps.py
+++ b/gn3/heatmaps.py
@@ -199,17 +199,26 @@ def build_heatmap(traits_names, conn: Any):
zip(traits_ids,
[traits[idx]["trait_fullname"] for idx in traits_order]))
- return generate_clustered_heatmap(
- process_traits_data_for_heatmap(
+ # return generate_clustered_heatmap(
+ # process_traits_data_for_heatmap(
+ # organised, traits_ids, chromosome_names),
+ # clustered,
+ # "single_heatmap_{}".format(random_string(10)),
+ # y_axis=tuple(
+ # ordered_traits_names[traits_ids[order]]
+ # for order in traits_order),
+ # y_label="Traits",
+ # x_axis=chromosome_names,
+ # x_label="Chromosomes")
+ return {
+ "clustering_data": clustered,
+ "heatmap_data": process_traits_data_for_heatmap(
organised, traits_ids, chromosome_names),
- clustered,
- "single_heatmap_{}".format(random_string(10)),
- y_axis=tuple(
+ "traits": tuple(
ordered_traits_names[traits_ids[order]]
for order in traits_order),
- y_label="Traits",
- x_axis=chromosome_names,
- x_label="Chromosomes")
+ "chromosomes": chromosome_names
+ }
def compute_traits_order(slink_data, neworder: tuple = tuple()):
"""