Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
Elasticsearch Proxy API
Commits
e4796ea1
Commit
e4796ea1
authored
Jun 30, 2021
by
David Mendez
Browse files
Related Entities: add tests for links from drug warnings
parent
4b9b286d
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
116 additions
and
12 deletions
+116
-12
app/entities_joiner/entities_joiner.py
app/entities_joiner/entities_joiner.py
+21
-0
app/entities_joiner/standardisation.py
app/entities_joiner/standardisation.py
+23
-2
app/swagger/swagger.yaml
app/swagger/swagger.yaml
+2
-2
functional_tests/specific_tests/entities_join/fun_test_entities_join_3.py
.../specific_tests/entities_join/fun_test_entities_join_3.py
+2
-2
functional_tests/specific_tests/entities_join/fun_test_entities_join_4.py
.../specific_tests/entities_join/fun_test_entities_join_4.py
+22
-0
functional_tests/specific_tests/entities_join/fun_test_entities_join_5.py
.../specific_tests/entities_join/fun_test_entities_join_5.py
+22
-0
functional_tests/specific_tests/entities_join/fun_test_entities_join_6.py
.../specific_tests/entities_join/fun_test_entities_join_6.py
+22
-0
functional_tests/specific_tests/entities_join/fun_test_entities_join_all_tests.py
...c_tests/entities_join/fun_test_entities_join_all_tests.py
+2
-2
functional_tests/specific_tests/entities_join/utils.py
functional_tests/specific_tests/entities_join/utils.py
+0
-4
No files found.
app/entities_joiner/entities_joiner.py
View file @
e4796ea1
...
...
@@ -3,10 +3,13 @@ Module with functions to make joins of entities
"""
import
json
import
base64
from
datetime
import
datetime
from
app.entities_joiner
import
standardisation
from
app.entities_joiner
import
ids_loader
from
app.url_shortening
import
url_shortener
from
app.config
import
RUN_CONFIG
from
app.usage_statistics
import
statistics_saver
class
EntitiesJoinerError
(
Exception
):
...
...
@@ -76,6 +79,7 @@ def get_tiny_hash_to_related_items(destination_entity_browser_state_template,
destination_entity_browser_state_template
,
previous_hash
)
save_statistics
(
entity_from
,
entity_to
,
len
(
ids
))
return
join_state_hash
...
...
@@ -139,3 +143,20 @@ def get_destination_url_hash(hashable_part):
shortening_response
=
url_shortener
.
shorten_url
(
hashable_part
)
return
shortening_response
[
'hash'
]
def
save_statistics
(
raw_entity_from
,
raw_entity_to
,
num_ids
):
"""
:param raw_entity_from: source entity of the items
:param raw_entity_to: destination entity of the join
:param num_ids: number of ids joined
"""
statistics_document
=
{
'entity_from'
:
raw_entity_from
,
'entity_to'
:
raw_entity_to
,
'num_ids'
:
num_ids
,
'request_date'
:
datetime
.
utcnow
().
timestamp
()
*
1000
,
}
index_name
=
RUN_CONFIG
.
get
(
'usage_statistics'
).
get
(
'entities_join_statistics_index'
)
statistics_saver
.
save_record_to_elasticsearch
(
statistics_document
,
index_name
)
app/entities_joiner/standardisation.py
View file @
e4796ea1
...
...
@@ -30,6 +30,9 @@ class PossibleEntitiesTo(Enum):
CHEMBL_CELL_LINES
=
'CHEMBL_CELL_LINES'
CHEMBL_TISSUES
=
'CHEMBL_TISSUES'
CHEMBL_DRUG_WARNINGS
=
'CHEMBL_DRUG_WARNINGS'
CHEMBL_DRUGS
=
'CHEMBL_DRUGS'
CHEMBL_DRUG_MECHANISMS
=
'CHEMBL_DRUG_MECHANISMS'
CHEMBL_DRUG_INDICATIONS
=
'CHEMBL_DRUG_INDICATIONS'
class
SelectionModes
(
Enum
):
...
...
@@ -73,6 +76,18 @@ JOIN_PROPERTIES = {
PossibleEntitiesTo
.
CHEMBL_COMPOUNDS
:
{
'from_property'
:
'drug_warning.molecule_chembl_id'
,
'to_property'
:
'molecule_chembl_id'
},
PossibleEntitiesTo
.
CHEMBL_DRUGS
:
{
'from_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'to_property'
:
'molecule_chembl_id'
},
PossibleEntitiesTo
.
CHEMBL_DRUG_MECHANISMS
:
{
'from_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'to_property'
:
'molecule_chembl_id'
},
PossibleEntitiesTo
.
CHEMBL_DRUG_INDICATIONS
:
{
'from_property'
:
'drug_warning.parent_molecule_chembl_id'
,
'to_property'
:
'molecule_chembl_id'
}
}
}
...
...
@@ -82,12 +97,18 @@ JOIN_PROPERTIES = {
# This is used by the frontend to know which settings use to load the page, should be discarded in the future
SETTINGS_PATHS_FOR_TO_ENTITIES
=
{
PossibleEntitiesTo
.
CHEMBL_ACTIVITIES
:
'ES_INDEXES_NO_MAIN_SEARCH.ACTIVITY'
,
PossibleEntitiesTo
.
CHEMBL_COMPOUNDS
:
'ES_INDEXES_NO_MAIN_SEARCH.COMPOUND_COOL_CARDS'
PossibleEntitiesTo
.
CHEMBL_COMPOUNDS
:
'ES_INDEXES_NO_MAIN_SEARCH.COMPOUND_COOL_CARDS'
,
PossibleEntitiesTo
.
CHEMBL_DRUGS
:
'ES_INDEXES_NO_MAIN_SEARCH.DRUGS_LIST'
,
PossibleEntitiesTo
.
CHEMBL_DRUG_MECHANISMS
:
'ES_INDEXES_NO_MAIN_SEARCH.MECHANISMS_OF_ACTION'
,
PossibleEntitiesTo
.
CHEMBL_DRUG_INDICATIONS
:
'ES_INDEXES_NO_MAIN_SEARCH.DRUG_INDICATIONS'
}
BROWSER_NAMES_FOR_TO_ENTITIES
=
{
PossibleEntitiesTo
.
CHEMBL_ACTIVITIES
:
'activities'
,
PossibleEntitiesTo
.
CHEMBL_COMPOUNDS
:
'compounds'
PossibleEntitiesTo
.
CHEMBL_COMPOUNDS
:
'compounds'
,
PossibleEntitiesTo
.
CHEMBL_DRUGS
:
'drugs'
,
PossibleEntitiesTo
.
CHEMBL_DRUG_MECHANISMS
:
'mechanisms_of_action'
,
PossibleEntitiesTo
.
CHEMBL_DRUG_INDICATIONS
:
'drug_indications'
}
...
...
app/swagger/swagger.yaml
View file @
e4796ea1
...
...
@@ -515,14 +515,14 @@ paths:
description
:
'
Source
entity
for
the
join.'
required
:
true
type
:
'
string'
enum
:
[
'
CHEMBL_ACTIVITIES'
,
'
CHEMBL_COMPOUNDS'
,
'
CHEMBL_TARGETS'
,
'
CHEMBL_ASSAYS'
,
'
CHEMBL_DOCUMENTS'
,
'
CHEMBL_CELL_LINES'
,
'
CHEMBL_TISSUES'
,
'
CHEMBL_DRUG_WARNINGS'
]
enum
:
[
'
CHEMBL_ACTIVITIES'
,
'
CHEMBL_COMPOUNDS'
,
'
CHEMBL_TARGETS'
,
'
CHEMBL_ASSAYS'
,
'
CHEMBL_DOCUMENTS'
,
'
CHEMBL_CELL_LINES'
,
'
CHEMBL_TISSUES'
,
'
CHEMBL_DRUG_WARNINGS'
,
'
CHEMBL_DRUGS'
]
default
:
'
CHEMBL_COMPOUNDS'
-
name
:
'
entity_to'
in
:
'
formData'
description
:
'
The
entity
in
ChEMBL
to
do
the
join
with.'
required
:
true
type
:
'
string'
enum
:
[
'
CHEMBL_ACTIVITIES'
,
'
CHEMBL_COMPOUNDS'
,
'
CHEMBL_TARGETS'
,
'
CHEMBL_ASSAYS'
,
'
CHEMBL_DOCUMENTS'
,
'
CHEMBL_CELL_LINES'
,
'
CHEMBL_TISSUES'
,
'
CHEMBL_DRUG_WARNINGS'
]
enum
:
[
'
CHEMBL_ACTIVITIES'
,
'
CHEMBL_COMPOUNDS'
,
'
CHEMBL_TARGETS'
,
'
CHEMBL_ASSAYS'
,
'
CHEMBL_DOCUMENTS'
,
'
CHEMBL_CELL_LINES'
,
'
CHEMBL_TISSUES'
,
'
CHEMBL_DRUG_WARNINGS'
,
'
CHEMBL_DRUGS'
,
'
CHEMBL_DRUG_MECHANISMS'
,
'
CHEMBL_DRUG_INDICATIONS'
]
default
:
'
CHEMBL_COMPOUNDS'
-
name
:
'
es_query'
in
:
'
formData'
...
...
functional_tests/specific_tests/entities_join/fun_test_entities_join_3.py
View file @
e4796ea1
# pylint: disable=import-error
"""
Module that tests the endpoints to do joins among entities
selecting no ids except some
Module that tests the endpoints to do joins among entities
from drug warnings to compounds
"""
from
specific_tests
import
utils
from
specific_tests.entities_join
import
utils
as
entities_join_utils
...
...
@@ -8,7 +8,7 @@ from specific_tests.entities_join import utils as entities_join_utils
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests doing a join among different entities
selecting no ids except some
Tests doing a join among different entities
from drug warnings to compounds
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
...
...
functional_tests/specific_tests/entities_join/fun_test_entities_join_4.py
0 → 100644
View file @
e4796ea1
# pylint: disable=import-error
"""
Module that tests the endpoints to do joins among entities from drug warnings to compounds
"""
from
specific_tests
import
utils
from
specific_tests.entities_join
import
utils
as
entities_join_utils
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests doing a join among different entities from drug warnings to compounds
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
print
(
'-------------------------------------------'
)
print
(
'Testing joins among entities selecting all none except'
)
print
(
'-------------------------------------------'
)
dataset_query
=
utils
.
load_json_data
(
'functional_tests/specific_tests/data/entities_join_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
"exceptions"
:
[]}
entities_join_utils
.
test_entities_join
(
dataset_query
,
selection_description
,
server_base_url
,
entity_from
=
'CHEMBL_DRUG_WARNINGS'
,
entity_to
=
'CHEMBL_DRUGS'
)
functional_tests/specific_tests/entities_join/fun_test_entities_join_5.py
0 → 100644
View file @
e4796ea1
# pylint: disable=import-error
"""
Module that tests the endpoints to do joins among entities from drug warnings to drug indications
"""
from
specific_tests
import
utils
from
specific_tests.entities_join
import
utils
as
entities_join_utils
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests doing a join among different entities from drug warnings to drug indications
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
print
(
'-------------------------------------------'
)
print
(
'Testing joins among entities selecting all none except'
)
print
(
'-------------------------------------------'
)
dataset_query
=
utils
.
load_json_data
(
'functional_tests/specific_tests/data/entities_join_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
"exceptions"
:
[]}
entities_join_utils
.
test_entities_join
(
dataset_query
,
selection_description
,
server_base_url
,
entity_from
=
'CHEMBL_DRUG_WARNINGS'
,
entity_to
=
'CHEMBL_DRUG_INDICATIONS'
)
functional_tests/specific_tests/entities_join/fun_test_entities_join_6.py
0 → 100644
View file @
e4796ea1
# pylint: disable=import-error
"""
Module that tests the endpoints to do joins among entities from drug warnings to drug indications
"""
from
specific_tests
import
utils
from
specific_tests.entities_join
import
utils
as
entities_join_utils
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests doing a join among different entities from drug warnings to drug mechanisms
:param server_base_url: base url of the running server. E.g. http://127.0.0.1:5000
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
print
(
'-------------------------------------------'
)
print
(
'Testing joins among entities selecting all none except'
)
print
(
'-------------------------------------------'
)
dataset_query
=
utils
.
load_json_data
(
'functional_tests/specific_tests/data/entities_join_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
"exceptions"
:
[]}
entities_join_utils
.
test_entities_join
(
dataset_query
,
selection_description
,
server_base_url
,
entity_from
=
'CHEMBL_DRUG_WARNINGS'
,
entity_to
=
'CHEMBL_DRUG_MECHANISMS'
)
functional_tests/specific_tests/entities_join/fun_test_entities_join_all_tests.py
View file @
e4796ea1
...
...
@@ -2,7 +2,7 @@
Module that runs all the tests related to the entities join
"""
from
specific_tests.entities_join
import
fun_test_entities_join_0
,
fun_test_entities_join_1
,
fun_test_entities_join_2
,
\
fun_test_entities_join_3
fun_test_entities_join_3
,
fun_test_entities_join_4
,
fun_test_entities_join_5
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
...
...
@@ -12,5 +12,5 @@ def run_test(server_base_url, delayed_jobs_server_base_path):
:param delayed_jobs_server_base_path: base path for the delayed_jobs
"""
for
test_module
in
[
fun_test_entities_join_0
,
fun_test_entities_join_1
,
fun_test_entities_join_2
,
fun_test_entities_join_3
]:
fun_test_entities_join_3
,
fun_test_entities_join_4
,
fun_test_entities_join_5
]:
test_module
.
run_test
(
server_base_url
,
delayed_jobs_server_base_path
)
functional_tests/specific_tests/entities_join/utils.py
View file @
e4796ea1
...
...
@@ -30,20 +30,16 @@ def test_entities_join(dataset_query, selection_description, server_base_url, en
request
=
requests
.
post
(
url
,
data
=
join_params
)
status_code
=
request
.
status_code
print
(
f
'status_code:
{
status_code
}
'
)
response_text
=
request
.
text
utils
.
print_es_response
(
response_text
)
assert
status_code
==
200
,
'The request failed!'
url_hash_got
=
request
.
json
()[
'tiny_hash'
]
print
(
'url_hash_got: '
,
url_hash_got
)
expansion_url
=
f
'
{
server_base_url
}
/url_shortening/expand_url/
{
url_hash_got
}
'
print
(
f
'Checking tiny hash:
{
expansion_url
}
'
)
request
=
requests
.
get
(
expansion_url
)
status_code
=
request
.
status_code
print
(
f
'status_code:
{
status_code
}
'
)
response_text
=
request
.
text
utils
.
print_es_response
(
response_text
)
assert
status_code
==
200
,
'The request failed!'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment