diff options
-rw-r--r-- | gn3/api/heatmaps.py | 28 | ||||
-rw-r--r-- | gn3/app.py | 2 |
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 @@ -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 |