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

Bug fix: filter on context parameter #131

Merged
merged 2 commits into from
May 29, 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
23 changes: 19 additions & 4 deletions dd-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,14 @@ paths:
example: UBERON
- name: context
in: query
required: true
description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context
required: false
description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context. Sources from base_context are included with other contexts.
schema:
type: string
example: base_context
enum:
- base_context
- hubmap_sennet_context
- data_distillery_context
responses:
'200':
description: An array of Concepts with preferred terms that exactly match the specified string
Expand Down Expand Up @@ -1527,9 +1530,11 @@ components:
description: citation reference
properties:
PMID:
type: string
description: PubMedID, if applicable
example: 37953324
url:
type: string
description: full URL to the citation
example: "https://pubmed.ncbi.nlm.nih.gov/37953324"
contexts:
Expand All @@ -1539,9 +1544,11 @@ components:
type: string
example: base_context
description:
type: string
description: longform description of the source
example: "An ontology for describing the classification of human diseases organized by etiology."
download_date:
type: string
description: Date when the source was obtained, in format YYYY_MM_DD
example: "2024_02_24"
home_urls:
Expand All @@ -1558,26 +1565,34 @@ components:
description: license
properties:
type:
type: string
description: the type of license
example: Creative Commons license (creativecommons.org)
subtype:
type: string
description: the subtype of license
example: CCO
version:
description: the versoin of the license
type: string
description: the version of the license
example: version 4
name:
type: string
description: name of the source
example: Human Disease Ontology
sab:
type: string
description: acronym for Source ABbreviation
example: DOID
source_etl:
type: string
description: the parameter provided to the UBKG generation framework ETL script. For sources that are from OWL files, source_etl is the URL to the OWL; for other sources, source_etl is a command for one of the python scripts that the generation framework uses to import the source.
example: "http://purl.obolibrary.org/obo/doid.owl"
source_type:
type: string
description: The type of source file. Possible values are owl, api, ftp, ubkg_edge_node, umls, and simpleknowledge.
example: owl
source_version:
type: string
description: A reference to the version of the source. If the source is an OWL file, the usual version is the date extracted from the VersionIRI of the file; if from a website, the file date. Dates are in format YYYY_MM_DD.
example: "2024_04_22"
3 changes: 2 additions & 1 deletion src/ubkg_api/common_routes/common_neo4j_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,11 @@ def sources_get_logic(neo4j_instance, sab=None, context=None) -> dict:
querytxt = querytxt.replace('$sabfilter', f" AND t.name IN {sab}")

# Filter by ubkg context.
# JAS 24 May 2024 bug fix - replace t.name with tContext.name
if len(context) == 0:
querytxt = querytxt.replace('$contextfilter', '')
else:
querytxt = querytxt.replace('$contextfilter', f" AND t.name IN {context}")
querytxt = querytxt.replace('$contextfilter', f" AND tContext.name IN {context}")

# Set timeout for query based on value in app.cfg.
query = neo4j.Query(text=querytxt, timeout=neo4j_instance.timeout)
Expand Down
10 changes: 10 additions & 0 deletions src/ubkg_api/common_routes/sources/sources_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ def sources_get():

sab = parameter_as_list(param_name='sab')
context = parameter_as_list(param_name='context')
# JAS 24 May 2024
# Validate context parameter against enum.
val_enum = ['base_context', 'data_distillery_context', 'hubmap_sennet_context']
if context is not None:
for c in context:
c = c.lower()
err = validate_parameter_value_in_enum(param_name='context', param_value=c,
enum_list=val_enum)
if err != 'ok':
return make_response(err, 400)

result = sources_get_logic(neo4j_instance, sab=sab, context=context)
iserr = result is None or result == []
Expand Down
12 changes: 10 additions & 2 deletions tests/test_dd_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1240,15 +1240,23 @@ curl --request GET \
echo | tee -a test.out
echo | tee -a test.out

echo "4. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out
echo "4. /sources?context=x GET => invalid context; should return custom 404" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?context=x" \
--header "Accept: application/json" \
--header "X-API-KEY:$apikey" | cut -c1-60 | tee -a test.out
echo | tee -a test.out
echo | tee -a test.out

echo "5. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?sab=HPOMP" \
--header "Accept: application/json" \
--header "X-API-KEY:$apikey" | cut -c1-60 | tee -a test.out
echo | tee -a test.out
echo | tee -a test.out

echo "5. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out
echo "6. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?context=base_context" \
--header "Accept: application/json" \
Expand Down
15 changes: 11 additions & 4 deletions tests/test_ubkg_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1103,17 +1103,24 @@ curl --request GET \
echo | tee -a test.out
echo | tee -a test.out

echo "4. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out
echo "4. /sources?context=x GET => invalid context; should return custom 400" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?sab=HPOMP" \
--url "${UBKG_URL}/sources?context=x" \
--header "Accept: application/json" | tee -a test.out
echo | tee -a test.out
echo | tee -a test.out

echo "5. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out
echo "5. /sources?sab=HPOMP GET => valid SAB; should return 200" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?sab=HPOMP" \
--header "Accept: application/json" | cut -c1-60 | tee -a test.out
echo | tee -a test.out
echo | tee -a test.out

echo "6. /sources?context=base_context GET => valid context; should return 200" | tee -a test.out
curl --request GET \
--url "${UBKG_URL}/sources?context=base_context" \
--header "Accept: application/json" | tee -a test.out
--header "Accept: application/json" | cut -c1-60 | tee -a test.out
echo | tee -a test.out
echo | tee -a test.out

20 changes: 15 additions & 5 deletions ubkg-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ paths:
description: No Concepts with terms matching the specified string.
'5XX':
description: Unknown error
/sources:
/sources:
get:
operationId: sources_get
summary: Returns a list of Concept nodes with preferred terms that exactly match the specified string.
Expand All @@ -859,11 +859,14 @@ paths:
example: UBERON
- name: context
in: query
required: true
description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context
required: false
description: A UBKG context to which to limit the response. Possible values are base_context, data_distillery_context, hubmap_sennet_context. The sources from base_context are included with any other context.
schema:
type: string
example: base_context
enum:
- base_context
- hubmap_sennet_context
- data_distillery_context
responses:
'200':
description: An array of Concepts with preferred terms that exactly match the specified string
Expand Down Expand Up @@ -1534,9 +1537,11 @@ components:
type: string
example: base_context
description:
type: string
description: longform description of the source
example: "An ontology for describing the classification of human diseases organized by etiology."
download_date:
type: string
description: Date when the source was obtained, in format YYYY_MM_DD
example: "2024_02_24"
home_urls:
Expand All @@ -1559,20 +1564,25 @@ components:
description: the subtype of license
example: CCO
version:
description: the versoin of the license
description: the version of the license
example: version 4
name:
type: string
description: name of the source
example: Human Disease Ontology
sab:
type: string
description: acronym for Source ABbreviation
example: DOID
source_etl:
type: string
description: the parameter provided to the UBKG generation framework ETL script. For sources that are from OWL files, source_etl is the URL to the OWL; for other sources, source_etl is a command for one of the python scripts that the generation framework uses to import the source.
example: "http://purl.obolibrary.org/obo/doid.owl"
source_type:
type: string
description: The type of source file. Possible values are owl, api, ftp, ubkg_edge_node, umls, and simpleknowledge.
example: owl
source_version:
type: string
description: A reference to the version of the source. If the source is an OWL file, the usual version is the date extracted from the VersionIRI of the file; if from a website, the file date. Dates are in format YYYY_MM_DD.
example: "2024_04_22"
Loading