aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/metadata.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2022-11-23 12:19:02 +0300
committerBonfaceKilz2022-11-23 12:47:39 +0300
commitd0d08d513e403f7836da450a1d05eaeb89a5ba30 (patch)
treec37e42a2c0b1893fd90eb0282257351beb680f2b /gn3/api/metadata.py
parenta93e8cc48815bd7e9b64c634ad808ddbfa85cd4b (diff)
downloadgenenetwork3-d0d08d513e403f7836da450a1d05eaeb89a5ba30.tar.gz
Create a new REST endpoint for fetching a phenotype's metadata
* gn3/api/general.py: (dataset_metadata) Delete. * gn3/api/metadata.py: Import Blueprint, jsonify, current_app, SPARQLWrapper and get_dataset_metadata. (metadata): New Blueprint (jsonify_dataset_metadata): New function/end-point. * gn3/app.py: Import metadata (create_app): Register metadata blueprint.
Diffstat (limited to 'gn3/api/metadata.py')
-rw-r--r--gn3/api/metadata.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/gn3/api/metadata.py b/gn3/api/metadata.py
new file mode 100644
index 0000000..4fe9e67
--- /dev/null
+++ b/gn3/api/metadata.py
@@ -0,0 +1,22 @@
+"""API for fetching metadata using an API"""
+from flask import Blueprint
+from flask import jsonify
+from flask import current_app
+
+from SPARQLWrapper import SPARQLWrapper
+
+from gn3.db.rdf import get_dataset_metadata
+
+
+metadata = Blueprint("metadata", __name__)
+
+
+@metadata.route("/dataset/<accession_id>", methods=["GET"])
+def jsonify_dataset_metadata(accession_id):
+ """Fetch a dataset's metadata given it's ACCESSION_ID"""
+ return jsonify(get_dataset_metadata(
+ SPARQLWrapper(current_app
+ .config
+ .get("SPARQL_ENDPOINT")),
+ accession_id
+ ).data)