diff --git a/big_scape/network/families.py b/big_scape/network/families.py index 10a54ba4..3f3bd15e 100644 --- a/big_scape/network/families.py +++ b/big_scape/network/families.py @@ -4,9 +4,6 @@ import sys from typing import Callable, Optional import warnings -import numpy as np -import networkx -import math import logging # from dependencies @@ -105,24 +102,6 @@ def generate_families( return regions_families -def get_cc_edge_weight_std(connected_component) -> float: - """calculates the standard deviation of the edge weights of a connected component - - Args: - connected_component (list[tuple[int, int, float, float, float, float, str]]): - connected component in the form of a list of edges - - Returns: - float: standard deviation of the edge weights of the connected component - """ - - edge_weights = [edge[2] for edge in connected_component] - edge_std = np.std(edge_weights) - edge_std = round(edge_std, 2) - - return edge_std - - def get_cc_density( connected_component: list[tuple[int, int, float, float, float, float, int]] ) -> float: @@ -148,46 +127,6 @@ def get_cc_density( return cc_density -def test_centrality(connected_component, node_fraction) -> tuple[bool, list[int]]: - """tests if a network will break when removing the top nodes - with highest betweenness centrality - - Args: - connected_component (list[tuple[int, int, float, float, float, float, str]]): - connected component in the form of a list of edges - node_fraction (float): fraction of nodes with highest betweenness centrality to remove - - Returns: - tuple[bool, list[int]]: whether the network breaks and the list of nodes sorted by betweenness centrality - """ - - edgelist = [(edge[0], edge[1], edge[2]) for edge in connected_component] - - graph = networkx.Graph() - graph.add_weighted_edges_from(edgelist) - - betweeness_centrality_dict = networkx.betweenness_centrality(graph) - sorted_between_bentrality_nodes = sorted( - betweeness_centrality_dict, key=betweeness_centrality_dict.get, reverse=True - ) - - # round up to nearest integer - top_nodes = math.ceil(len(sorted_between_bentrality_nodes) * node_fraction) - nodes_to_remove = sorted_between_bentrality_nodes[:top_nodes] - - for node in nodes_to_remove: - graph.remove_node(node) - - nr_ccs = networkx.number_connected_components(graph) - - del graph - - if nr_ccs > 1: - return True, sorted_between_bentrality_nodes - - return False, sorted_between_bentrality_nodes - - def aff_sim_matrix(matrix, preference: Optional[float] = None): """Execute affinity propagation on a __similarity__ matrix diff --git a/big_scape/network/utility.py b/big_scape/network/utility.py index ab3a9dfd..284c544d 100644 --- a/big_scape/network/utility.py +++ b/big_scape/network/utility.py @@ -2,23 +2,6 @@ # from dependencies import numpy as np -import networkx as nx - - -def sim_matrix_from_graph(graph: nx.Graph, edge_property: str) -> np.ndarray: - """Return a similarity matrix from a graph in the form of a numpy array - - Args: - graph (Graph): graph - edge_property (str): _description_ - - Returns: - ndarray: _description_ - """ - matrix = nx.to_numpy_array(graph, weight=edge_property, nonedge=1.0) - # have to convert from distances to similarity - matrix = 1 - matrix - return matrix def edge_list_to_adj_list( diff --git a/big_scape/utility/version.py b/big_scape/utility/version.py index df85de3a..daefdd02 100644 --- a/big_scape/utility/version.py +++ b/big_scape/utility/version.py @@ -1,8 +1,7 @@ """Module that contains helper functions specifically related to the bigscape version """ -import toml - +import tomllib from importlib import metadata from pathlib import Path @@ -21,7 +20,8 @@ def get_bigscape_version() -> str: pyproject_toml = Path(__file__).parent.parent.parent / "pyproject.toml" if pyproject_toml.exists(): - return toml.load(pyproject_toml)["project"]["version"] + with open(pyproject_toml, "rb") as fp: + return tomllib.load(fp)["project"]["version"] # if not, we're probably running as a package. get the version of the currently # installed big-scape package diff --git a/environment.yml b/environment.yml index 1a86722f..e668390c 100644 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,6 @@ dependencies: - biopython=1.81 - sortedcontainers=2.4.0 - fasttree=2.1.11 - - networkx=3.1 - numpy=1.26.0 - pandas=2.1.1 - pyhmmer=0.10.14 diff --git a/Figures/BiG-SCAPE-CORASON_Fig1_20171122_v01_MM_nocorason.png b/figures/BiG-SCAPE-CORASON_Fig1_20171122_v01_MM_nocorason.png similarity index 100% rename from Figures/BiG-SCAPE-CORASON_Fig1_20171122_v01_MM_nocorason.png rename to figures/BiG-SCAPE-CORASON_Fig1_20171122_v01_MM_nocorason.png diff --git a/pyproject.toml b/pyproject.toml index a68e0a86..2a3e1506 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ dev = [ # type stubs (https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports) "types-psutil", - "networkx-stubs", "data-science-types", "types-tqdm", "types-setuptools" diff --git a/test/comparison/__init__.py b/test/comparison/__init__.py new file mode 100644 index 00000000..03dc8e43 --- /dev/null +++ b/test/comparison/__init__.py @@ -0,0 +1 @@ +"""Contains tests for distance calculation""" diff --git a/test/hmm/__init__.py b/test/hmm/__init__.py new file mode 100644 index 00000000..c6dfb8cc --- /dev/null +++ b/test/hmm/__init__.py @@ -0,0 +1 @@ +"""Contains tests involving (py)HMMer analysis and processing""" diff --git a/test/network/__init__.py b/test/network/__init__.py new file mode 100644 index 00000000..8f435c38 --- /dev/null +++ b/test/network/__init__.py @@ -0,0 +1 @@ +"""Contains tests involving CC and family generation""" diff --git a/test/network/test_family.py b/test/network/test_family.py index 95e904d2..07c0bcbe 100644 --- a/test/network/test_family.py +++ b/test/network/test_family.py @@ -121,18 +121,6 @@ def test_aff_sim_matrix(self): self.assertListEqual(expected_labels, actual_labels) - def test_get_cc_edge_weight_std(self): - """Tests whether the standard deviation of the edge weights of a connected - component is correctly calculated - """ - adj_list = TestAffinityPropagation.gen_edge_list() - - expected_std = 0.12 - - actual_std = bs_families.get_cc_edge_weight_std(adj_list) - - self.assertEqual(expected_std, actual_std) - def test_get_cc_density(self): """Tests whether the density of a connected component is correctly calculated @@ -146,17 +134,3 @@ def test_get_cc_density(self): actual_density = bs_families.get_cc_density(adj_list) self.assertEqual(expected_density, actual_density) - - def test_test_centrality(self): - """Tests whether the test_centrality function correctly identifies a network - that will break when removing the top nodes with highest betweenness centrality - """ - adj_list = TestAffinityPropagation.gen_edge_list_alt() - - expected_break = True - - actual_break, actual_sorted_centrality_nodes = bs_families.test_centrality( - adj_list, 0.3 - ) - - self.assertEqual(expected_break, actual_break)