Skip to content

Commit

Permalink
add test to change the categories to various things #1818
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoslicki committed Jul 3, 2022
1 parent 65a6a2c commit 11cd111
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
13 changes: 10 additions & 3 deletions code/ARAX/ARAXQuery/Infer/scripts/infer_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)
from ARAX_expander import ARAXExpander
from ARAX_resultify import ARAXResultify
from ARAX_decorator import ARAXDecorator
from biolink_helper import BiolinkHelper
import traceback
from collections import Counter
from collections.abc import Hashable
Expand Down Expand Up @@ -43,7 +44,8 @@ def __init__(self):
self.response = None
self.message = None
self.parameters = None
self.report_stats = True
self.report_stats = True
self.bh = BiolinkHelper()

def __get_formated_edge_key(self, edge: Edge, kp: str = 'infores:rtx-kg2') -> str:
return f"{kp}:{edge.subject}-{edge.predicate}-{edge.object}"
Expand Down Expand Up @@ -129,8 +131,13 @@ def genrete_treat_subgraphs(self, response: ARAXResponse, top_drugs: pd.DataFram
self.response.envelope.message.knowledge_graph.nodes = {}
self.response.envelope.message.knowledge_graph.edges = {}
# FIXME: is this the best way to be adding the node to the knowledge graph?
self.response.envelope.message.knowledge_graph.nodes[disease] = Node(name=disease_name, categories=[
'biolink:DiseaseOrPhenotypicFeature'])
#self.response.envelope.message.knowledge_graph.nodes[disease] = Node(name=disease_name, categories=[
# 'biolink:DiseaseOrPhenotypicFeature', 'biolink:Disease'])
categories_to_add = set()
categories_to_add.update(self.bh.get_ancestors('biolink:Disease'))
categories_to_add.update(list(synonymizer.get_normalizer_results(disease_curie)[disease_curie]['categories'].keys()))
categories_to_add = list(categories_to_add)
self.response.envelope.message.knowledge_graph.nodes[disease] = Node(name=disease_name, categories=categories_to_add)
drug_qnode_key = response.envelope.message.query_graph.edges[qedge_id].subject
disease_qnode_key = response.envelope.message.query_graph.edges[qedge_id].object
self.response.envelope.message.knowledge_graph.nodes[disease].qnode_keys = [disease_qnode_key]
Expand Down
62 changes: 62 additions & 0 deletions code/ARAX/test/test_ARAX_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,5 +1083,67 @@ def test_xdtd_expand():
nodes_by_qg_id, edges_by_qg_id = _run_query_and_do_standard_testing(json_query=query)


def test_xdtd_different_categories():
query = {
"nodes": {
"disease": {
"ids": ["MONDO:0004975"]
},
"chemical": {
"categories": ["biolink:Drug"]
}
},
"edges": {
"t_edge": {
"object": "disease",
"subject": "chemical",
"predicates": ["biolink:treats"],
"knowledge_type": "inferred"
}
}
}
nodes_by_qg_id, edges_by_qg_id = _run_query_and_do_standard_testing(json_query=query)
query = {
"nodes": {
"disease": {
"ids": ["MONDO:0004975"],
"categories": ["biolink:Disease"]
},
"chemical": {
"categories": ["biolink:Drug"]
}
},
"edges": {
"t_edge": {
"object": "disease",
"subject": "chemical",
"predicates": ["biolink:treats"],
"knowledge_type": "inferred"
}
}
}
nodes_by_qg_id, edges_by_qg_id = _run_query_and_do_standard_testing(json_query=query)
query = {
"nodes": {
"disease": {
"ids": ["MONDO:0004975"],
"categories": ["biolink:DiseaseOrPhenotypicFeature"]
},
"chemical": {
"categories": ["biolink:ChemicalMixture"]
}
},
"edges": {
"t_edge": {
"object": "disease",
"subject": "chemical",
"predicates": ["biolink:treats"],
"knowledge_type": "inferred"
}
}
}
nodes_by_qg_id, edges_by_qg_id = _run_query_and_do_standard_testing(json_query=query)


if __name__ == "__main__":
pytest.main(['-v', 'test_ARAX_expand.py'])

0 comments on commit 11cd111

Please sign in to comment.