risk-network 0.0.13b4__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.
- risk/__init__.py +3 -2
- risk/_annotation/__init__.py +10 -0
- risk/{annotation/annotation.py → _annotation/_annotation.py} +18 -11
- risk/{annotation/io.py → _annotation/_io.py} +20 -12
- risk/{annotation/nltk_setup.py → _annotation/_nltk_setup.py} +7 -5
- risk/_log/__init__.py +11 -0
- risk/{log/console.py → _log/_console.py} +22 -12
- risk/{log/parameters.py → _log/_parameters.py} +25 -14
- risk/_neighborhoods/__init__.py +8 -0
- risk/{neighborhoods/api.py → _neighborhoods/_api.py} +23 -14
- risk/{neighborhoods/community.py → _neighborhoods/_community.py} +19 -11
- risk/{neighborhoods/domains.py → _neighborhoods/_domains.py} +15 -9
- risk/{neighborhoods/neighborhoods.py → _neighborhoods/_neighborhoods.py} +24 -35
- risk/_neighborhoods/_stats/__init__.py +13 -0
- risk/_neighborhoods/_stats/_permutation/__init__.py +6 -0
- risk/{neighborhoods/stats/permutation/permutation.py → _neighborhoods/_stats/_permutation/_permutation.py} +9 -6
- risk/{neighborhoods/stats/permutation/test_functions.py → _neighborhoods/_stats/_permutation/_test_functions.py} +6 -4
- risk/{neighborhoods/stats/tests.py → _neighborhoods/_stats/_tests.py} +12 -7
- risk/_network/__init__.py +8 -0
- risk/_network/_graph/__init__.py +7 -0
- risk/{network/graph/api.py → _network/_graph/_api.py} +13 -10
- risk/{network/graph/graph.py → _network/_graph/_graph.py} +24 -13
- risk/{network/graph/stats.py → _network/_graph/_stats.py} +8 -5
- risk/{network/graph/summary.py → _network/_graph/_summary.py} +21 -12
- risk/{network/io.py → _network/_io.py} +45 -24
- risk/_network/_plotter/__init__.py +6 -0
- risk/{network/plotter/api.py → _network/_plotter/_api.py} +9 -7
- risk/{network/plotter/canvas.py → _network/_plotter/_canvas.py} +14 -10
- risk/{network/plotter/contour.py → _network/_plotter/_contour.py} +17 -11
- risk/{network/plotter/labels.py → _network/_plotter/_labels.py} +38 -23
- risk/{network/plotter/network.py → _network/_plotter/_network.py} +17 -11
- risk/{network/plotter/plotter.py → _network/_plotter/_plotter.py} +19 -15
- risk/_network/_plotter/_utils/__init__.py +7 -0
- risk/{network/plotter/utils/colors.py → _network/_plotter/_utils/_colors.py} +19 -11
- risk/{network/plotter/utils/layout.py → _network/_plotter/_utils/_layout.py} +8 -5
- risk/risk.py +8 -8
- {risk_network-0.0.13b4.dist-info → risk_network-0.0.13b5.dist-info}/METADATA +1 -1
- risk_network-0.0.13b5.dist-info/RECORD +41 -0
- {risk_network-0.0.13b4.dist-info → risk_network-0.0.13b5.dist-info}/WHEEL +1 -1
- risk/annotation/__init__.py +0 -10
- risk/log/__init__.py +0 -11
- risk/neighborhoods/__init__.py +0 -7
- risk/neighborhoods/stats/__init__.py +0 -13
- risk/neighborhoods/stats/permutation/__init__.py +0 -6
- risk/network/__init__.py +0 -4
- risk/network/graph/__init__.py +0 -4
- risk/network/plotter/__init__.py +0 -4
- risk_network-0.0.13b4.dist-info/RECORD +0 -40
- {risk_network-0.0.13b4.dist-info → risk_network-0.0.13b5.dist-info}/licenses/LICENSE +0 -0
- {risk_network-0.0.13b4.dist-info → risk_network-0.0.13b5.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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/
|
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
|
12
|
+
from ..._log import log_header, logger
|
13
13
|
|
14
14
|
|
15
15
|
class Summary:
|
16
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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/
|
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
|
18
|
+
from .._log import log_header, logger, params
|
19
19
|
|
20
20
|
|
21
21
|
class NetworkIO:
|
22
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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
|
-
"""
|
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').
|
@@ -1,19 +1,20 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
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
|
11
|
-
from
|
12
|
-
from
|
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
|
-
"""
|
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
|
-
"""
|
33
|
+
"""
|
34
|
+
Get a Plotter object for plotting.
|
33
35
|
|
34
36
|
Args:
|
35
37
|
graph (Graph): The graph to plot.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_canvas
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import List, Tuple, Union
|
@@ -8,17 +8,18 @@ from typing import List, Tuple, Union
|
|
8
8
|
import matplotlib.pyplot as plt
|
9
9
|
import numpy as np
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
13
|
-
from
|
14
|
-
from
|
11
|
+
from ..._log import params
|
12
|
+
from .._graph import Graph
|
13
|
+
from ._utils._colors import to_rgba
|
14
|
+
from ._utils._layout import calculate_bounding_box
|
15
15
|
|
16
16
|
|
17
17
|
class Canvas:
|
18
18
|
"""A class for laying out the canvas in a network graph."""
|
19
19
|
|
20
20
|
def __init__(self, graph: Graph, ax: plt.Axes) -> None:
|
21
|
-
"""
|
21
|
+
"""
|
22
|
+
Initialize the Canvas with a Graph and axis for plotting.
|
22
23
|
|
23
24
|
Args:
|
24
25
|
graph (Graph): The Graph object containing the network data.
|
@@ -41,7 +42,8 @@ class Canvas:
|
|
41
42
|
title_space_offset: float = 0.075,
|
42
43
|
subtitle_offset: float = 0.025,
|
43
44
|
) -> None:
|
44
|
-
"""
|
45
|
+
"""
|
46
|
+
Plot title and subtitle on the network graph with customizable parameters.
|
45
47
|
|
46
48
|
Args:
|
47
49
|
title (str, optional): Title of the plot. Defaults to None.
|
@@ -122,7 +124,8 @@ class Canvas:
|
|
122
124
|
outline_alpha: Union[float, None] = 1.0,
|
123
125
|
fill_alpha: Union[float, None] = 0.0,
|
124
126
|
) -> None:
|
125
|
-
"""
|
127
|
+
"""
|
128
|
+
Plot a circle around the network graph to represent the network perimeter.
|
126
129
|
|
127
130
|
Args:
|
128
131
|
scale (float, optional): Scaling factor for the perimeter diameter. Defaults to 1.0.
|
@@ -257,7 +260,8 @@ class Canvas:
|
|
257
260
|
center_offset_x: float = 0.0,
|
258
261
|
center_offset_y: float = 0.0,
|
259
262
|
) -> Tuple[float, float]:
|
260
|
-
"""
|
263
|
+
"""
|
264
|
+
Calculate the adjusted center for the network perimeter circle based on user-defined offsets.
|
261
265
|
|
262
266
|
Args:
|
263
267
|
center (Tuple[float, float]): Original center coordinates of the network graph.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_contour
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import Any, Dict, List, Tuple, Union
|
@@ -11,16 +11,17 @@ from scipy import linalg
|
|
11
11
|
from scipy.ndimage import label
|
12
12
|
from scipy.stats import gaussian_kde
|
13
13
|
|
14
|
-
from
|
15
|
-
from
|
16
|
-
from
|
14
|
+
from ..._log import logger, params
|
15
|
+
from .._graph import Graph
|
16
|
+
from ._utils import get_annotated_domain_colors, to_rgba
|
17
17
|
|
18
18
|
|
19
19
|
class Contour:
|
20
20
|
"""Class to generate Kernel Density Estimate (KDE) contours for nodes in a network graph."""
|
21
21
|
|
22
22
|
def __init__(self, graph: Graph, ax: plt.Axes) -> None:
|
23
|
-
"""
|
23
|
+
"""
|
24
|
+
Initialize the Contour with a Graph and axis for plotting.
|
24
25
|
|
25
26
|
Args:
|
26
27
|
graph (Graph): The Graph object containing the network data.
|
@@ -40,7 +41,8 @@ class Contour:
|
|
40
41
|
alpha: Union[float, None] = 1.0,
|
41
42
|
fill_alpha: Union[float, None] = None,
|
42
43
|
) -> None:
|
43
|
-
"""
|
44
|
+
"""
|
45
|
+
Draw KDE contours for nodes in various domains of a network graph, highlighting areas of high density.
|
44
46
|
|
45
47
|
Args:
|
46
48
|
levels (int, optional): Number of contour levels to plot. Defaults to 5.
|
@@ -105,7 +107,8 @@ class Contour:
|
|
105
107
|
alpha: Union[float, None] = 1.0,
|
106
108
|
fill_alpha: Union[float, None] = None,
|
107
109
|
) -> None:
|
108
|
-
"""
|
110
|
+
"""
|
111
|
+
Plot a subcontour for a given set of nodes or a list of node sets using Kernel Density Estimation (KDE).
|
109
112
|
|
110
113
|
Args:
|
111
114
|
nodes (List, Tuple, or np.ndarray): List of node labels or list of lists of node labels to plot the contour for.
|
@@ -179,7 +182,8 @@ class Contour:
|
|
179
182
|
linewidth: float = 1.5,
|
180
183
|
fill_alpha: Union[float, None] = 0.2,
|
181
184
|
) -> None:
|
182
|
-
"""
|
185
|
+
"""
|
186
|
+
Draw a Kernel Density Estimate (KDE) contour plot for a set of nodes on a given axis.
|
183
187
|
|
184
188
|
Args:
|
185
189
|
ax (plt.Axes): The axis to draw the contour on.
|
@@ -283,7 +287,8 @@ class Contour:
|
|
283
287
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
284
288
|
random_seed: int = 888,
|
285
289
|
) -> List[Tuple]:
|
286
|
-
"""
|
290
|
+
"""
|
291
|
+
Get colors for the contours based on node annotation or a specified colormap.
|
287
292
|
|
288
293
|
Args:
|
289
294
|
cmap (str, optional): Name of the colormap to use for generating contour colors. Defaults to "gist_rainbow".
|
@@ -317,7 +322,8 @@ class Contour:
|
|
317
322
|
)
|
318
323
|
|
319
324
|
def _is_connected(self, z: np.ndarray) -> bool:
|
320
|
-
"""
|
325
|
+
"""
|
326
|
+
Determine if a thresholded grid represents a single, connected component.
|
321
327
|
|
322
328
|
Args:
|
323
329
|
z (np.ndarray): A binary grid where the component connectivity is evaluated.
|