This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from biothings/reasoner-output
Update Reasoner API Std output
- Loading branch information
Showing
2 changed files
with
149 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,92 @@ | ||
import unittest | ||
from biothings_explorer.user_query_dispatcher import FindConnection | ||
from biothings_explorer.user_query_dispatcher import ( | ||
FindConnection, | ||
SingleEdgeQueryDispatcher, | ||
) | ||
from biothings_explorer.hint import Hint | ||
import requests | ||
import json | ||
|
||
ht = Hint() | ||
cxcr4 = ht.query('CXCR4')['Gene'][0] | ||
fc = FindConnection(input_obj=cxcr4, output_obj='ChemicalSubstance', intermediate_nodes=None) | ||
fc.connect(verbose=True) | ||
response = fc.to_reasoner_std() | ||
|
||
class TestSingleHopQuery(unittest.TestCase): | ||
|
||
def test_result_section(self): | ||
res = requests.post("http://transltr.io:7071/validate_result", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(response["results"])).json() | ||
self.assertEqual(res, "Successfully validated") | ||
|
||
def test_query_graph_section(self): | ||
res = requests.post("http://transltr.io:7071/validate_querygraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(response["query_graph"])).json() | ||
self.assertEqual(res, "Successfully validated") | ||
|
||
def test_knowledge_graph_section(self): | ||
res = requests.post("http://transltr.io:7071/validate_knowledgegraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(response["knowledge_graph"])).json() | ||
self.assertEqual(res, "Successfully validated") | ||
|
||
class TestFindConnection(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
ht = Hint() | ||
cxcr4 = ht.query("CXCR4")["Gene"][0] | ||
fc = FindConnection( | ||
input_obj=cxcr4, output_obj="ChemicalSubstance", intermediate_nodes=None | ||
) | ||
fc.connect(verbose=True) | ||
cls.response = fc.to_reasoner_std() | ||
|
||
def test_result_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_result", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["results"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
def test_query_graph_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_querygraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["query_graph"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
def test_knowledge_graph_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_knowledgegraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["knowledge_graph"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
|
||
class TestSingleEdgeQuery(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
seqd = SingleEdgeQueryDispatcher( | ||
input_cls="ChemicalSubstance", | ||
output_cls="Protein", | ||
pred="", | ||
input_id="CHEMBL.COMPOUND", | ||
values="CHEMBL112", | ||
) | ||
seqd.query() | ||
cls.response = seqd.to_reasoner_std() | ||
|
||
def test_result_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_result", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["results"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
def test_query_graph_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_querygraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["query_graph"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
def test_knowledge_graph_section(cls): | ||
res = requests.post( | ||
"http://transltr.io:7071/validate_knowledgegraph", | ||
headers={"accept": "text/plain", "content-type": "application/json"}, | ||
data=json.dumps(cls.response["knowledge_graph"]), | ||
).json() | ||
cls.assertEqual(res, "Successfully validated") | ||
|
||
def test_knowledge_graph_node_id(cls): | ||
nodes = [item["id"] for item in cls.response["knowledge_graph"]["nodes"]] | ||
cls.assertIn("CHEMBL.COMPOUND:CHEMBL112", nodes) | ||
cls.assertIn("PR:000011298", nodes) | ||
|
||
def test_results_node_binding(cls): | ||
nodes = [item["kg_id"] for item in cls.response["results"]["node_bindings"]] | ||
cls.assertIn("CHEMBL.COMPOUND:CHEMBL112", nodes) | ||
cls.assertIn("PR:000011298", nodes) |