blob: cf445e15abf3a4cafbf373b247d7bc41abd496ec (
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
|
"""this module contains the all endpoints for traits"""
from unittest import mock
from flask import Blueprint
from flask import jsonify
from flask import request
from gn3.computations.traits import fetch_trait
from gn3.computations.traits import get_trait_info_data
from gn3.experimental_db import database_connector
trait = Blueprint("trait", __name__)
@trait.route("/<string:trait_name>/<string:dataset_name>")
def create_trait(trait_name, dataset_name):
"""/test:trait_name/dataset_name/type :retrieve sample\
data for trait"""
# xtodo replace the object at most this endpoint
# requires dataset_type,dataset_name ,dataset_id
trait_dataset = {
"name": dataset_name,
"id": 12,
"type": "ProbeSet" # temp values
}
conn, _cursor = database_connector()
trait_results = fetch_trait(dataset=trait_dataset,
trait_name=trait_name,
database=conn)
conn.close()
return jsonify(trait_results)
@trait.route("/trait_info/<string:trait_name>", methods=["POST"])
def fetch_trait_info(trait_name):
"""api endpoint for fetching the trait info \
expects the trait and trait dataset to have\
been created """
data = request.get_json()
trait_dataset = data["trait_dataset"]
trait_data = data["trait"]
_trait_name = trait_name # should be used as key to return results
database_instance = mock.Mock()
results = get_trait_info_data(trait_dataset, trait_data, database_instance)
return jsonify(results)
|