aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/heatmaps.py
blob: 43ac5802f0959a9ca1455dfd1cafb8c9e362cb7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()
    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]
    return jsonify(build_heatmap(traits_fullnames, conn)), 200