aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/datasets.py
blob: 2d1312068bc9d3a532af09414a8d45ecef922d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""this module contains code for creating datasets"""
from flask import Blueprint
from flask import jsonify

from gn3.computations.datasets import create_dataset
from gn3.computations.datasets import get_traits_data
from gn3.computations.datasets import get_probeset_trait_data

from gn3.db_utils import database_connector


dataset = Blueprint("dataset", __name__)


@dataset.route("/create/<dataset_name>/")
@dataset.route("/create/<dataset_name>/<dataset_type>")
def create_dataset_api(dataset_name, dataset_type=None):
    """Endpoint of creating dataset"""

    new_dataset = create_dataset(
        dataset_type=dataset_type, dataset_name=dataset_name)

    results = {
        "dataset": new_dataset
    }
    return jsonify(results)


@dataset.route("/fetch_traits_data/<dataset_name>/<dataset_type>")
def fetch_traits_data(dataset_name, dataset_type):
    """Endpoint for fetching Trait data"""
    # should fetch this(temp)
    trait_sample_ids = [4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15,
                        17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31,
                        35, 36, 37, 39, 98, 99, 100, 103, 487, 105, 106, 110, 115,
                        116, 117, 118, 119, 120, 919, 147,
                        121, 40, 41, 124, 125, 128, 135, 129, 130, 131,
                        132, 134, 138, 139, 140, 141, 142, 144,
                        145, 148, 149, 920, 922, 2, 3, 1, 1100]

    conn, _cursor = database_connector()
    results = get_traits_data(sample_ids=trait_sample_ids, database_instance=conn,
                              dataset_name=dataset_name, dataset_type=dataset_type)
    conn.close()

    return jsonify({"results": results})


@dataset.route("/fetch_probeset_data/<dataset_name>")
def fetch_probeset_data(dataset_name):
    """Endpoint for fetching probeset trait data"""
    trait_sample_ids = [4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15,
                        17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31,
                        35, 36, 37, 39, 98, 99, 100, 103, 487, 105, 106, 110, 115,
                        116, 117, 118, 119, 120, 919, 147,
                        121, 40, 41, 124, 125, 128, 135, 129, 130, 131,
                        132, 134, 138, 139, 140, 141, 142, 144,
                        145, 148, 149, 920, 922, 2, 3, 1, 1100]

    conn, _cursor = database_connector()

    results = get_probeset_trait_data(trait_sample_ids, conn, dataset_name)

    return jsonify({"results": results})