aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/traits.py
diff options
context:
space:
mode:
authorAlexander Kabui2021-03-30 18:13:35 +0300
committerAlexander Kabui2021-03-30 18:13:35 +0300
commitb67938a6730e0dc557f0d4aa978e0b9aa9211772 (patch)
treefe5db4a91a8d325287271b132afe53533e1b6dd0 /gn3/api/traits.py
parente6f10522833cbd75441766e5b8656b3f5925d6d7 (diff)
downloadgenenetwork3-b67938a6730e0dc557f0d4aa978e0b9aa9211772.tar.gz
initial commit for creating dataset
Diffstat (limited to 'gn3/api/traits.py')
-rw-r--r--gn3/api/traits.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/gn3/api/traits.py b/gn3/api/traits.py
new file mode 100644
index 0000000..b3ddcc0
--- /dev/null
+++ b/gn3/api/traits.py
@@ -0,0 +1,48 @@
+"""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
+trait = Blueprint("trait", __name__)
+
+
+@trait.route("/")
+def home():
+ """initial endpoint for traits"""
+ return jsonify({"results": "success"})
+
+
+@trait.route("/<string:trait_name>/<string:dataset_name>")
+def create_trait(trait_name, dataset_name):
+ """endpoints for creating trait first should\
+ call the endpoint for creating the trait only\
+ trait data is the sample data"""
+
+ trait_dataset = mock.Mock() # xtodo should replace this with calling epoints
+ trait_dataset.name = dataset_name
+
+ trait_results = fetch_trait(dataset=trait_dataset, trait_name=trait_name)
+
+ 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)