risk-network 0.0.13b3__py3-none-any.whl → 0.0.13b5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. risk/__init__.py +3 -2
  2. risk/_annotation/__init__.py +10 -0
  3. risk/{annotation/annotation.py → _annotation/_annotation.py} +40 -19
  4. risk/{annotation/io.py → _annotation/_io.py} +78 -32
  5. risk/{annotation/nltk_setup.py → _annotation/_nltk_setup.py} +7 -5
  6. risk/_log/__init__.py +11 -0
  7. risk/{log/console.py → _log/_console.py} +22 -12
  8. risk/{log/parameters.py → _log/_parameters.py} +25 -14
  9. risk/_neighborhoods/__init__.py +8 -0
  10. risk/{neighborhoods/api.py → _neighborhoods/_api.py} +23 -14
  11. risk/{neighborhoods/community.py → _neighborhoods/_community.py} +19 -11
  12. risk/{neighborhoods/domains.py → _neighborhoods/_domains.py} +15 -9
  13. risk/{neighborhoods/neighborhoods.py → _neighborhoods/_neighborhoods.py} +24 -35
  14. risk/_neighborhoods/_stats/__init__.py +13 -0
  15. risk/_neighborhoods/_stats/_permutation/__init__.py +6 -0
  16. risk/{neighborhoods/stats/permutation/permutation.py → _neighborhoods/_stats/_permutation/_permutation.py} +9 -6
  17. risk/{neighborhoods/stats/permutation/test_functions.py → _neighborhoods/_stats/_permutation/_test_functions.py} +6 -4
  18. risk/{neighborhoods/stats/tests.py → _neighborhoods/_stats/_tests.py} +12 -7
  19. risk/_network/__init__.py +8 -0
  20. risk/_network/_graph/__init__.py +7 -0
  21. risk/{network/graph/api.py → _network/_graph/_api.py} +13 -10
  22. risk/{network/graph/graph.py → _network/_graph/_graph.py} +24 -13
  23. risk/{network/graph/stats.py → _network/_graph/_stats.py} +8 -5
  24. risk/{network/graph/summary.py → _network/_graph/_summary.py} +21 -12
  25. risk/{network/io.py → _network/_io.py} +45 -24
  26. risk/_network/_plotter/__init__.py +6 -0
  27. risk/{network/plotter/api.py → _network/_plotter/_api.py} +9 -7
  28. risk/{network/plotter/canvas.py → _network/_plotter/_canvas.py} +14 -10
  29. risk/{network/plotter/contour.py → _network/_plotter/_contour.py} +17 -11
  30. risk/{network/plotter/labels.py → _network/_plotter/_labels.py} +38 -23
  31. risk/{network/plotter/network.py → _network/_plotter/_network.py} +17 -11
  32. risk/{network/plotter/plotter.py → _network/_plotter/_plotter.py} +19 -15
  33. risk/_network/_plotter/_utils/__init__.py +7 -0
  34. risk/{network/plotter/utils/colors.py → _network/_plotter/_utils/_colors.py} +19 -11
  35. risk/{network/plotter/utils/layout.py → _network/_plotter/_utils/_layout.py} +8 -5
  36. risk/risk.py +8 -8
  37. {risk_network-0.0.13b3.dist-info → risk_network-0.0.13b5.dist-info}/METADATA +2 -2
  38. risk_network-0.0.13b5.dist-info/RECORD +41 -0
  39. {risk_network-0.0.13b3.dist-info → risk_network-0.0.13b5.dist-info}/WHEEL +1 -1
  40. risk/annotation/__init__.py +0 -10
  41. risk/log/__init__.py +0 -11
  42. risk/neighborhoods/__init__.py +0 -7
  43. risk/neighborhoods/stats/__init__.py +0 -13
  44. risk/neighborhoods/stats/permutation/__init__.py +0 -6
  45. risk/network/__init__.py +0 -4
  46. risk/network/graph/__init__.py +0 -4
  47. risk/network/plotter/__init__.py +0 -4
  48. risk_network-0.0.13b3.dist-info/RECORD +0 -40
  49. {risk_network-0.0.13b3.dist-info → risk_network-0.0.13b5.dist-info}/licenses/LICENSE +0 -0
  50. {risk_network-0.0.13b3.dist-info → risk_network-0.0.13b5.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/neighborhoods/stats/tests
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_neighborhoods/_stats/_tests
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import Any, Dict
@@ -15,7 +15,8 @@ def compute_binom_test(
15
15
  annotation: csr_matrix,
16
16
  null_distribution: str = "network",
17
17
  ) -> Dict[str, Any]:
18
- """Compute Binomial test for enrichment and depletion in neighborhoods with selectable null distribution.
18
+ """
19
+ Compute Binomial test for enrichment and depletion in neighborhoods with selectable null distribution.
19
20
 
20
21
  Args:
21
22
  neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
@@ -60,7 +61,8 @@ def compute_chi2_test(
60
61
  annotation: csr_matrix,
61
62
  null_distribution: str = "network",
62
63
  ) -> Dict[str, Any]:
63
- """Compute chi-squared test for enrichment and depletion in neighborhoods with selectable null distribution.
64
+ """
65
+ Compute chi-squared test for enrichment and depletion in neighborhoods with selectable null distribution.
64
66
 
65
67
  Args:
66
68
  neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
@@ -122,7 +124,8 @@ def compute_hypergeom_test(
122
124
  annotation: csr_matrix,
123
125
  null_distribution: str = "network",
124
126
  ) -> Dict[str, Any]:
125
- """Compute hypergeometric test for enrichment and depletion in neighborhoods with selectable null distribution.
127
+ """
128
+ Compute hypergeometric test for enrichment and depletion in neighborhoods with selectable null distribution.
126
129
 
127
130
  Args:
128
131
  neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
@@ -178,7 +181,8 @@ def compute_poisson_test(
178
181
  annotation: csr_matrix,
179
182
  null_distribution: str = "network",
180
183
  ) -> Dict[str, Any]:
181
- """Compute Poisson test for enrichment and depletion in neighborhoods with selectable null distribution.
184
+ """
185
+ Compute Poisson test for enrichment and depletion in neighborhoods with selectable null distribution.
182
186
 
183
187
  Args:
184
188
  neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
@@ -220,7 +224,8 @@ def compute_zscore_test(
220
224
  annotation: csr_matrix,
221
225
  null_distribution: str = "network",
222
226
  ) -> Dict[str, Any]:
223
- """Compute z-score test for enrichment and depletion in neighborhoods with selectable null distribution.
227
+ """
228
+ Compute z-score test for enrichment and depletion in neighborhoods with selectable null distribution.
224
229
 
225
230
  Args:
226
231
  neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
@@ -0,0 +1,8 @@
1
+ """
2
+ risk/_network
3
+ ~~~~~~~~~~~~~
4
+ """
5
+
6
+ from ._graph import GraphAPI
7
+ from ._io import NetworkIO
8
+ from ._plotter import PlotterAPI
@@ -0,0 +1,7 @@
1
+ """
2
+ risk/_network/_graph
3
+ ~~~~~~~~~~~~~~~~~~~~
4
+ """
5
+
6
+ from ._api import GraphAPI
7
+ from ._graph import Graph
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/graph/api
3
- ~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_graph/_api
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  import copy
@@ -9,19 +9,20 @@ from typing import Any, Dict, Union
9
9
  import networkx as nx
10
10
  import pandas as pd
11
11
 
12
- from risk.annotation import define_top_annotation
13
- from risk.log import log_header, logger, params
14
- from risk.neighborhoods import (
12
+ from ..._annotation import define_top_annotation
13
+ from ..._log import log_header, logger, params
14
+ from ..._neighborhoods import (
15
15
  define_domains,
16
16
  process_neighborhoods,
17
17
  trim_domains,
18
18
  )
19
- from risk.network.graph.graph import Graph
20
- from risk.network.graph.stats import calculate_significance_matrices
19
+ from ._graph import Graph
20
+ from ._stats import calculate_significance_matrices
21
21
 
22
22
 
23
23
  class GraphAPI:
24
- """Handles the loading of network graphs and associated data.
24
+ """
25
+ Handles the loading of network graphs and associated data.
25
26
 
26
27
  The GraphAPI class provides methods to load and process network graphs, annotations, and neighborhoods.
27
28
  """
@@ -46,7 +47,8 @@ class GraphAPI:
46
47
  min_cluster_size: int = 5,
47
48
  max_cluster_size: int = 1000,
48
49
  ) -> Graph:
49
- """Load and process the network graph, defining top annotations and domains.
50
+ """
51
+ Load and process the network graph, defining top annotations and domains.
50
52
 
51
53
  Args:
52
54
  network (nx.Graph): The network graph.
@@ -169,7 +171,8 @@ class GraphAPI:
169
171
  min_cluster_size: int = 5,
170
172
  max_cluster_size: int = 1000,
171
173
  ) -> pd.DataFrame:
172
- """Define top annotations for the network.
174
+ """
175
+ Define top annotations for the network.
173
176
 
174
177
  Args:
175
178
  network (nx.Graph): The network graph.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/graph/graph
3
- ~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_graph/_graph
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from collections import defaultdict
@@ -10,11 +10,12 @@ import networkx as nx
10
10
  import numpy as np
11
11
  import pandas as pd
12
12
 
13
- from risk.network.graph.summary import Summary
13
+ from ._summary import Summary
14
14
 
15
15
 
16
16
  class Graph:
17
- """A class to represent a network graph and process its nodes and edges.
17
+ """
18
+ A class to represent a network graph and process its nodes and edges.
18
19
 
19
20
  The Graph class provides functionality to handle and manipulate a network graph,
20
21
  including managing domains, annotation, and node significance data. It also includes methods
@@ -32,7 +33,9 @@ class Graph:
32
33
  node_label_to_node_id_map: Dict[str, Any],
33
34
  node_significance_sums: np.ndarray,
34
35
  ):
35
- """Initialize the Graph object.
36
+ """
37
+
38
+ Initialize the Graph object.
36
39
 
37
40
  Args:
38
41
  network (nx.Graph): The network graph.
@@ -72,7 +75,8 @@ class Graph:
72
75
  self.summary = Summary(annotation, neighborhoods, self)
73
76
 
74
77
  def pop(self, domain_id: int) -> List[str]:
75
- """Remove a domain ID from the graph and return the corresponding node labels.
78
+ """
79
+ Remove a domain ID from the graph and return the corresponding node labels.
76
80
 
77
81
  Args:
78
82
  key (int): The domain ID key to be removed from each mapping.
@@ -104,7 +108,8 @@ class Graph:
104
108
  return node_labels
105
109
 
106
110
  def _create_domain_id_to_node_ids_map(self, domains: pd.DataFrame) -> Dict[int, Any]:
107
- """Create a mapping from domains to the list of node IDs belonging to each domain.
111
+ """
112
+ Create a mapping from domains to the list of node IDs belonging to each domain.
108
113
 
109
114
  Args:
110
115
  domains (pd.DataFrame): DataFrame containing domain information, including the 'primary domain' for each node.
@@ -123,7 +128,8 @@ class Graph:
123
128
  def _create_domain_id_to_domain_terms_map(
124
129
  self, trimmed_domains: pd.DataFrame
125
130
  ) -> Dict[int, Any]:
126
- """Create a mapping from domain IDs to their corresponding terms.
131
+ """
132
+ Create a mapping from domain IDs to their corresponding terms.
127
133
 
128
134
  Args:
129
135
  trimmed_domains (pd.DataFrame): DataFrame containing domain IDs and their corresponding labels.
@@ -142,7 +148,8 @@ class Graph:
142
148
  self,
143
149
  trimmed_domains: pd.DataFrame,
144
150
  ) -> Dict[int, Dict[str, Any]]:
145
- """Create a mapping from domain IDs to their corresponding full description and significance score,
151
+ """
152
+ Create a mapping from domain IDs to their corresponding full description and significance score,
146
153
  with scores sorted in descending order.
147
154
 
148
155
  Args:
@@ -178,7 +185,8 @@ class Graph:
178
185
  def _create_node_id_to_domain_ids_and_significances(
179
186
  self, domains: pd.DataFrame
180
187
  ) -> Dict[int, Dict]:
181
- """Creates a dictionary mapping each node ID to its corresponding domain IDs and significance values.
188
+ """
189
+ Creates a dictionary mapping each node ID to its corresponding domain IDs and significance values.
182
190
 
183
191
  Args:
184
192
  domains (pd.DataFrame): A DataFrame containing domain information for each node. Assumes the last
@@ -210,7 +218,8 @@ class Graph:
210
218
  return node_id_to_domain_ids_and_significances
211
219
 
212
220
  def _create_domain_id_to_node_labels_map(self) -> Dict[int, List[str]]:
213
- """Create a map from domain IDs to node labels.
221
+ """
222
+ Create a map from domain IDs to node labels.
214
223
 
215
224
  Returns:
216
225
  Dict[int, List[str]]: A dictionary mapping domain IDs to the corresponding node labels.
@@ -224,7 +233,8 @@ class Graph:
224
233
  return domain_id_to_label_map
225
234
 
226
235
  def _unfold_sphere_to_plane(self, G: nx.Graph) -> nx.Graph:
227
- """Convert 3D coordinates to 2D by unfolding a sphere to a plane.
236
+ """
237
+ Convert 3D coordinates to 2D by unfolding a sphere to a plane.
228
238
 
229
239
  Args:
230
240
  G (nx.Graph): A network graph with 3D coordinates. Each node should have 'x', 'y', and 'z' attributes.
@@ -254,7 +264,8 @@ class Graph:
254
264
  return G
255
265
 
256
266
  def _extract_node_coordinates(self, G: nx.Graph) -> np.ndarray:
257
- """Extract 2D coordinates of nodes from the graph.
267
+ """
268
+ Extract 2D coordinates of nodes from the graph.
258
269
 
259
270
  Args:
260
271
  G (nx.Graph): The network graph with node coordinates.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/graph/stats
3
- ~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_graph/_stats
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import Any, Dict, Union
@@ -16,7 +16,8 @@ def calculate_significance_matrices(
16
16
  pval_cutoff: float = 0.05,
17
17
  fdr_cutoff: float = 0.05,
18
18
  ) -> Dict[str, Any]:
19
- """Calculate significance matrices based on p-values and specified tail.
19
+ """
20
+ Calculate significance matrices based on p-values and specified tail.
20
21
 
21
22
  Args:
22
23
  depletion_pvals (np.ndarray): Matrix of depletion p-values.
@@ -89,7 +90,8 @@ def _select_significance_matrices(
89
90
  log_enrichment_matrix: np.ndarray,
90
91
  enrichment_alpha_threshold_matrix: np.ndarray,
91
92
  ) -> tuple:
92
- """Select significance matrices based on the specified tail type.
93
+ """
94
+ Select significance matrices based on the specified tail type.
93
95
 
94
96
  Args:
95
97
  tail (str): The tail type for significance selection. Options are 'left', 'right', or 'both'.
@@ -143,7 +145,8 @@ def _compute_threshold_matrix(
143
145
  pval_cutoff: float = 0.05,
144
146
  fdr_cutoff: float = 0.05,
145
147
  ) -> np.ndarray:
146
- """Compute a threshold matrix indicating significance based on p-value and FDR cutoffs.
148
+ """
149
+ Compute a threshold matrix indicating significance based on p-value and FDR cutoffs.
147
150
 
148
151
  Args:
149
152
  pvals (np.ndarray): Array of p-values for statistical tests.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/graph/summary
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_graph/_summary
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import Any, Dict, Tuple, Union
@@ -9,11 +9,12 @@ import numpy as np
9
9
  import pandas as pd
10
10
  from statsmodels.stats.multitest import fdrcorrection
11
11
 
12
- from risk.log.console import log_header, logger
12
+ from ..._log import log_header, logger
13
13
 
14
14
 
15
15
  class Summary:
16
- """Handles the processing, storage, and export of network analysis results.
16
+ """
17
+ Handles the processing, storage, and export of network analysis results.
17
18
 
18
19
  The Results class provides methods to process significance and depletion data, compute
19
20
  FDR-corrected q-values, and structure information on domains and annotations into a
@@ -27,7 +28,8 @@ class Summary:
27
28
  neighborhoods: Dict[str, Any],
28
29
  graph, # Avoid type hinting Graph to prevent circular imports
29
30
  ):
30
- """Initialize the Results object with analysis components.
31
+ """
32
+ Initialize the Results object with analysis components.
31
33
 
32
34
  Args:
33
35
  annotation (Dict[str, Any]): Annotation data, including ordered annotations and matrix of associations.
@@ -39,7 +41,8 @@ class Summary:
39
41
  self.graph = graph
40
42
 
41
43
  def to_csv(self, filepath: str) -> None:
42
- """Export significance results to a CSV file.
44
+ """
45
+ Export significance results to a CSV file.
43
46
 
44
47
  Args:
45
48
  filepath (str): The path where the CSV file will be saved.
@@ -50,7 +53,8 @@ class Summary:
50
53
  logger.info(f"Analysis summary exported to CSV file: {filepath}")
51
54
 
52
55
  def to_json(self, filepath: str) -> None:
53
- """Export significance results to a JSON file.
56
+ """
57
+ Export significance results to a JSON file.
54
58
 
55
59
  Args:
56
60
  filepath (str): The path where the JSON file will be saved.
@@ -61,7 +65,8 @@ class Summary:
61
65
  logger.info(f"Analysis summary exported to JSON file: {filepath}")
62
66
 
63
67
  def to_txt(self, filepath: str) -> None:
64
- """Export significance results to a text file.
68
+ """
69
+ Export significance results to a text file.
65
70
 
66
71
  Args:
67
72
  filepath (str): The path where the text file will be saved.
@@ -74,7 +79,8 @@ class Summary:
74
79
  logger.info(f"Analysis summary exported to text file: {filepath}")
75
80
 
76
81
  def load(self) -> pd.DataFrame:
77
- """Load and process domain and annotation data into a DataFrame with significance metrics.
82
+ """
83
+ Load and process domain and annotation data into a DataFrame with significance metrics.
78
84
 
79
85
  Returns:
80
86
  pd.DataFrame: Processed DataFrame containing significance scores, p-values, q-values,
@@ -171,7 +177,8 @@ class Summary:
171
177
  return results
172
178
 
173
179
  def _calculate_qvalues(self, pvals: np.ndarray) -> np.ndarray:
174
- """Calculate q-values (FDR) for each row of a p-value matrix.
180
+ """
181
+ Calculate q-values (FDR) for each row of a p-value matrix.
175
182
 
176
183
  Args:
177
184
  pvals (np.ndarray): 2D array of p-values.
@@ -190,7 +197,8 @@ class Summary:
190
197
  enrichment_qvals: np.ndarray,
191
198
  depletion_qvals: np.ndarray,
192
199
  ) -> Tuple[Union[float, None], Union[float, None], Union[float, None], Union[float, None]]:
193
- """Retrieve the most significant p-values and q-values (FDR) for a given annotation.
200
+ """
201
+ Retrieve the most significant p-values and q-values (FDR) for a given annotation.
194
202
 
195
203
  Args:
196
204
  domain_id (int): The domain ID associated with the annotation.
@@ -226,7 +234,8 @@ class Summary:
226
234
  )
227
235
 
228
236
  def _get_annotation_members(self, description: str) -> str:
229
- """Retrieve node labels associated with a given annotation description.
237
+ """
238
+ Retrieve node labels associated with a given annotation description.
230
239
 
231
240
  Args:
232
241
  description (str): The annotation description.
@@ -1,6 +1,6 @@
1
1
  """
2
- risk/network/io
3
- ~~~~~~~~~~~~~~~
2
+ risk/_network/_io
3
+ ~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  import copy
@@ -15,11 +15,12 @@ import networkx as nx
15
15
  import numpy as np
16
16
  import pandas as pd
17
17
 
18
- from risk.log import log_header, logger, params
18
+ from .._log import log_header, logger, params
19
19
 
20
20
 
21
21
  class NetworkIO:
22
- """A class for loading, processing, and managing network data.
22
+ """
23
+ A class for loading, processing, and managing network data.
23
24
 
24
25
  The NetworkIO class provides methods to load network data from various formats (e.g., GPickle, NetworkX)
25
26
  and process the network by adjusting node coordinates, calculating edge lengths, and validating graph structure.
@@ -31,7 +32,8 @@ class NetworkIO:
31
32
  surface_depth: float = 0.0,
32
33
  min_edges_per_node: int = 0,
33
34
  ):
34
- """Initialize the NetworkIO class.
35
+ """
36
+ Initialize the NetworkIO class.
35
37
 
36
38
  Args:
37
39
  compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
@@ -55,7 +57,8 @@ class NetworkIO:
55
57
  surface_depth: float = 0.0,
56
58
  min_edges_per_node: int = 0,
57
59
  ) -> nx.Graph:
58
- """Load a network from a GPickle file.
60
+ """
61
+ Load a network from a GPickle file.
59
62
 
60
63
  Args:
61
64
  filepath (str): Path to the GPickle file.
@@ -74,7 +77,8 @@ class NetworkIO:
74
77
  return networkio._load_network_gpickle(filepath=filepath)
75
78
 
76
79
  def _load_network_gpickle(self, filepath: str) -> nx.Graph:
77
- """Private method to load a network from a GPickle file.
80
+ """
81
+ Private method to load a network from a GPickle file.
78
82
 
79
83
  Args:
80
84
  filepath (str): Path to the GPickle file.
@@ -100,7 +104,8 @@ class NetworkIO:
100
104
  surface_depth: float = 0.0,
101
105
  min_edges_per_node: int = 0,
102
106
  ) -> nx.Graph:
103
- """Load a NetworkX graph.
107
+ """
108
+ Load a NetworkX graph.
104
109
 
105
110
  Args:
106
111
  network (nx.Graph): A NetworkX graph object.
@@ -119,7 +124,8 @@ class NetworkIO:
119
124
  return networkio._load_network_networkx(network=network)
120
125
 
121
126
  def _load_network_networkx(self, network: nx.Graph) -> nx.Graph:
122
- """Private method to load a NetworkX graph.
127
+ """
128
+ Private method to load a NetworkX graph.
123
129
 
124
130
  Args:
125
131
  network (nx.Graph): A NetworkX graph object.
@@ -147,7 +153,8 @@ class NetworkIO:
147
153
  surface_depth: float = 0.0,
148
154
  min_edges_per_node: int = 0,
149
155
  ) -> nx.Graph:
150
- """Load a network from a Cytoscape file.
156
+ """
157
+ Load a network from a Cytoscape file.
151
158
 
152
159
  Args:
153
160
  filepath (str): Path to the Cytoscape file.
@@ -180,7 +187,8 @@ class NetworkIO:
180
187
  target_label: str = "target",
181
188
  view_name: str = "",
182
189
  ) -> nx.Graph:
183
- """Private method to load a network from a Cytoscape file.
190
+ """
191
+ Private method to load a network from a Cytoscape file.
184
192
 
185
193
  Args:
186
194
  filepath (str): Path to the Cytoscape file.
@@ -316,7 +324,8 @@ class NetworkIO:
316
324
  surface_depth: float = 0.0,
317
325
  min_edges_per_node: int = 0,
318
326
  ) -> nx.Graph:
319
- """Load a network from a Cytoscape JSON (.cyjs) file.
327
+ """
328
+ Load a network from a Cytoscape JSON (.cyjs) file.
320
329
 
321
330
  Args:
322
331
  filepath (str): Path to the Cytoscape JSON file.
@@ -341,7 +350,8 @@ class NetworkIO:
341
350
  )
342
351
 
343
352
  def _load_network_cyjs(self, filepath, source_label="source", target_label="target"):
344
- """Private method to load a network from a Cytoscape JSON (.cyjs) file.
353
+ """
354
+ Private method to load a network from a Cytoscape JSON (.cyjs) file.
345
355
 
346
356
  Args:
347
357
  filepath (str): Path to the Cytoscape JSON file.
@@ -396,7 +406,8 @@ class NetworkIO:
396
406
  return self._initialize_graph(G)
397
407
 
398
408
  def _initialize_graph(self, G: nx.Graph) -> nx.Graph:
399
- """Initialize the graph by processing and validating its nodes and edges.
409
+ """
410
+ Initialize the graph by processing and validating its nodes and edges.
400
411
 
401
412
  Args:
402
413
  G (nx.Graph): The input NetworkX graph.
@@ -414,7 +425,8 @@ class NetworkIO:
414
425
  return G
415
426
 
416
427
  def _remove_invalid_graph_properties(self, G: nx.Graph) -> None:
417
- """Remove invalid properties from the graph, including self-loops, nodes with fewer edges than
428
+ """
429
+ Remove invalid properties from the graph, including self-loops, nodes with fewer edges than
418
430
  the threshold, and isolated nodes.
419
431
 
420
432
  Args:
@@ -449,7 +461,8 @@ class NetworkIO:
449
461
  logger.debug(f"Final edge count: {num_final_edges}")
450
462
 
451
463
  def _assign_edge_weights(self, G: nx.Graph) -> None:
452
- """Assign default edge weights to the graph.
464
+ """
465
+ Assign default edge weights to the graph.
453
466
 
454
467
  Args:
455
468
  G (nx.Graph): A NetworkX graph object.
@@ -459,7 +472,8 @@ class NetworkIO:
459
472
  nx.set_edge_attributes(G, default_weight, "weight")
460
473
 
461
474
  def _validate_nodes(self, G: nx.Graph) -> None:
462
- """Validate the graph structure and attributes with attribute fallback for positions and labels.
475
+ """
476
+ Validate the graph structure and attributes with attribute fallback for positions and labels.
463
477
 
464
478
  Args:
465
479
  G (nx.Graph): A NetworkX graph object.
@@ -519,7 +533,8 @@ class NetworkIO:
519
533
  )
520
534
 
521
535
  def _assign_edge_lengths(self, G: nx.Graph) -> None:
522
- """Prepare the network by adjusting surface depth and calculating edge lengths.
536
+ """
537
+ Prepare the network by adjusting surface depth and calculating edge lengths.
523
538
 
524
539
  Args:
525
540
  G (nx.Graph): The input network graph.
@@ -537,7 +552,8 @@ class NetworkIO:
537
552
  compute_sphere: bool = True,
538
553
  surface_depth: float = 0.0,
539
554
  ) -> nx.Graph:
540
- """Prepare the graph by normalizing coordinates and optionally mapping nodes to a sphere.
555
+ """
556
+ Prepare the graph by normalizing coordinates and optionally mapping nodes to a sphere.
541
557
 
542
558
  Args:
543
559
  G (nx.Graph): The input graph.
@@ -558,7 +574,8 @@ class NetworkIO:
558
574
  return G_depth
559
575
 
560
576
  def _calculate_and_set_edge_lengths(self, G: nx.Graph, compute_sphere: bool) -> None:
561
- """Compute and assign edge lengths in the graph.
577
+ """
578
+ Compute and assign edge lengths in the graph.
562
579
 
563
580
  Args:
564
581
  G (nx.Graph): The input graph.
@@ -592,7 +609,8 @@ class NetworkIO:
592
609
  G.edges[u, v]["length"] = distance
593
610
 
594
611
  def _map_to_sphere(self, G: nx.Graph) -> None:
595
- """Map the x and y coordinates of graph nodes onto a 3D sphere.
612
+ """
613
+ Map the x and y coordinates of graph nodes onto a 3D sphere.
596
614
 
597
615
  Args:
598
616
  G (nx.Graph): The input graph with nodes having 'x' and 'y' coordinates.
@@ -616,7 +634,8 @@ class NetworkIO:
616
634
  nx.set_node_attributes(G, xyz_coords)
617
635
 
618
636
  def _normalize_graph_coordinates(self, G: nx.Graph) -> None:
619
- """Normalize the x and y coordinates of the nodes in the graph to the [0, 1] range.
637
+ """
638
+ Normalize the x and y coordinates of the nodes in the graph to the [0, 1] range.
620
639
 
621
640
  Args:
622
641
  G (nx.Graph): The input graph with nodes having 'x' and 'y' coordinates.
@@ -633,7 +652,8 @@ class NetworkIO:
633
652
  G.nodes[node]["x"], G.nodes[node]["y"] = normalized_xy[i]
634
653
 
635
654
  def _create_depth(self, G: nx.Graph, surface_depth: float = 0.0) -> nx.Graph:
636
- """Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
655
+ """
656
+ Adjust the 'z' attribute of each node based on the subcluster strengths and normalized surface depth.
637
657
 
638
658
  Args:
639
659
  G (nx.Graph): The input graph.
@@ -677,7 +697,8 @@ class NetworkIO:
677
697
  filetype: str,
678
698
  filepath: str = "",
679
699
  ) -> None:
680
- """Log the loading of the network with relevant parameters.
700
+ """
701
+ Log the loading of the network with relevant parameters.
681
702
 
682
703
  Args:
683
704
  filetype (str): The type of the file being loaded (e.g., 'CSV', 'JSON').
@@ -0,0 +1,6 @@
1
+ """
2
+ risk/_network/_plotter
3
+ ~~~~~~~~~~~~~~~~~~~~~~
4
+ """
5
+
6
+ from ._api import PlotterAPI
@@ -1,19 +1,20 @@
1
1
  """
2
- risk/network/plotter/api
3
- ~~~~~~~~~~~~~~~~~~~~~~~~
2
+ risk/_network/_plotter/_api
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
4
  """
5
5
 
6
6
  from typing import List, Tuple, Union
7
7
 
8
8
  import numpy as np
9
9
 
10
- from risk.log import log_header
11
- from risk.network.graph.graph import Graph
12
- from risk.network.plotter.plotter import Plotter
10
+ from ..._log import log_header
11
+ from .._graph import Graph
12
+ from ._plotter import Plotter
13
13
 
14
14
 
15
15
  class PlotterAPI:
16
- """Handles the loading of network plotter objects.
16
+ """
17
+ Handles the loading of network plotter objects.
17
18
 
18
19
  The PlotterAPI class provides methods to load and configure Plotter objects for plotting network graphs.
19
20
  """
@@ -29,7 +30,8 @@ class PlotterAPI:
29
30
  background_alpha: Union[float, None] = 1.0,
30
31
  pad: float = 0.3,
31
32
  ) -> Plotter:
32
- """Get a Plotter object for plotting.
33
+ """
34
+ Get a Plotter object for plotting.
33
35
 
34
36
  Args:
35
37
  graph (Graph): The graph to plot.