Skip to content

Commit

Permalink
improved connect_nodes, minor fix to yfiles visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
marcorusc committed Jun 28, 2024
1 parent 4157eba commit 0049046
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
20 changes: 10 additions & 10 deletions neko/_visual/visualize_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def render(self, output_file='network', view=False, highlight_nodes=None, highli
display(self.graph) # Display the graph directly in the Jupyter Notebook

def yfiles_visual(
# self,
network,
self,
graph_layout,
directed,
):
Expand All @@ -149,10 +148,10 @@ def yfiles_visual(

# filling w with nodes
objects = []
for idx, item in network.nodes.iterrows():
for idx, item in self.dataframe_nodes.iterrows():
obj = {
"id": network.nodes["Uniprot"].loc[idx],
"properties": {"label": network.nodes["Genesymbol"].loc[idx]},
"id": self.dataframe_nodes["Uniprot"].loc[idx],
"properties": {"label": self.dataframe_nodes["Genesymbol"].loc[idx]},
"color": "#ffffff",
"styles": {"backgroundColor": "#ffffff"}
}
Expand All @@ -161,12 +160,12 @@ def yfiles_visual(

# filling w with edges
objects = []
for index, row in network.edges.iterrows():
for index, row in self.dataframe_edges.iterrows():
obj = {
"id": network.edges["Effect"].loc[index],
"start": network.edges["source"].loc[index],
"end": network.edges["target"].loc[index],
"properties": {"references": network.edges["References"].loc[index]}}
"id": self.dataframe_edges["Effect"].loc[index],
"start": self.dataframe_edges["source"].loc[index],
"end": self.dataframe_edges["target"].loc[index],
"properties": {"references": self.dataframe_edges["References"].loc[index]}}
objects.append(obj)
w.edges = objects

Expand Down Expand Up @@ -206,6 +205,7 @@ def custom_label_styles_mapping(node: Dict):
display(w)

def vis_comparison(
self,
int_comparison,
node_comparison,
graph_layout,
Expand Down
25 changes: 15 additions & 10 deletions neko/core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,9 +717,9 @@ def connect_nodes(self,
The only_signed flag makes sure that just signed interaction will be added to the network, while "consensus_only"
makes sure that just signed interaction with consensus among references will be included.
Parameters:
- only_signed: A boolean flag indicating whether to only add signed interactions to the network.
- consensus_only: A boolean flag indicating whether to only add signed interactions with consensus among references to the network.
Parameters: - only_signed: A boolean flag indicating whether to only add signed interactions to the network.
- consensus_only: A boolean flag indicating whether to only add signed interactions with consensus among
references to the network.
Returns:
None. The function modifies the network object in-place.
Expand All @@ -731,7 +731,8 @@ def connect_nodes(self,

def add_edge_if_not_empty_and_signed(node1, node2):
"""
Helper function to add an edge to the network if the interaction is not empty and, if the `only_signed` flag is set, the interaction is signed.
Helper function to add an edge to the network if the interaction is not empty and, if the `only_signed`
flag is set, the interaction is signed.
Parameters:
- node1: The source node of the interaction.
Expand All @@ -740,10 +741,12 @@ def add_edge_if_not_empty_and_signed(node1, node2):
Returns:
None. The function modifies the network object in-place.
"""
interaction = self.resources.loc[(self.resources["source"] == node1) &
(self.resources["target"] == node2)]
if not interaction.empty and (not only_signed or check_sign(interaction, consensus_only) != "undefined"):
self.add_edge(interaction)
if node2 in self.connect.find_all_neighbours(node1):
interaction = self.resources.loc[(self.resources["source"] == node1) &
(self.resources["target"] == node2)]
if not interaction.empty and (
not only_signed or check_sign(interaction, consensus_only) != "undefined"):
self.add_edge(interaction)

for node1, node2 in combinations(self.nodes["Uniprot"], 2):
add_edge_if_not_empty_and_signed(node1, node2)
Expand Down Expand Up @@ -889,9 +892,10 @@ def dfs_algorithm(self,
"""

i = 0
i = 1
min_len = 1
while i <= maxlen:
paths = self.connect.find_paths(node2, node1, maxlen=i)
paths = self.connect.find_paths(node2, node1, maxlen=i, minlen=min_len)
if only_signed:
paths = self.filter_unsigned_paths(paths, consensus)
if paths:
Expand All @@ -902,6 +906,7 @@ def dfs_algorithm(self,
break
else:
i += 1
min_len += 1

def bfs_algorithm(self,
node1: str,
Expand Down

0 comments on commit 0049046

Please sign in to comment.