Skip to content

Commit 662913d

Browse files
authored
Merge pull request #61 from BioPack-team/fix_lookup_results
Fix lookup results
2 parents bfb6747 + 928e4d8 commit 662913d

File tree

7 files changed

+38
-101
lines changed

7 files changed

+38
-101
lines changed

shepherd_server/openapi-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ contact:
44
x-id: https://github.com/maximusunc
55
x-role: responsible developer
66
description: '<img src="/static/favicon.png" width="200px"><br /><br />Shepherd: Translator Autonomous Relay Agent Platform'
7-
version: 0.5.2
7+
version: 0.5.3
88
servers:
99
- description: Default server
1010
url: https://shepherd.renci.org

workers/bte_lookup/template_groups.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"predicate": ["treats", "ameliorates"],
1212
"object": ["Disease", "PhenotypicFeature", "DiseaseOrPhenotypicFeature"],
1313
"templates": [
14-
"Chem-treats-DoP.json",
1514
"Chem-treats-PhenoOfDisease.json",
1615
"Chem-regulates,affects-Gene-biomarker,associated_condition-DoP.json"
1716
],
@@ -33,7 +32,6 @@
3332
},
3433
"object": ["Gene", "Protein"],
3534
"templates": [
36-
"Chem-increasesGene.json",
3735
"Chem-IncreaseAnotherGeneThatUpregs-Gene.json",
3836
"Chem-DecreaseAnotherGeneThatDownregs-Gene.json",
3937
"Chem-physically_interacts-GeneThatUpregs-Gene.json",
@@ -56,7 +54,6 @@
5654
},
5755
"object": ["Gene", "Protein"],
5856
"templates": [
59-
"Chem-decreasesGene.json",
6057
"Chem-IncreaseAnotherGeneThatDownregs-Gene.json",
6158
"Chem-DecreaseAnotherGeneThatUpregs-Gene.json",
6259
"Chem-physically_interacts-GeneThatDownregs-Gene.json",

workers/bte_lookup/templates/Chem-decreases-Gene/Chem-decreasesGene.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

workers/bte_lookup/templates/Chem-increases-Gene/Chem-increasesGene.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

workers/bte_lookup/templates/Drug-treats-Disease/Chem-treats-DoP.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

workers/bte_lookup/worker.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,18 @@ def expand_bte_query(query_dict: dict[str, Any], logger: logging.Logger) -> list
397397
object_key,
398398
object_curie,
399399
)
400+
for qedge in query_graph["edges"].values():
401+
del qedge["knowledge_type"]
400402

401-
return filled_templates
403+
expanded_queries = [
404+
{
405+
"message": {"query_graph": query_graph},
406+
"parameters": query_dict["parameters"],
407+
}
408+
]
409+
expanded_queries.extend(filled_templates)
410+
411+
return expanded_queries
402412

403413

404414
async def process_task(task, parent_ctx, logger, limiter):

workers/merge_message/worker.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,16 @@ def queries_equivalent(query1, query2):
223223
for node in q["nodes"].values():
224224
if "is_set" in node and node["is_set"] is False:
225225
del node["is_set"]
226+
if (
227+
"set_interpretation" in node and node["set_interpretation"] == "BATCH"
228+
) or ("set_interpretation" in node and node["set_interpretation"] is None):
229+
del node["set_interpretation"]
226230
if "constraints" in node and len(node["constraints"]) == 0:
227231
del node["constraints"]
232+
if "member_ids" in node and len(node["member_ids"]) == 0:
233+
del node["member_ids"]
234+
if "ids" in node and node["ids"] is None:
235+
del node["ids"]
228236
for edge in q["edges"].values():
229237
if (
230238
"attribute_constraints" in edge
@@ -236,6 +244,14 @@ def queries_equivalent(query1, query2):
236244
and len(edge["qualifier_constraints"]) == 0
237245
):
238246
del edge["qualifier_constraints"]
247+
if "knowledge_type" in edge:
248+
del edge["knowledge_type"]
249+
# handle treats and treats_or_applied_or_studied_to_treat
250+
for pred_indx, predicate in enumerate(edge["predicates"]):
251+
if predicate == "biolink:treats":
252+
edge["predicates"][
253+
pred_indx
254+
] = "biolink:treats_or_applied_or_studied_to_treat"
239255
return q1 == q2
240256

241257

@@ -350,17 +366,22 @@ def merge_messages(
350366
aux_dict
351367
)
352368
# The result with the direct lookup needs to be handled specially. It's the one with the lookup query graph
353-
lookup_results = [] # in case we don't have any
354369
lookup_results = (
355370
response["message"]["results"]
356371
if response["message"].get("results") is not None
357372
else []
358373
)
359-
result["message"]["results"].extend(
360-
new_response["message"]["results"]
361-
if new_response["message"].get("results") is not None
362-
else []
374+
is_direct_lookup = queries_equivalent(
375+
new_response["message"]["query_graph"], original_query_graph
363376
)
377+
if is_direct_lookup:
378+
lookup_results.extend(new_response["message"]["results"])
379+
else:
380+
result["message"]["results"].extend(
381+
new_response["message"]["results"]
382+
if new_response["message"].get("results") is not None
383+
else []
384+
)
364385

365386
answer_node_id = get_answer_node(original_query_graph)
366387
merged_messages = merge_results_by_node(

0 commit comments

Comments
 (0)