Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reformat repo #77

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions bento_beacon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@

# find path for beacon-v2 spec
app_parent_dir = os.path.dirname(app.root_path)
beacon_request_spec_uri = urlunsplit(
("file", app_parent_dir, REQUEST_SPEC_RELATIVE_PATH, "", ""))
app.config.from_mapping(
BEACON_REQUEST_SPEC_URI=beacon_request_spec_uri
)
beacon_request_spec_uri = urlunsplit(("file", app_parent_dir, REQUEST_SPEC_RELATIVE_PATH, "", ""))
app.config.from_mapping(BEACON_REQUEST_SPEC_URI=beacon_request_spec_uri)

app.config.from_object(Config)

# all logs are printed in dev mode regardless of level
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
logging.StreamHandler()
]
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", handlers=[logging.StreamHandler()]
)

# attach authz middleware to the Flask app
Expand Down Expand Up @@ -72,7 +65,7 @@
count_threshold = None
retries = 0
max_retries = current_app.config["MAX_RETRIES_FOR_CENSORSHIP_PARAMS"]
for tries in range(max_retries+1):
for tries in range(max_retries + 1):
current_app.logger.info(f"calling katsu for censorship parameters (try={tries})")
try:
max_filters, count_threshold = katsu_censorship_settings()
Expand All @@ -83,14 +76,15 @@
# swallow exception and continue retries
current_app.logger.error(f"error calling katsu for censorship settings: {e}")

sleep(5 + 5*tries)
sleep(5 + 5 * tries)

# either params retrieved or we hit max retries
if max_filters is None or count_threshold is None:
current_app.logger.error("unable to retrieve censorship settings from katsu")
else:
current_app.logger.info(
f"retrieved censorship params: max_filter {max_filters}, count_threshold: {count_threshold}")
f"retrieved censorship params: max_filter {max_filters}, count_threshold: {count_threshold}"
)

# save even if None
set_censorship_settings(max_filters, count_threshold)
Expand Down
2 changes: 1 addition & 1 deletion bento_beacon/authz/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Config.AUTHZ_URL,
enabled=Config.AUTHZ_ENABLED,
beacon_meta_callback=middleware_meta_callback,
debug_mode=Config.BENTO_DEBUG
debug_mode=Config.BENTO_DEBUG,
)


Expand Down
110 changes: 52 additions & 58 deletions bento_beacon/config_files/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class Config:
"biosamples": "count",
"cohorts": "record",
"datasets": "record",
"info": "record"
"info": "record",
}

DEFAULT_PAGINATION_PAGE_SIZE = 10

BENTO_DEBUG = os.environ.get("BENTO_DEBUG", os.environ.get(
"FLASK_DEBUG", "false")).strip().lower() in ('true', '1', 't')
BENTO_DEBUG = os.environ.get("BENTO_DEBUG", os.environ.get("FLASK_DEBUG", "false")).strip().lower() in (
"true",
"1",
"t",
)

BENTO_DOMAIN = os.environ.get("BENTOV2_DOMAIN")
BEACON_BASE_URL = os.environ.get("BEACON_BASE_URL")
Expand All @@ -33,7 +36,7 @@ class Config:
BEACON_ID = ".".join(reversed(BENTO_DOMAIN.split("."))) + ".beacon"

BEACON_NAME = os.environ.get("BENTO_PUBLIC_CLIENT_NAME", "Bento") + " Beacon"
BEACON_UI_ENABLED = os.environ.get("BENTO_BEACON_UI_ENABLED").strip().lower() in ('true', '1', 't')
BEACON_UI_ENABLED = os.environ.get("BENTO_BEACON_UI_ENABLED").strip().lower() in ("true", "1", "t")
BEACON_UI_URL = BENTO_PUBLIC_URL + "/#/en/beacon"

ENTRY_TYPES_DETAILS = {
Expand All @@ -44,10 +47,10 @@ class Config:
"defaultSchema": {
"id": "ga4gh-beacon-biosample-v2.0.0",
"name": "Default schema for biosamples",
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/biosamples/defaultSchema.json",
"schemaVersion": "v2.0.0"
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/biosamples/defaultSchema.json",
"schemaVersion": "v2.0.0",
},
"partOfSpecification": "Beacon v2.0.0"
"partOfSpecification": "Beacon v2.0.0",
},
"cohorts": {
"entryType": "cohort",
Expand All @@ -56,84 +59,80 @@ class Config:
"defaultSchema": {
"id": "ga4gh-beacon-cohort-v2.0.0",
"name": "Default schema for cohorts",
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/cohorts/defaultSchema.json",
"schemaVersion": "v2.0.0"
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/cohorts/defaultSchema.json",
"schemaVersion": "v2.0.0",
},
"partOfSpecification": "Beacon v2.0.0"

"partOfSpecification": "Beacon v2.0.0",
},
"datasets": {
"entryType": "dataset",
"name": "Dataset",
"ontologyTermForThisType": {"id": "NCIT:C47824", "label": "Data set"},
"ontologyTermForThisType": {"id": "NCIT:C47824", "label": "Data set"},
"defaultSchema": {
"id": "ga4gh-beacon-dataset-v2.0.0",
"name": "Default schema for datasets",
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/datasets/defaultSchema.json",
"schemaVersion": "v2.0.0"
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/datasets/defaultSchema.json",
"schemaVersion": "v2.0.0",
},
"partOfSpecification": "Beacon v2.0.0"

"partOfSpecification": "Beacon v2.0.0",
},
"individuals": {
"entryType": "individual",
"name": "Individual",
"ontologyTermForThisType": {"id": "NCIT:C25190", "label": "Person"},
"ontologyTermForThisType": {"id": "NCIT:C25190", "label": "Person"},
"defaultSchema": {
"id": "phenopacket-v2",
"name": "phenopacket v2",
"referenceToSchemaDefinition": f"{BEACON_BASE_URL}/individual_schema",
"schemaVersion": "v2.0.0"
"referenceToSchemaDefinition": f"{BEACON_BASE_URL}/individual_schema",
"schemaVersion": "v2.0.0",
},
"partOfSpecification": "Phenopacket v1"
"partOfSpecification": "Phenopacket v1",
},
"variants": {
"entryType": "genomicVariation",
"name": "Genomic Variant",
"ontologyTermForThisType": {"id": "ENSGLOSSARY:0000092", "label": "Variant"},
"ontologyTermForThisType": {"id": "ENSGLOSSARY:0000092", "label": "Variant"},
"defaultSchema": {
"id": "ga4gh-beacon-variant-v2.0.0",
"name": "Default schema for a genomic variation",
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/genomicVariations/defaultSchema.json",
"schemaVersion": "v2.0.0"
"referenceToSchemaDefinition": f"{GA4GH_BEACON_REPO_URL}/main/models/json/beacon-v2-default-model/genomicVariations/defaultSchema.json",
"schemaVersion": "v2.0.0",
},
"partOfSpecification": "Beacon v2.0.0"

}
"partOfSpecification": "Beacon v2.0.0",
},
}

INFO_ENDPOINTS_SCHEMAS = {
"/": {
"/": {
"entityType": "info",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconInfoResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconInfoResponse.json",
},
"/configuration": {
"entityType": "configuration",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconConfigurationResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconConfigurationResponse.json",
},
"/entry_types": {
"entityType": "entryType",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconEntryTypesResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconEntryTypesResponse.json",
},
"/filtering_terms": {
"entityType": "filteringTerm",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconFilteringTermsResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconFilteringTermsResponse.json",
},
"/info": {
"entityType": "info",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconInfoResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconInfoResponse.json",
},
"/map": {
"entityType": "map",
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconMapResponse.json"
"schema": f"{GA4GH_BEACON_REPO_URL}/main/framework/json/responses/beaconMapResponse.json",
},
"/overview": {}
"/overview": {},
}
# -------------------
# katsu
# -------------------
# katsu

KATSU_BASE_URL = os.environ.get(
"KATSU_BASE_URL")
KATSU_BASE_URL = os.environ.get("KATSU_BASE_URL")
KATSU_BIOSAMPLES_ENDPOINT = "/api/biosamples"
KATSU_INDIVIDUALS_ENDPOINT = "/api/individuals"
KATSU_BATCH_INDIVIDUALS_ENDPOINT = "/api/batch/individuals"
Expand All @@ -152,45 +151,40 @@ class Config:
KATSU_PUBLIC_OVERVIEW = "/api/public_overview"
KATSU_TIMEOUT = int(os.environ.get("BEACON_KATSU_TIMEOUT", 180))

MAP_EXTRA_PROPERTIES_TO_INFO = os.environ.get(
"MAP_EXTRA_PROPERTIES_TO_INFO", True)
MAP_EXTRA_PROPERTIES_TO_INFO = os.environ.get("MAP_EXTRA_PROPERTIES_TO_INFO", True)

PHENOPACKETS_SCHEMA_REFERENCE = {
"entityType": "individual",
"schema": "phenopackets v1"
}
PHENOPACKETS_SCHEMA_REFERENCE = {"entityType": "individual", "schema": "phenopackets v1"}

MAX_RETRIES_FOR_CENSORSHIP_PARAMS = 2
# -------------------
# gohan
# -------------------
# gohan

GOHAN_BASE_URL = os.environ.get("GOHAN_BASE_URL")
GOHAN_SEARCH_ENDPOINT = "/variants/get/by/variantId"
GOHAN_COUNT_ENDPOINT = "/variants/count/by/variantId"
GOHAN_OVERVIEW_ENDPOINT = "/variants/overview"
GOHAN_TIMEOUT = int(os.environ.get("BEACON_GOHAN_TIMEOUT", 60))

# -------------------
# drs
# -------------------
# drs

DRS_URL = os.environ.get("DRS_URL")

# -------------------
# authorization
# -------------------
# authorization

AUTHZ_URL: str = os.environ.get("BENTO_AUTHZ_SERVICE_URL", "")
AUTHZ_ENABLED: bool = os.environ.get("AUTHZ_ENABLED", "true").strip().lower() in ("true", "1", "yes")

# -------------------
# handle injected config files
# a) obtain reference to the expected configuration files' location by
# using the programmable env variable `CONFIG_ABSOLUTE_PATH` if it exists, or
# b) default to using "this file's directory" as the reference to where
# configuration files are expected to be located
# -------------------
# handle injected config files
# a) obtain reference to the expected configuration files' location by
# using the programmable env variable `CONFIG_ABSOLUTE_PATH` if it exists, or
# b) default to using "this file's directory" as the reference to where
# configuration files are expected to be located
def retrieve_config_json(filename):
# TODO: abstract out CONFIG_PATH if needed
config_path = os.environ.get(
"CONFIG_ABSOLUTE_PATH", os.path.dirname(os.path.abspath(__file__)))
config_path = os.environ.get("CONFIG_ABSOLUTE_PATH", os.path.dirname(os.path.abspath(__file__)))
print(f"Searching for file {filename} in {config_path}")
file_path = os.path.join(config_path, filename)
try:
Expand Down
10 changes: 5 additions & 5 deletions bento_beacon/endpoints/biosamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
biosamples = Blueprint("biosamples", __name__)


@biosamples.route("/biosamples", methods=['GET', 'POST'])
@biosamples.route("/biosamples", methods=["GET", "POST"])
def get_biosamples(): # TODO: authz
raise NotImplemented()


@biosamples.route("/biosamples/<id>", methods=['GET', 'POST'])
@biosamples.route("/biosamples/<id>", methods=["GET", "POST"])
def get_katsu_biosamples_by_id(id): # TODO: authz
raise NotImplemented()


@biosamples.route("/biosamples/<id>/g_variants", methods=['GET', 'POST'])
@biosamples.route("/biosamples/<id>/g_variants", methods=["GET", "POST"])
def variants_by_biosample(id): # TODO: authz
raise NotImplemented()


@biosamples.route("/biosamples/<id>/analyses", methods=['GET', 'POST'])
@biosamples.route("/biosamples/<id>/analyses", methods=["GET", "POST"])
def analyses_by_biosample(id): # TODO: authz
raise NotImplemented()


@biosamples.route("/biosamples/<id>/runs", methods=['GET', 'POST'])
@biosamples.route("/biosamples/<id>/runs", methods=["GET", "POST"])
def runs_by_biosample(id): # TODO: authz
raise NotImplemented()
4 changes: 2 additions & 2 deletions bento_beacon/endpoints/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
cohorts = Blueprint("cohorts", __name__)


@cohorts.route("/cohorts", methods=['GET', 'POST'])
@cohorts.route("/cohorts", methods=["GET", "POST"])
@authz_middleware.deco_public_endpoint
def get_cohorts():
cohorts = current_app.config["BEACON_COHORT"]
return beacon_collections_response({"collections": cohorts})


@cohorts.route("/cohorts/<id>", methods=['GET', 'POST'])
@cohorts.route("/cohorts/<id>", methods=["GET", "POST"])
@authz_middleware.deco_public_endpoint
def get_cohort_by_id(id):
cohorts = current_app.config["BEACON_COHORT"]
Expand Down
4 changes: 2 additions & 2 deletions bento_beacon/endpoints/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
datasets = Blueprint("datasets", __name__)


@datasets.route("/datasets", methods=['GET', 'POST'])
@datasets.route("/datasets", methods=["GET", "POST"])
@authz_middleware.deco_public_endpoint # TODO: authz - more flexibility in what is visible (?)
def get_datasets():
k_datasets = katsu_datasets()
datasets_beacon_format = list(map(katsu_to_beacon_dataset_mapping, k_datasets))
return beacon_collections_response({"collections": datasets_beacon_format})


@datasets.route("/datasets/<id>", methods=['GET', 'POST'])
@datasets.route("/datasets/<id>", methods=["GET", "POST"])
@authz_middleware.deco_public_endpoint # TODO: authz - more flexibility in what is visible (?)
def get_datasets_by_id(id):
k_dataset = katsu_datasets(id)
Expand Down
15 changes: 6 additions & 9 deletions bento_beacon/endpoints/individuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
)
from flask import Blueprint
from functools import reduce
from ..authz.middleware import (
authz_middleware,
check_permission
)
from ..authz.middleware import authz_middleware, check_permission
from ..utils.beacon_request import (
query_parameters_from_request,
summary_stats_requested,
Expand All @@ -18,13 +15,13 @@
add_overview_stats_to_response,
zero_count_response,
build_query_response,
beacon_result_set_response
beacon_result_set_response,
)
from ..utils.katsu_utils import (
katsu_filters_and_sample_ids_query,
katsu_total_individuals_count,
search_from_config,
phenopackets_for_ids
phenopackets_for_ids,
)
from ..utils.search import biosample_id_search
from ..utils.handover_utils import handover_for_ids
Expand All @@ -33,7 +30,7 @@
individuals = Blueprint("individuals", __name__)


@individuals.route("/individuals", methods=['GET', 'POST'])
@individuals.route("/individuals", methods=["GET", "POST"])
def get_individuals():
variants_query, phenopacket_filters, experiment_filters, config_filters = query_parameters_from_request()

Expand Down Expand Up @@ -124,7 +121,7 @@ def individuals_full_results(ids):


# forbidden / unauthorized if no permissions
@individuals.route("/individuals/<id>", methods=['GET', 'POST'])
@individuals.route("/individuals/<id>", methods=["GET", "POST"])
@authz_middleware.deco_require_permissions_on_resource({P_QUERY_DATA})
def individual_by_id(id):
result_sets, numTotalResults = individuals_full_results([id])
Expand All @@ -133,7 +130,7 @@ def individual_by_id(id):
# only authorized users will get 404 here, so this can't be used to probe ids
if not result_sets:
raise NotFoundException()

return beacon_result_set_response(result_sets, numTotalResults)


Expand Down
Loading