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
a8b612ac
Commit
a8b612ac
authored
Jun 11, 2021
by
David Mendez
Browse files
Entities Joiner: implement getting ids query for none except some
parent
23b2075a
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
76 deletions
+187
-76
app/entities_joiner/entities_joiner.py
app/entities_joiner/entities_joiner.py
+1
-0
app/entities_joiner/ids_loader.py
app/entities_joiner/ids_loader.py
+60
-17
app/entities_joiner/test/data/sample_query_0.json
app/entities_joiner/test/data/sample_query_0.json
+22
-0
app/entities_joiner/test/test_ids_loader.py
app/entities_joiner/test/test_ids_loader.py
+42
-46
functional_tests/run_functional_tests.py
functional_tests/run_functional_tests.py
+2
-10
functional_tests/specific_tests/fun_test_entities_join_0.py
functional_tests/specific_tests/fun_test_entities_join_0.py
+60
-3
No files found.
app/entities_joiner/entities_joiner.py
View file @
a8b612ac
...
...
@@ -49,4 +49,5 @@ def get_tiny_hash_to_related_items(destination_entity_browser_state_template,
if
entity_to
==
entity_from
:
raise
EntitiesJoinerError
(
f
'entity_to (
{
entity_to
}
) and entity_from (
{
entity_from
}
) cannot be the same!'
)
print
(
'get_tiny_hash_to_related_items'
)
return
'holaaaa'
app/entities_joiner/ids_loader.py
View file @
a8b612ac
...
...
@@ -17,22 +17,65 @@ def get_ids_query(es_query, selection_description, from_property):
if
parsed_selection_mode
==
standardisation
.
SelectionModes
.
ALL_ITEMS_EXCEPT
:
if
len
(
exceptions
)
==
0
:
return
{
'query'
:
es_query
.
get
(
'query'
),
"_source"
:
[
from_property
],
}
return
get_ids_query_for_all_items
(
es_query
,
from_property
)
else
:
dataset_query
=
es_query
.
get
(
'query'
)
if
dataset_query
.
get
(
'bool'
)
is
None
:
dataset_query
[
'bool'
]
=
{}
if
dataset_query
.
get
(
'bool'
).
get
(
'must_not'
)
is
None
:
dataset_query
[
'bool'
][
'must_not'
]
=
[]
dataset_query
[
'bool'
][
'must_not'
].
append
({
'terms'
:
{
from_property
:
exceptions
}
})
return
{
'query'
:
dataset_query
,
"_source"
:
[
from_property
],
return
get_ids_query_for_all_items_except_some
(
es_query
,
from_property
,
exceptions
)
# Selecting none except some
return
get_ids_query_for_no_items_except_some
(
es_query
,
from_property
,
exceptions
)
def
get_ids_query_for_all_items
(
es_query
,
from_property
):
"""
:param es_query: uery for the dataset
:param from_property: property to get to to the join
:return: the ids query for all items
"""
return
{
'query'
:
es_query
.
get
(
'query'
),
"_source"
:
[
from_property
],
}
def
get_ids_query_for_all_items_except_some
(
es_query
,
from_property
,
exceptions
):
"""
:param es_query: query for the dataset
:param from_property: property to get to to the join
:param exceptions: selection exceptions
:return: the ids query for all items except some
"""
dataset_query
=
es_query
.
get
(
'query'
)
if
dataset_query
.
get
(
'bool'
)
is
None
:
dataset_query
[
'bool'
]
=
{}
if
dataset_query
.
get
(
'bool'
).
get
(
'must_not'
)
is
None
:
dataset_query
[
'bool'
][
'must_not'
]
=
[]
dataset_query
[
'bool'
][
'must_not'
].
append
({
'terms'
:
{
from_property
:
exceptions
}
})
return
{
'query'
:
dataset_query
,
"_source"
:
[
from_property
],
}
def
get_ids_query_for_no_items_except_some
(
es_query
,
from_property
,
exceptions
):
"""
:param es_query: query for the dataset
:param from_property: property to get to to the join
:param exceptions: selection exceptions
:return: the ids query for all items except some
"""
dataset_query
=
es_query
.
get
(
'query'
)
dataset_query
[
'bool'
]
=
{
'filter'
:
[{
'terms'
:
{
from_property
:
exceptions
}
}]
}
return
{
'query'
:
dataset_query
,
"_source"
:
[
from_property
],
}
app/entities_joiner/test/data/sample_query_0.json
0 → 100644
View file @
a8b612ac
{
"query"
:
{
"bool"
:
{
"filter"
:
[],
"should"
:
[],
"must_not"
:
[]
}
},
"track_total_hits"
:
true
,
"size"
:
20
,
"from"
:
0
,
"_source"
:
[
"drug_warning.molecule_chembl_id"
,
"drug_warning.parent_molecule_chembl_id"
,
"drug_warning.warning_type"
,
"drug_warning.warning_class"
,
"drug_warning.warning_description"
,
"drug_warning.where"
,
"drug_warning.warning_refs"
],
"sort"
:
[]
}
\ No newline at end of file
app/entities_joiner/test/test_ids_loader.py
View file @
a8b612ac
...
...
@@ -2,10 +2,23 @@
Module to test the ids loader
"""
import
unittest
import
os
import
json
from
app.entities_joiner
import
ids_loader
def
load_sample_query
(
filename
):
"""
:param filename: name of the file to read
:return: the dict with the query contained in the file in the data directory of these tests
"""
filepath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'data'
,
filename
)
with
open
(
filepath
)
as
query_file
:
return
json
.
loads
(
query_file
.
read
())
class
TestIDsLoader
(
unittest
.
TestCase
):
"""
Class to test the ids loader module
...
...
@@ -15,28 +28,7 @@ class TestIDsLoader(unittest.TestCase):
"""
test that it generates the required query when selected all items in dataset
"""
es_query
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[],
"should"
:
[],
"must_not"
:
[]
}
},
"track_total_hits"
:
True
,
"size"
:
20
,
"from"
:
0
,
"_source"
:
[
"drug_warning.molecule_chembl_id"
,
"drug_warning.parent_molecule_chembl_id"
,
"drug_warning.warning_type"
,
"drug_warning.warning_class"
,
"drug_warning.warning_description"
,
"drug_warning.where"
,
"drug_warning.warning_refs"
],
"sort"
:
[]
}
es_query
=
load_sample_query
(
'sample_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
...
...
@@ -64,28 +56,7 @@ class TestIDsLoader(unittest.TestCase):
"""
test that it generates the required query when selected all items in dataset
"""
es_query
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[],
"should"
:
[],
"must_not"
:
[]
}
},
"track_total_hits"
:
True
,
"size"
:
20
,
"from"
:
0
,
"_source"
:
[
"drug_warning.molecule_chembl_id"
,
"drug_warning.parent_molecule_chembl_id"
,
"drug_warning.warning_type"
,
"drug_warning.warning_class"
,
"drug_warning.warning_description"
,
"drug_warning.where"
,
"drug_warning.warning_refs"
],
"sort"
:
[]
}
es_query
=
load_sample_query
(
'sample_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
...
...
@@ -115,7 +86,32 @@ class TestIDsLoader(unittest.TestCase):
self
.
assertDictEqual
(
ids_query_must_be
,
ids_query_got
,
msg
=
'The query was not generated correctly when selecting all items except some!'
)
def
test_generates_query_to_get_ids_when_selecting_none
(
self
):
def
test_generates_query_to_get_ids_when_selecting_none
_except_some
(
self
):
"""
test that it generates the required query when select
in
dataset
test that it generates the required query when selectin
g none except zone
"""
es_query
=
load_sample_query
(
'sample_query_0.json'
)
selection_description
=
{
"selectionMode"
:
"noItemsExcept"
,
"exceptions"
:
[
'CHEMBL3989861'
,
'CHEMBL3989724'
,
'CHEMBL64'
]
}
from_property
=
'drug_warning.molecule_chembl_id'
ids_query_must_be
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[{
"terms"
:
{
from_property
:
selection_description
[
'exceptions'
]
}
}],
}
},
"_source"
:
[
from_property
],
}
ids_query_got
=
ids_loader
.
get_ids_query
(
es_query
,
selection_description
,
from_property
)
self
.
assertDictEqual
(
ids_query_must_be
,
ids_query_got
,
msg
=
'The query was not generated correctly when selecting no items except some!'
)
functional_tests/run_functional_tests.py
View file @
a8b612ac
...
...
@@ -12,7 +12,7 @@ from specific_tests import fun_test_simple_query, fun_test_query_with_context, \
fun_test_go_slim_target_classification
,
fun_test_in_vivo_assay_classification
,
\
fun_test_organism_taxonomy_target_classification
,
fun_test_protein_target_classification
,
\
fun_test_covid_entities_records
,
fun_test_database_summary
,
fun_test_entities_records
,
\
fun_test_get_all_properties
,
fun_test_identify_separator
fun_test_get_all_properties
,
fun_test_identify_separator
,
fun_test_entities_join_0
PARSER
=
argparse
.
ArgumentParser
()
PARSER
.
add_argument
(
'server_base_path'
,
help
=
'server base path to run the tests against'
,
...
...
@@ -28,15 +28,7 @@ def run():
"""
print
(
f
'Running functional tests on
{
ARGS
.
server_base_path
}
'
)
for
test_module
in
[
fun_test_simple_query
,
fun_test_query_with_context
,
fun_test_query_with_search_by_ids_context
,
fun_test_property_config
,
fun_test_group_config
,
fun_test_facets_group_config
,
fun_test_get_document
,
fun_test_id_properties
,
fun_test_get_context_data
,
fun_test_search_parsing
,
fun_test_url_shortening
,
fun_test_element_usage
,
fun_test_go_slim_target_classification
,
fun_test_in_vivo_assay_classification
,
fun_test_organism_taxonomy_target_classification
,
fun_test_protein_target_classification
,
fun_test_covid_entities_records
,
fun_test_database_summary
,
fun_test_entities_records
,
fun_test_get_all_properties
,
fun_test_identify_separator
]:
for
test_module
in
[
fun_test_entities_join_0
]:
test_module
.
run_test
(
ARGS
.
server_base_path
,
ARGS
.
delayed_jobs_server_base_path
)
...
...
functional_tests/specific_tests/fun_test_entities_join_0.py
View file @
a8b612ac
# pylint: disable=import-error
"""
Module that tests the endpoints to do joins among entities
Module that tests the endpoints to do joins among entities
selecting all ids
"""
import
json
import
requests
def
run_test
(
server_base_url
,
delayed_jobs_server_base_path
):
"""
Tests doing a join among different entities
Tests doing a join among different entities
selecting all ids
: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
"""
...
...
@@ -15,12 +17,67 @@ def run_test(server_base_url, delayed_jobs_server_base_path):
print
(
'-------------------------------------------'
)
print
(
'Testing joins among entities'
)
print
(
'-------------------------------------------'
)
dataset_query
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[
{
"bool"
:
{
"should"
:
[
{
"terms"
:
{
"drug_warning.warning_class"
:
[
"Hepatotoxicity"
]
}
}
]
}
},
{
"bool"
:
{
"should"
:
[
{
"terms"
:
{
"drug_warning.where.country"
:
[
"United Kingdom"
]
}
}
]
}
}
],
"should"
:
[],
"must_not"
:
[]
}
},
"track_total_hits"
:
True
,
"size"
:
20
,
"from"
:
0
,
"_source"
:
[
"drug_warning.molecule_chembl_id"
,
"drug_warning.parent_molecule_chembl_id"
,
"drug_warning.warning_type"
,
"drug_warning.warning_class"
,
"drug_warning.warning_description"
,
"drug_warning.where"
,
"drug_warning.warning_refs"
],
"sort"
:
[]
}
selection_description
=
{
"selectionMode"
:
"allItemsExcept"
,
"exceptions"
:
[]}
join_params
=
{
'destination_entity_browser_state_template'
:
'wwwdev.ebi.ac.uk/chembl/g/#browse/<BROWSER_NAME>/full_state/<GENERATED_STATE>'
,
'entity_from'
:
'CHEMBL_DRUG_WARNINGS'
,
'entity_to'
:
'CHEMBL_ACTIVITIES'
,
'es_query'
:
''
,
'es_query'
:
json
.
dumps
(
dataset_query
),
'selection_description'
:
json
.
dumps
(
selection_description
)
}
url
=
f
'
{
server_base_url
}
/entities_join/get_link_to_related_items'
print
(
'doing post'
)
request
=
requests
.
post
(
url
,
data
=
join_params
)
print
(
'post done!'
)
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