aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-02-15 00:25:20 +0300
committerBonfaceKilz2023-03-01 22:03:39 +0300
commit104723d9954359cbc10140c36d4ae4f8d2f4f7f4 (patch)
treee81c17fe975616ca3f4004a389f96221b2ff8cb0
parent01e12ddb0c7f71c8c1700a4fac0b9447d83f3f9f (diff)
downloadgenenetwork3-104723d9954359cbc10140c36d4ae4f8d2f4f7f4.tar.gz
Create API endpoint for fetching trait metadata
* gn3/api/metadata.py (dataset_metadata): New function and endpoint. (jsonify_dataset_metadata): Rename to dataset_metadata. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--gn3/api/metadata.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
index 8f6127f..f87743b 100644
--- a/gn3/api/metadata.py
+++ b/gn3/api/metadata.py
@@ -8,13 +8,14 @@ from flask import current_app
from SPARQLWrapper import SPARQLWrapper
from gn3.db.rdf import get_dataset_metadata
+from gn3.db.rdf import get_trait_metadata
metadata = Blueprint("metadata", __name__)
@metadata.route("/dataset/<name>", methods=["GET"])
-def jsonify_dataset_metadata(name):
+def dataset_metadata(name):
"""Fetch a dataset's metadata given it's ACCESSION_ID"""
try:
return jsonify(
@@ -26,3 +27,18 @@ def jsonify_dataset_metadata(name):
# The virtuoso server is misconfigured or it isn't running at all
except (RemoteDisconnected, URLError):
return jsonify({})
+
+
+@metadata.route("/dataset/<dataset_name>/trait/<trait_name>", methods=["GET"])
+def trait_metadata(dataset_name, trait_name):
+ """Fetch a trait's metadata given the trait_name and dataset_name'"""
+ try:
+ return jsonify(
+ get_trait_metadata(
+ SPARQLWrapper(current_app.config.get("SPARQL_ENDPOINT")),
+ trait_name, dataset_name
+ ).data
+ )
+ # The virtuoso server is misconfigured or it isn't running at all
+ except (RemoteDisconnected, URLError):
+ return jsonify({})