From 32c144cdf41d2f109901d34930296f34fa51323e Mon Sep 17 00:00:00 2001 From: Munyoki Kilyungi Date: Wed, 1 Mar 2023 15:48:15 +0300 Subject: Fetch sampledata * gn3/api/sampledata.py (get_sampledata): New end-point. * gn3/app.py: Register above end-point. * gn3/settings.py: Add new conf variable for LMDB. Signed-off-by: Munyoki Kilyungi --- gn3/api/sampledata.py | 23 +++++++++++++++++++++++ gn3/app.py | 2 ++ gn3/settings.py | 3 +++ 3 files changed, 28 insertions(+) create mode 100644 gn3/api/sampledata.py diff --git a/gn3/api/sampledata.py b/gn3/api/sampledata.py new file mode 100644 index 0000000..5b09b52 --- /dev/null +++ b/gn3/api/sampledata.py @@ -0,0 +1,23 @@ +"""API for fetching sampledata from a given trait""" +import os +from flask import Blueprint +from flask import jsonify +from flask import current_app + +from gn3.db.matrix import get_current_matrix + + +sampledata = Blueprint("sampledata", __name__) + + +@sampledata.route("/dataset//trait/", methods=["GET"]) +def get_sampledata(dataset_name, trait_name): + """Fetch a trait's sampledata as a matrix.""" + return jsonify( + get_current_matrix( + os.path.join( + current_app.config.get("LMDB_PATH"), + dataset_name, trait_name + ) + ) + ) diff --git a/gn3/app.py b/gn3/app.py index 72d76c2..0c2f9f9 100644 --- a/gn3/app.py +++ b/gn3/app.py @@ -20,6 +20,7 @@ from gn3.api.async_commands import async_commands from gn3.api.menu import menu from gn3.api.search import search from gn3.api.metadata import metadata +from gn3.api.sampledata import sampledata from gn3.auth import oauth2 from gn3.auth.authentication.oauth2.server import setup_oauth2_server @@ -59,6 +60,7 @@ def create_app(config: Union[Dict, str, None] = None) -> Flask: app.register_blueprint(menu, url_prefix="/api/menu") app.register_blueprint(search, url_prefix="/api/search") app.register_blueprint(metadata, url_prefix="/api/metadata") + app.register_blueprint(sampledata, url_prefix="/api/sampledata") app.register_blueprint(oauth2, url_prefix="/api/oauth2") register_error_handlers(app) diff --git a/gn3/settings.py b/gn3/settings.py index 5fec562..1de4d27 100644 --- a/gn3/settings.py +++ b/gn3/settings.py @@ -15,6 +15,9 @@ RQTL_WRAPPER = "rqtl_wrapper.R" # SPARQL endpoint SPARQL_ENDPOINT = "http://localhost:8891/sparql" +# LMDB path +LMDB_PATH = os.environ.get( + "LMDB_PATH", f"{os.environ.get('HOME')}/tmp/dataset") # SQL confs SQL_URI = os.environ.get( -- cgit v1.2.3