Skip to content

Commit

Permalink
fixed trapi->dict to ignore nones
Browse files Browse the repository at this point in the history
  • Loading branch information
cbizon committed Dec 13, 2023
1 parent a4531bd commit e828a4d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
10 changes: 10 additions & 0 deletions check_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json

types = set()
with open("robokop_nodes.jsonl","r") as inf:
for line in inf:
s = json.loads(line)
type = s["category"][0]
if type not in types:
print(type, len(types))
types.add(type)
12 changes: 6 additions & 6 deletions notebooks/ROBOKOP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "controlling-greek",
"metadata": {},
"outputs": [],
Expand All @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "psychological-sunrise",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -115,7 +115,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"id": "caring-invitation",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -191,7 +191,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 3,
"id": "premier-myrtle",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -245,15 +245,15 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 9,
"id": "directed-steel",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Returned 5062 in 0:02:09.111197\n"
"Returned 5062 in 0:01:37.274773\n"
]
}
],
Expand Down
5 changes: 1 addition & 4 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@APP.post("/query", tags=["Query"], response_model=PDResponse, response_model_exclude_none=True, status_code=200)
async def query_handler(request: PDResponse):
""" Query operations. """
dict_request = request.to_dict()
dict_request = request.dict(exclude_unset=True, exclude_none=True)
# Check the query graph for basic validity
query_graph = dict_request['message']['query_graph']
if len(query_graph['edges']) != 1:
Expand Down Expand Up @@ -91,9 +91,6 @@ async def query_handler(request: PDResponse):
# edges.extend(edges_r)

# Create edge identifiers
for eid, edge in enumerate(edges):
print(type(json.loads(edge)))
print(edge)
edge_id_to_edge = { f"knowledge_edge_{i}":json.loads(edge) for i, edge in enumerate(edges)}
# These edges are the ones that are going the same direction as the query
forward_edge_ids = set(edge_id_to_edge.keys())
Expand Down
32 changes: 32 additions & 0 deletions tests/test_trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@ def test_profile_asthma():
}
response = client.post("/query", json={"message": {"query_graph": query_graph}}).json()

def test_500():
# This is giving a 500, seems like it's getting into the double ended query by mistake.
m = {
"message": {
"query_graph": {
"nodes": {
"chemical": {
"categories": ["biolink:ChemicalEntity"],
"is_set": False,
"constraints": []
},
"f": {
"ids": ["MONDO:0005737"],
"is_set": False,
"constraints": []
}
},
"edges": {
"edge_1": {
"subject": "chemical",
"object": "f",
"predicates": ["biolink:treats"],
"attribute_constraints": [],
"qualifier_constraints": []
}
}
}
}
}
response = client.post("/query", json=m)
assert response.status_code == 200

def xtest_type_descendant_queries(rc, descender):
# Given the edge defined in run_basic_tests, query for it by subject and object with super types
run_basic_tests(rc, descender, subject_type = "biolink:NamedThing", object_type = "biolink:NamedThing")
Expand Down

0 comments on commit e828a4d

Please sign in to comment.