diff options
author | zsloan | 2021-10-12 18:56:34 +0000 |
---|---|---|
committer | zsloan | 2021-10-12 18:56:34 +0000 |
commit | 0f396f4a1a753d449cf2975fc425d587d9350689 (patch) | |
tree | c9dac243dc05e5cb90ccb7f1d96fd599986bf60a /gn3/api | |
parent | 976660ce9ef915426c7ce5ff9077b439e4102a2c (diff) | |
parent | 77c274b79c3ec01de60e90db3299763cb58f715b (diff) | |
download | genenetwork3-0f396f4a1a753d449cf2975fc425d587d9350689.tar.gz |
Merge branch 'main' of https://github.com/genenetwork/genenetwork3 into feature/add_rqtl_pairscan
Diffstat (limited to 'gn3/api')
-rw-r--r-- | gn3/api/heatmaps.py | 36 | ||||
-rw-r--r-- | gn3/api/wgcna.py | 25 |
2 files changed, 61 insertions, 0 deletions
diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py new file mode 100644 index 0000000..62ca2ad --- /dev/null +++ b/gn3/api/heatmaps.py @@ -0,0 +1,36 @@ +""" +Module to hold the entrypoint functions that generate heatmaps +""" + +import io +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(): + """ + Parses the incoming data and responds with the JSON-serialized plotly figure + representing the clustered heatmap. + """ + traits_names = request.get_json().get("traits_names", tuple()) + if len(traits_names) < 2: + return jsonify({ + "message": "You need to provide at least two trait names." + }), 400 + conn, _cursor = database_connector() + def parse_trait_fullname(trait): + name_parts = trait.split(":") + return "{dataset_name}::{trait_name}".format( + dataset_name=name_parts[1], trait_name=name_parts[0]) + traits_fullnames = [parse_trait_fullname(trait) for trait in traits_names] + + with io.StringIO() as io_str: + _filename, figure = build_heatmap(traits_fullnames, conn) + figure.write_json(io_str) + fig_json = io_str.getvalue() + return fig_json, 200 diff --git a/gn3/api/wgcna.py b/gn3/api/wgcna.py new file mode 100644 index 0000000..fa044cf --- /dev/null +++ b/gn3/api/wgcna.py @@ -0,0 +1,25 @@ +"""endpoint to run wgcna analysis""" +from flask import Blueprint +from flask import request +from flask import current_app +from flask import jsonify + +from gn3.computations.wgcna import call_wgcna_script + +wgcna = Blueprint("wgcna", __name__) + + +@wgcna.route("/run_wgcna", methods=["POST"]) +def run_wgcna(): + """run wgcna:output should be a json with a the data""" + + wgcna_data = request.json + + wgcna_script = current_app.config["WGCNA_RSCRIPT"] + + results = call_wgcna_script(wgcna_script, wgcna_data) + + if results.get("data") is None: + return jsonify(results), 401 + + return jsonify(results), 200 |