Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paths to renci python image #452

Merged
merged 11 commits into from
Jul 23, 2024
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use RENCI python base image
FROM renciorg/renci-python-image:v3.12.4
FROM ghcr.io/translatorsri/renci-python-image:3.12.4

# Add image info
LABEL org.opencontainers.image.source https://github.com/ranking-agent/strider
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12
FROM ghcr.io/translatorsri/renci-python-image:3.12.4

# Add image info
LABEL org.opencontainers.image.source https://github.com/ranking-agent/strider
Expand Down
4 changes: 2 additions & 2 deletions strider/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ async def sync_query(
return JSONResponse(query_results)


@APP.post("/asyncquery", response_model=ReasonerResponse)
@APP.post("/asyncquery")
async def async_query(
background_tasks: BackgroundTasks,
query: AsyncQuery = Body(..., example=AEXAMPLE),
Expand Down Expand Up @@ -406,7 +406,7 @@ async def async_query(
return


@APP.post("/multiquery", response_model=dict[str, ReasonerResponse])
@APP.post("/multiquery")
async def multi_query(
background_tasks: BackgroundTasks,
multiquery: dict[str, AsyncQuery] = Body(..., example=MEXAMPLE),
Expand Down
59 changes: 42 additions & 17 deletions strider/throttle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,6 @@ def filter_by_curie_mapping(
]
)

# Construct result-specific knowledge graph
filtered_msg.knowledge_graph = KnowledgeGraph(
nodes={
binding.id: message.knowledge_graph.nodes[binding.id]
for result in filtered_msg.results
for _, bindings in result.node_bindings.items()
for binding in bindings
},
edges={
binding.id: message.knowledge_graph.edges[binding.id]
for result in filtered_msg.results
for analysis in result.analyses
for _, bindings in analysis.edge_bindings.items()
for binding in bindings
},
)

# Construct result-specific auxiliary graphs
filtered_aux_graphs = [
aux_graph_id
Expand All @@ -130,6 +113,48 @@ def filter_by_curie_mapping(
}
)

# get all edge ids from the result
kgraph_edge_ids = [
binding.id
for result in filtered_msg.results
for analysis in result.analyses or []
for _, bindings in analysis.edge_bindings.items()
for binding in bindings
]

# get all edge ids from auxiliary graphs
kgraph_edge_ids.extend(
[
edge_id
for aux_graph_id in filtered_aux_graphs
for edge_id in message.auxiliary_graphs[aux_graph_id].edges or []
]
)

kgraph_node_ids = set(
binding.id
for result in filtered_msg.results
for _, bindings in result.node_bindings.items()
for binding in bindings
)

for aux_graph_id in filtered_aux_graphs:
for edge_id in message.auxiliary_graphs[aux_graph_id].edges or []:
kgraph_node_ids.add(message.knowledge_graph.edges[edge_id].subject)
kgraph_node_ids.add(message.knowledge_graph.edges[edge_id].object)

# Construct result-specific knowledge graph
filtered_msg.knowledge_graph = KnowledgeGraph(
nodes={
node_id: message.knowledge_graph.nodes[node_id]
for node_id in kgraph_node_ids
},
edges={
edge_id: message.knowledge_graph.edges[edge_id]
for edge_id in kgraph_edge_ids
},
)

return filtered_msg


Expand Down
29 changes: 28 additions & 1 deletion strider/trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,18 @@ def convert_subclasses_to_aux_graphs(
"subject": subclass,
"object": node.id,
"predicate": "biolink:subclass_of",
"attributes": [],
"attributes": [
{
"attribute_type_id": "biolink:knowledge_level",
"value": "not_provided",
"attribute_source": "infores:aragorn",
},
{
"attribute_type_id": "biolink:agent_type",
"value": "automated_agent",
"attribute_source": "infores:aragorn",
},
],
"sources": [
{
"resource_id": kp_id,
Expand All @@ -472,6 +483,7 @@ def convert_subclasses_to_aux_graphs(
message.knowledge_graph.edges[primary_edge_id].object = node.id

had_support_graphs = False
had_knowledge_level = False
for attribute in message.knowledge_graph.edges[
primary_edge_id
].attributes:
Expand All @@ -481,6 +493,10 @@ def convert_subclasses_to_aux_graphs(
):
had_support_graphs = True
attribute.value.append(aux_edge_id)
if attribute.attribute_type_id == "biolink:knowledge_level":
had_knowledge_level = True
attribute.value = "logical_entailment"
attribute.attribute_source = "infores:aragorn"
if not had_support_graphs:
message.knowledge_graph.edges[primary_edge_id].attributes.add(
Attribute.parse_obj(
Expand All @@ -492,6 +508,17 @@ def convert_subclasses_to_aux_graphs(
)
)

if not had_knowledge_level:
message.knowledge_graph.edges[primary_edge_id].attributes.add(
Attribute.parse_obj(
{
"attribute_type_id": "biolink:knowledge_level",
"value": "logical_entailment",
"attribute_source": "infores:aragorn",
}
)
)

# create aux graph
message.auxiliary_graphs[aux_edge_id] = AuxiliaryGraph.parse_obj(
{
Expand Down
4 changes: 3 additions & 1 deletion strider/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ def remove_null_values(obj):
return {
key: remove_null_values(value)
for key, value in obj.items()
if value is not None
# TODO: also handle empty lists
# need to take this out when automats get fixed
if value is not None and value != []
}
elif isinstance(obj, list):
return [remove_null_values(el) for el in obj]
Expand Down
72 changes: 36 additions & 36 deletions tests/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ async def test_mixed_canonical(monkeypatch, mocker):
"ids": ["CHEBI:6801"],
"categories": ["biolink:ChemicalSubstance"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"categories": ["biolink:Disease"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:treats", "biolink:phenotype_of"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down Expand Up @@ -121,23 +121,23 @@ async def test_symmetric_noncanonical(monkeypatch, mocker):
"ids": ["CHEBI:6801"],
"categories": ["biolink:ChemicalSubstance"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"categories": ["biolink:Disease"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:genetically_interacts_with"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down Expand Up @@ -236,23 +236,23 @@ async def test_protein_gene_conflation(monkeypatch, mocker):
"ids": ["MONDO:0008114"],
"categories": ["biolink:Disease"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"categories": ["biolink:Protein", "biolink:Gene"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:related_to"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down Expand Up @@ -296,24 +296,24 @@ async def test_gene_protein_conflation(monkeypatch, mocker):
"n0": {
"categories": ["biolink:Gene", "biolink:Protein"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"ids": ["MONDO:0008114"],
"categories": ["biolink:Disease"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:related_to"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down Expand Up @@ -361,23 +361,23 @@ async def test_node_set(monkeypatch, mocker):
"ids": ["CHEBI:6801"],
"categories": ["biolink:ChemicalSubstance"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"categories": ["biolink:Disease"],
"set_interpretation": "ALL",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:treats"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down Expand Up @@ -425,23 +425,23 @@ async def test_bypass_cache_is_sent_along_to_kps(monkeypatch, mocker):
"ids": ["CHEBI:6801"],
"categories": ["biolink:ChemicalSubstance"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
"n1": {
"categories": ["biolink:Disease"],
"set_interpretation": "BATCH",
"member_ids": [],
"constraints": [],
# "member_ids": [],
# "constraints": [],
},
},
"edges": {
"n0n1": {
"subject": "n0",
"object": "n1",
"predicates": ["biolink:treats"],
"attribute_constraints": [],
"qualifier_constraints": [],
# "attribute_constraints": [],
# "qualifier_constraints": [],
},
},
},
Expand Down
Loading
Loading