From 300b62ba1505435fa55f20f400d3dea5b0d17894 Mon Sep 17 00:00:00 2001 From: MalinAhlberg Date: Thu, 9 May 2019 13:48:29 +0200 Subject: [PATCH 1/4] Allow for configurable sample queries --- beacon_api/__init__.py | 4 +++- beacon_api/api/info.py | 5 +++-- beacon_api/conf/__init__.py | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/beacon_api/__init__.py b/beacon_api/__init__.py index 77e24208..368b58c4 100644 --- a/beacon_api/__init__.py +++ b/beacon_api/__init__.py @@ -5,7 +5,7 @@ """ import datetime -from .conf import CONFIG_INFO +from .conf import CONFIG_INFO, SAMPLE_QUERIES __title__ = CONFIG_INFO.title __version__ = CONFIG_INFO.version @@ -34,3 +34,5 @@ __org_contactUrl__ = CONFIG_INFO.org_contactUrl __org_logoUrl__ = CONFIG_INFO.org_logoUrl __org_info__ = {'orgInfo': CONFIG_INFO.org_info} + +__sample_queries__ = SAMPLE_QUERIES diff --git a/beacon_api/api/info.py b/beacon_api/api/info.py index 7201d74f..e6d06c0a 100644 --- a/beacon_api/api/info.py +++ b/beacon_api/api/info.py @@ -9,7 +9,7 @@ from .. import __apiVersion__, __title__, __version__, __description__, __url__, __alturl__, __handover_beacon__ from .. import __createtime__, __updatetime__, __org_id__, __org_name__, __org_description__ from .. import __org_address__, __org_logoUrl__, __org_welcomeUrl__, __org_info__, __org_contactUrl__ -from .. import __handover_drs__ +from .. import __sample_queries__,__handover_drs__ from ..utils.data_query import fetch_dataset_metadata from ..extensions.handover import make_handover from aiocache import cached @@ -25,6 +25,7 @@ async def beacon_info(host, pool): beacon_dataset = await fetch_dataset_metadata(pool) # If one sets up a beacon it is recommended to adjust these sample requests + # for instance by adding a list of other samples in beacon_api/conf/sample_queries.json sample_allele_request = [{ "alternateBases": "G", "referenceBases": "A", @@ -75,7 +76,7 @@ async def beacon_info(host, pool): 'createDateTime': __createtime__, 'updateDateTime': __updatetime__, 'datasets': beacon_dataset, - 'sampleAlleleRequests': sample_allele_request, + 'sampleAlleleRequests': __sample_queries__ or sample_allele_request, 'info': {"achievement": "World's first 1.0 Beacon"}, } diff --git a/beacon_api/conf/__init__.py b/beacon_api/conf/__init__.py index 6a764d17..c89d117c 100644 --- a/beacon_api/conf/__init__.py +++ b/beacon_api/conf/__init__.py @@ -1,5 +1,6 @@ """Beacon Python Application Configuration.""" +import json import os from configparser import ConfigParser from collections import namedtuple @@ -58,3 +59,6 @@ def parse_oauth2_config_file(path): OAUTH2_CONFIG = parse_oauth2_config_file(os.environ.get('CONFIG_FILE', os.path.join(os.path.dirname(__file__), 'config.ini'))) + +sampleq_file = os.environ.get('SAMPLEQUERY_FILE', os.path.join(os.path.dirname(__file__), 'sample_queries.json')) +SAMPLE_QUERIES = json.load(open(sampleq_file)) if os.path.isfile(sampleq_file) else [] From 572a165a11ff3efe0265e92e690f244731fc8d23 Mon Sep 17 00:00:00 2001 From: MalinAhlberg Date: Mon, 13 May 2019 11:16:24 +0200 Subject: [PATCH 2/4] Add missing whitespace --- beacon_api/api/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_api/api/info.py b/beacon_api/api/info.py index e6d06c0a..bb92b002 100644 --- a/beacon_api/api/info.py +++ b/beacon_api/api/info.py @@ -9,7 +9,7 @@ from .. import __apiVersion__, __title__, __version__, __description__, __url__, __alturl__, __handover_beacon__ from .. import __createtime__, __updatetime__, __org_id__, __org_name__, __org_description__ from .. import __org_address__, __org_logoUrl__, __org_welcomeUrl__, __org_info__, __org_contactUrl__ -from .. import __sample_queries__,__handover_drs__ +from .. import __sample_queries__, __handover_drs__ from ..utils.data_query import fetch_dataset_metadata from ..extensions.handover import make_handover from aiocache import cached From a528bdad9a795985f6417dd044b5bd2b2f7a2299 Mon Sep 17 00:00:00 2001 From: MalinAhlberg Date: Mon, 13 May 2019 11:22:18 +0200 Subject: [PATCH 3/4] Remove whitespace --- beacon_api/api/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_api/api/info.py b/beacon_api/api/info.py index bb92b002..4686f0e5 100644 --- a/beacon_api/api/info.py +++ b/beacon_api/api/info.py @@ -9,7 +9,7 @@ from .. import __apiVersion__, __title__, __version__, __description__, __url__, __alturl__, __handover_beacon__ from .. import __createtime__, __updatetime__, __org_id__, __org_name__, __org_description__ from .. import __org_address__, __org_logoUrl__, __org_welcomeUrl__, __org_info__, __org_contactUrl__ -from .. import __sample_queries__, __handover_drs__ +from .. import __sample_queries__, __handover_drs__ from ..utils.data_query import fetch_dataset_metadata from ..extensions.handover import make_handover from aiocache import cached From df62b84de9df894486dcf9ca9ed9cad59d5ea7de Mon Sep 17 00:00:00 2001 From: MalinAhlberg Date: Mon, 13 May 2019 12:35:53 +0200 Subject: [PATCH 4/4] Add comment about sample structure Co-Authored-By: Teemu Kataja --- beacon_api/conf/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_api/conf/__init__.py b/beacon_api/conf/__init__.py index c89d117c..ac8703b7 100644 --- a/beacon_api/conf/__init__.py +++ b/beacon_api/conf/__init__.py @@ -59,6 +59,6 @@ def parse_oauth2_config_file(path): OAUTH2_CONFIG = parse_oauth2_config_file(os.environ.get('CONFIG_FILE', os.path.join(os.path.dirname(__file__), 'config.ini'))) - +# Sample query file should be of format [{BeaconAlleleRequest}] https://github.com/ga4gh-beacon/specification/ sampleq_file = os.environ.get('SAMPLEQUERY_FILE', os.path.join(os.path.dirname(__file__), 'sample_queries.json')) SAMPLE_QUERIES = json.load(open(sampleq_file)) if os.path.isfile(sampleq_file) else []