From ba16663362f403127061f099caac568ec6e17c04 Mon Sep 17 00:00:00 2001 From: Florian Huber <36473328+florian-huber@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:28:50 +0200 Subject: [PATCH 1/2] remove deprecated functions --- matchmsextras/networking.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/matchmsextras/networking.py b/matchmsextras/networking.py index 2298dc4..4614f38 100644 --- a/matchmsextras/networking.py +++ b/matchmsextras/networking.py @@ -358,7 +358,7 @@ def erode_clusters(graph_main, max_cluster_size=100, keep_weights_above=0.8): links_removed = [] # Split graph into separate clusters - graphs = list(nx.connected_component_subgraphs(graph_main)) + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] for graph in graphs: cluster_size = len(graph.nodes) @@ -380,7 +380,7 @@ def erode_clusters(graph_main, max_cluster_size=100, keep_weights_above=0.8): # If link removal caused split of cluster: if not nx.is_connected(graph): - subgraphs = list(nx.connected_component_subgraphs(graph)) + subgraphs = [graph.subgraph(c) for c in nx.connected_components(graph))] print("Getting from cluster with", len(graph.nodes), "nodes, to clusters with", [len(x.nodes) for x in subgraphs], "nodes.") @@ -450,7 +450,7 @@ def split_cluster(graph_main, """ # Split graph into separate clusters - graphs = list(nx.connected_component_subgraphs(graph_main)) + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] links_removed = [] for i, graph in enumerate(graphs): @@ -503,9 +503,7 @@ def split_cluster(graph_main, pair[m * 2], pair[m * 2 + 1]) # Check if created subclustes are big enough: - subgraphs = list( - nx.connected_component_subgraphs( - new_graph_testing)) + subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing))] min_size_after_cutting.append( min([len(x.nodes) for x in subgraphs])) @@ -531,8 +529,7 @@ def split_cluster(graph_main, # Remove edge from main graph: graph_main.remove_edge(pair[m * 2], pair[m * 2 + 1]) links_removed.append((pair[m * 2], pair[m * 2 + 1])) - subgraphs = list( - nx.connected_component_subgraphs(new_graph_testing)) + subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing))] if int(pairs.shape[1] / 2) > 1: print("Removed", int(pairs.shape[1] / 2), "edges:", @@ -588,7 +585,7 @@ def refine_network(graph_main, ------- """ # Split graph into separate clusters - graphs = list(nx.connected_component_subgraphs(graph_main)) + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] links_removed = [] links_added = [] @@ -610,7 +607,7 @@ def refine_network(graph_main, links_removed.extend(links) # Split updated graph into separate clusters - graphs = list(nx.connected_component_subgraphs(graph_main)) + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] cluster_max = np.max([len(x.nodes) for x in graphs]) counter += 1 @@ -664,7 +661,7 @@ def evaluate_clusters(graph_main, m_sim_ref): """ # Split graph into separate clusters - graphs = list(nx.connected_component_subgraphs(graph_main)) + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] num_nodes = [] num_edges = [] From 4d2a5667d857f7bf34a7bf24339d7b47b3e72b9f Mon Sep 17 00:00:00 2001 From: Florian Huber <36473328+florian-huber@users.noreply.github.com> Date: Mon, 19 Jun 2023 16:30:16 +0200 Subject: [PATCH 2/2] fixes --- matchmsextras/networking.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/matchmsextras/networking.py b/matchmsextras/networking.py index 4614f38..10638bb 100644 --- a/matchmsextras/networking.py +++ b/matchmsextras/networking.py @@ -358,7 +358,7 @@ def erode_clusters(graph_main, max_cluster_size=100, keep_weights_above=0.8): links_removed = [] # Split graph into separate clusters - graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main)] for graph in graphs: cluster_size = len(graph.nodes) @@ -380,7 +380,7 @@ def erode_clusters(graph_main, max_cluster_size=100, keep_weights_above=0.8): # If link removal caused split of cluster: if not nx.is_connected(graph): - subgraphs = [graph.subgraph(c) for c in nx.connected_components(graph))] + subgraphs = [graph.subgraph(c) for c in nx.connected_components(graph)] print("Getting from cluster with", len(graph.nodes), "nodes, to clusters with", [len(x.nodes) for x in subgraphs], "nodes.") @@ -450,7 +450,7 @@ def split_cluster(graph_main, """ # Split graph into separate clusters - graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main)] links_removed = [] for i, graph in enumerate(graphs): @@ -503,7 +503,7 @@ def split_cluster(graph_main, pair[m * 2], pair[m * 2 + 1]) # Check if created subclustes are big enough: - subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing))] + subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing)] min_size_after_cutting.append( min([len(x.nodes) for x in subgraphs])) @@ -529,7 +529,7 @@ def split_cluster(graph_main, # Remove edge from main graph: graph_main.remove_edge(pair[m * 2], pair[m * 2 + 1]) links_removed.append((pair[m * 2], pair[m * 2 + 1])) - subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing))] + subgraphs = [new_graph_testing.subgraph(c) for c in nx.connected_components(new_graph_testing)] if int(pairs.shape[1] / 2) > 1: print("Removed", int(pairs.shape[1] / 2), "edges:", @@ -585,7 +585,7 @@ def refine_network(graph_main, ------- """ # Split graph into separate clusters - graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main)] links_removed = [] links_added = [] @@ -607,7 +607,7 @@ def refine_network(graph_main, links_removed.extend(links) # Split updated graph into separate clusters - graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main)] cluster_max = np.max([len(x.nodes) for x in graphs]) counter += 1 @@ -661,7 +661,7 @@ def evaluate_clusters(graph_main, m_sim_ref): """ # Split graph into separate clusters - graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main))] + graphs = [graph_main.subgraph(c) for c in nx.connected_components(graph_main)] num_nodes = [] num_edges = []