aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-09-16 13:06:04 +0300
committerFrederick Muriuki Muriithi2021-09-16 13:06:04 +0300
commit056171a0a2f127e90ab803b74635495fb0c079a2 (patch)
treeb14c46a89f26bc695427c1eef561757fb9d9b4dc
parent2cc9f382e199dbdbaab98c7e06deabd72e244adb (diff)
downloadgenenetwork3-056171a0a2f127e90ab803b74635495fb0c079a2.tar.gz
Intergrate the heatmap generation with the API
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Intergrate the heatmap generation code on the /api/heatmaps/clustered endpoint. The endpoint should take a json query of the form: {"traits_names": [ ... ] } where the "traits_name" value is a list of the full names of traits. A sample query to the endpoint could be something like the following: curl -i -X POST "http://localhost:8080/api/heatmaps/clustered" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d '{ "traits_names": [ "UCLA_BXDBXH_CARTILAGE_V2::ILM103710672", "UCLA_BXDBXH_CARTILAGE_V2::ILM2260338", "UCLA_BXDBXH_CARTILAGE_V2::ILM3140576", "UCLA_BXDBXH_CARTILAGE_V2::ILM5670577", "UCLA_BXDBXH_CARTILAGE_V2::ILM2070121", "UCLA_BXDBXH_CARTILAGE_V2::ILM103990541", "UCLA_BXDBXH_CARTILAGE_V2::ILM1190722", "UCLA_BXDBXH_CARTILAGE_V2::ILM6590722", "UCLA_BXDBXH_CARTILAGE_V2::ILM4200064", "UCLA_BXDBXH_CARTILAGE_V2::ILM3140463" ] }' which should respond with a json response containing the raw binary string for the png format and possibly another for the svg format.
-rw-r--r--gn3/api/heatmaps.py28
-rw-r--r--gn3/app.py2
2 files changed, 30 insertions, 0 deletions
diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py
new file mode 100644
index 0000000..cac9c71
--- /dev/null
+++ b/gn3/api/heatmaps.py
@@ -0,0 +1,28 @@
+from flask import jsonify
+from flask import request
+from flask import Blueprint
+from gn3.heatmaps import build_heatmap
+from gn3.db_utils import database_connector
+
+heatmaps = Blueprint("heatmaps", __name__)
+
+@heatmaps.route("/clustered", methods=("POST",))
+def clustered_heatmaps():
+ heatmap_request = request.get_json()
+ traits_names = heatmap_request.get("traits_names", tuple())
+ if len(traits_names) < 1:
+ return jsonify({
+ "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
diff --git a/gn3/app.py b/gn3/app.py
index 046b5de..b4b08d0 100644
--- a/gn3/app.py
+++ b/gn3/app.py
@@ -7,6 +7,7 @@ from flask import Flask
from gn3.api.gemma import gemma
from gn3.api.rqtl import rqtl
from gn3.api.general import general
+from gn3.api.heatmaps import heatmaps
from gn3.api.correlation import correlation
from gn3.api.data_entry import data_entry
@@ -30,6 +31,7 @@ def create_app(config: Union[Dict, str, None] = None) -> Flask:
app.register_blueprint(general, url_prefix="/api/")
app.register_blueprint(gemma, url_prefix="/api/gemma")
app.register_blueprint(rqtl, url_prefix="/api/rqtl")
+ app.register_blueprint(heatmaps, url_prefix="/api/heatmaps")
app.register_blueprint(correlation, url_prefix="/api/correlation")
app.register_blueprint(data_entry, url_prefix="/api/dataentry")
return app