Skip to content

Commit

Permalink
Merge pull request #2399 from RTXteam/xrcrg-2.10.1c
Browse files Browse the repository at this point in the history
Fixing xCRG for KG2.10.1 deployment
  • Loading branch information
kvnthomas98 authored Oct 11, 2024
2 parents 320506d + 74a8566 commit 1520592
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions code/ARAX/ARAXQuery/Infer/scripts/creativeCRG.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def _check_params(query_chemical: Optional[str], query_gene: Optional[str], mode
return None
answers = res['gene_id'].tolist()
self.preferred_curies = self.get_preferred_curies(answers)
self.preferred_to_original_curie = {value: key for key, value in self.preferred_curies.items() if value}
valid_genes = [item for item in self.preferred_curies.values() if item]
status_code, gene_neighbors = call_plover(valid_genes)
if status_code != 200:
Expand Down Expand Up @@ -517,6 +518,7 @@ def _check_params(query_chemical: Optional[str], query_gene: Optional[str], mode
return None
answers = res['chemical_id'].tolist()
self.preferred_curies = self.get_preferred_curies(answers)
self.preferred_to_original_curie = {value: key for key, value in self.preferred_curies.items() if value}
valid_chemicals = [item for item in self.preferred_curies.values() if item]
status_code, chemical_neighbors = call_plover(valid_chemicals)
if status_code != 200:
Expand All @@ -526,6 +528,7 @@ def _check_params(query_chemical: Optional[str], query_gene: Optional[str], mode
if status_code != 200:
self.response.warning(f"Could not get answers from Plover. Plover responded with status code: {status_code}")
return None

paths = self.get_paths(preferred_query_gene, res['chemical_id'].tolist(), gene_neighbors, chemical_neighbors, query_tf_neighbors, answer_tf_neigbors,self.tf_list, M)
final_paths = self.add_node_ids_to_path(paths, tf_edges, chemical_neighbors, gene_neighbors)
return final_paths
Expand All @@ -541,13 +544,15 @@ def get_paths(self, query_curie, answer_curies, query_neighbors, answer_neighbor
valid_answer_tf_list = {}
for answer in answer_curies:
valid_answer_tf_list[answer] = []

edges_to_ignore = set()
for edge_id, edge in answer_neighbors['edges']['e00'].items():
if edge[1] not in self.preferred_curies.values():
if edge[1] not in self.preferred_to_original_curie:
continue
if edge[0] == query_curie or edge[1] == query_curie:
edges_to_ignore.add(edge_id)
continue
relevant_node = False
answer = edge[1]
answer = self.preferred_to_original_curie[edge[1]]
neighbor = edge[0]
# ignoring lookup edges
if neighbor == query_curie:
Expand Down Expand Up @@ -588,6 +593,10 @@ def get_paths(self, query_curie, answer_curies, query_neighbors, answer_neighbor
for edge_id, edge in query_neighbors['edges']['e00'].items():
if edge_id in edges_to_ignore:
continue
if edge[0] in self.preferred_to_original_curie or edge[1] in self.preferred_to_original_curie:
continue
if (edge[1] == query_curie and edge[0] in self.preferred_to_original_curie) or (edge[0] == query_curie and edge[1] in self.preferred_to_original_curie):
continue
if edge[1] in tf_list and edge[1] not in query_path:
valid_query_tf_list.append(edge[1])
query_path[edge[1]] = [edge_id,self.predicate_depth_map[edge[2]]]
Expand All @@ -597,6 +606,8 @@ def get_paths(self, query_curie, answer_curies, query_neighbors, answer_neighbor

# two hop from query
for edge_id, edge in query_neighbors['edges']['e00'].items():
if edge[0] in self.preferred_to_original_curie or edge[1] in self.preferred_to_original_curie:
continue
if edge[0] != query_curie:
continue
relevant_node = False
Expand All @@ -618,9 +629,9 @@ def get_paths(self, query_curie, answer_curies, query_neighbors, answer_neighbor
# joining paths
for answer in answer_curies:
combined_path[(query_curie,answer)] = list()
if not self.preferred_curies[answer]:
if answer not in self.preferred_curies or not self.preferred_curies[answer]:
continue
key = self.preferred_curies[answer]
key = answer
if key not in answer_path:
continue

Expand Down

0 comments on commit 1520592

Please sign in to comment.