aboutsummaryrefslogtreecommitdiff
path: root/gn3/heatmaps.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-09-22 07:03:53 +0300
committerFrederick Muriuki Muriithi2021-09-22 07:03:53 +0300
commit920be820e9cefe1dcde86d9a252f098c67a2bb8b (patch)
treeffa17fce2a2dca25974370cf8a1677fdb3d0b0ac /gn3/heatmaps.py
parent8442204492a28153e995f3147e06c9758cd3bd28 (diff)
downloadgenenetwork3-920be820e9cefe1dcde86d9a252f098c67a2bb8b.tar.gz
Return serialized plotly figure
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/api/heatmaps.py: Serialize the figure to JSON * gn3/heatmaps.py: Return the figure object Serialize the Plotly figure into JSON, and return that, so that it can be used on the client to display the image.
Diffstat (limited to 'gn3/heatmaps.py')
-rw-r--r--gn3/heatmaps.py27
1 files changed, 8 insertions, 19 deletions
diff --git a/gn3/heatmaps.py b/gn3/heatmaps.py
index 205a3b3..cd93b3f 100644
--- a/gn3/heatmaps.py
+++ b/gn3/heatmaps.py
@@ -187,38 +187,27 @@ def build_heatmap(traits_names, conn: Any):
genotype_filename, traits_filename, separate_nperm_output=True)
qtlresults = parse_reaper_main_results(main_output)
- # permudata = parse_reaper_permutation_results(permutations_output)
organised = organise_reaper_main_results(qtlresults)
traits_ids = [# sort numerically, but retain the ids as strings
str(i) for i in sorted({int(row["ID"]) for row in qtlresults})]
chromosome_names = sorted(
{row["Chr"] for row in qtlresults}, key=chromosome_sorter_key_fn)
- # loci_names = sorted({row["Locus"] for row in qtlresults})
ordered_traits_names = dict(
zip(traits_ids,
[traits[idx]["trait_fullname"] for idx in traits_order]))
- # 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(
+ return generate_clustered_heatmap(
+ process_traits_data_for_heatmap(
organised, traits_ids, chromosome_names),
- "traits": tuple(
+ clustered,
+ "single_heatmap_{}".format(random_string(10)),
+ y_axis=tuple(
ordered_traits_names[traits_ids[order]]
for order in traits_order),
- "chromosomes": chromosome_names
- }
+ y_label="Traits",
+ x_axis=chromosome_names,
+ x_label="Chromosomes")
def compute_traits_order(slink_data, neworder: tuple = tuple()):
"""