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/_plotter/_labels
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
import copy
|
@@ -10,10 +10,9 @@ import matplotlib.pyplot as plt
|
|
10
10
|
import numpy as np
|
11
11
|
import pandas as pd
|
12
12
|
|
13
|
-
from
|
14
|
-
from
|
15
|
-
from
|
16
|
-
from risk.network.plotter.utils.layout import calculate_bounding_box
|
13
|
+
from ..._log import params
|
14
|
+
from .._graph import Graph
|
15
|
+
from ._utils import calculate_bounding_box, get_annotated_domain_colors, to_rgba
|
17
16
|
|
18
17
|
TERM_DELIMITER = "::::" # String used to separate multiple domain terms when constructing composite domain labels
|
19
18
|
|
@@ -22,7 +21,8 @@ class Labels:
|
|
22
21
|
"""Class to handle the annotation of network graphs with labels for different domains."""
|
23
22
|
|
24
23
|
def __init__(self, graph: Graph, ax: plt.Axes):
|
25
|
-
"""
|
24
|
+
"""
|
25
|
+
Initialize the Labeler object with a network graph and matplotlib axes.
|
26
26
|
|
27
27
|
Args:
|
28
28
|
graph (Graph): Graph object containing the network data.
|
@@ -56,7 +56,8 @@ class Labels:
|
|
56
56
|
ids_to_keep: Union[List, Tuple, np.ndarray, None] = None,
|
57
57
|
ids_to_labels: Union[Dict[int, str], None] = None,
|
58
58
|
) -> None:
|
59
|
-
"""
|
59
|
+
"""
|
60
|
+
Annotate the network graph with labels for different domains, positioned around the network for clarity.
|
60
61
|
|
61
62
|
Args:
|
62
63
|
scale (float, optional): Scale factor for positioning labels around the perimeter. Defaults to 1.05.
|
@@ -261,7 +262,8 @@ class Labels:
|
|
261
262
|
arrow_base_shrink: float = 0.0,
|
262
263
|
arrow_tip_shrink: float = 0.0,
|
263
264
|
) -> None:
|
264
|
-
"""
|
265
|
+
"""
|
266
|
+
Annotate the network graph with a label for the given nodes, with one arrow pointing to each centroid of sublists of nodes.
|
265
267
|
|
266
268
|
Args:
|
267
269
|
nodes (List, Tuple, or np.ndarray): List of node labels or list of lists of node labels.
|
@@ -349,7 +351,8 @@ class Labels:
|
|
349
351
|
)
|
350
352
|
|
351
353
|
def _calculate_domain_centroid(self, nodes: List) -> tuple:
|
352
|
-
"""
|
354
|
+
"""
|
355
|
+
Calculate the most centrally located node in the domain based on the coordinates of the nodes.
|
353
356
|
|
354
357
|
Args:
|
355
358
|
nodes (List): List of node labels to include in the subnetwork.
|
@@ -384,7 +387,8 @@ class Labels:
|
|
384
387
|
filtered_domain_terms: Dict[int, str],
|
385
388
|
valid_indices: List[int],
|
386
389
|
) -> None:
|
387
|
-
"""
|
390
|
+
"""
|
391
|
+
Process the ids_to_keep, apply filtering, and store valid domain centroids and terms.
|
388
392
|
|
389
393
|
Args:
|
390
394
|
domain_id_to_centroid_map (Dict[int, np.ndarray]): Mapping of domain IDs to their centroids.
|
@@ -450,7 +454,8 @@ class Labels:
|
|
450
454
|
filtered_domain_terms: Dict[int, str],
|
451
455
|
valid_indices: List[int],
|
452
456
|
) -> None:
|
453
|
-
"""
|
457
|
+
"""
|
458
|
+
Process remaining domains to fill in additional labels, respecting the remaining_labels limit.
|
454
459
|
|
455
460
|
Args:
|
456
461
|
domain_id_to_centroid_map (Dict[int, np.ndarray]): Mapping of domain IDs to their centroids.
|
@@ -551,7 +556,8 @@ class Labels:
|
|
551
556
|
filtered_domain_terms: Dict[int, str],
|
552
557
|
valid_indices: List[int],
|
553
558
|
) -> bool:
|
554
|
-
"""
|
559
|
+
"""
|
560
|
+
Validate and process the domain terms, updating relevant dictionaries if valid.
|
555
561
|
|
556
562
|
Args:
|
557
563
|
domain_id (int): Domain ID to process.
|
@@ -607,7 +613,8 @@ class Labels:
|
|
607
613
|
min_chars_per_line: int,
|
608
614
|
max_chars_per_line: int,
|
609
615
|
) -> str:
|
610
|
-
"""
|
616
|
+
"""
|
617
|
+
Process terms for a domain, applying word length constraints and combining words where appropriate.
|
611
618
|
|
612
619
|
Args:
|
613
620
|
domain_id (int): Domain ID to process.
|
@@ -646,7 +653,8 @@ class Labels:
|
|
646
653
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
647
654
|
random_seed: int = 888,
|
648
655
|
) -> List:
|
649
|
-
"""
|
656
|
+
"""
|
657
|
+
Get colors for the labels based on node annotation or a specified colormap.
|
650
658
|
|
651
659
|
Args:
|
652
660
|
cmap (str, optional): Name of the colormap to use for generating label colors. Defaults to "gist_rainbow".
|
@@ -682,8 +690,9 @@ class Labels:
|
|
682
690
|
def _combine_words(
|
683
691
|
self, words: List[str], max_chars_per_line: int, max_label_lines: int
|
684
692
|
) -> str:
|
685
|
-
"""
|
686
|
-
|
693
|
+
"""
|
694
|
+
Combine words to fit within the max_chars_per_line and max_label_lines constraints, and separate the
|
695
|
+
final output by TERM_DELIMITER for plotting.
|
687
696
|
|
688
697
|
Args:
|
689
698
|
words (List[str]): List of words to combine.
|
@@ -753,7 +762,8 @@ class Labels:
|
|
753
762
|
radius: float,
|
754
763
|
offset: float,
|
755
764
|
) -> Dict[int, Any]:
|
756
|
-
"""
|
765
|
+
"""
|
766
|
+
Calculate and optimize label positions for clarity.
|
757
767
|
|
758
768
|
Args:
|
759
769
|
filtered_domain_centroids (Dict[int, Any]): Centroids of the filtered domains.
|
@@ -777,7 +787,8 @@ class Labels:
|
|
777
787
|
def _calculate_equidistant_positions_around_center(
|
778
788
|
self, center: Tuple[float, float], radius: float, label_offset: float, num_domains: int
|
779
789
|
) -> List[np.ndarray]:
|
780
|
-
"""
|
790
|
+
"""
|
791
|
+
Calculate positions around a center at equidistant angles.
|
781
792
|
|
782
793
|
Args:
|
783
794
|
center (Tuple[float, float]): The center point around which positions are calculated.
|
@@ -799,7 +810,8 @@ class Labels:
|
|
799
810
|
def _optimize_label_positions(
|
800
811
|
self, best_label_positions: Dict[int, Any], domain_centroids: Dict[int, Any]
|
801
812
|
) -> Dict[int, Any]:
|
802
|
-
"""
|
813
|
+
"""
|
814
|
+
Optimize label positions around the perimeter to minimize total distance to centroids.
|
803
815
|
|
804
816
|
Args:
|
805
817
|
best_label_positions (Dict[int, Any]): Initial positions of labels around the perimeter.
|
@@ -838,7 +850,8 @@ class Labels:
|
|
838
850
|
def _calculate_total_distance(
|
839
851
|
self, label_positions: Dict[int, Any], domain_centroids: Dict[int, Any]
|
840
852
|
) -> float:
|
841
|
-
"""
|
853
|
+
"""
|
854
|
+
Calculate the total distance from label positions to their domain centroids.
|
842
855
|
|
843
856
|
Args:
|
844
857
|
label_positions (Dict[int, Any]): Positions of labels around the perimeter.
|
@@ -862,7 +875,8 @@ class Labels:
|
|
862
875
|
j: int,
|
863
876
|
domain_centroids: Dict[int, Any],
|
864
877
|
) -> float:
|
865
|
-
"""
|
878
|
+
"""
|
879
|
+
Swap two labels and evaluate the total distance after the swap.
|
866
880
|
|
867
881
|
Args:
|
868
882
|
label_positions (Dict[int, Any]): Positions of labels around the perimeter.
|
@@ -887,7 +901,8 @@ class Labels:
|
|
887
901
|
def _apply_str_transformation(
|
888
902
|
self, words: List[str], transformation: Union[str, Dict[str, str]]
|
889
903
|
) -> List[str]:
|
890
|
-
"""
|
904
|
+
"""
|
905
|
+
Apply a user-specified case transformation to each word in the list without appending duplicates.
|
891
906
|
|
892
907
|
Args:
|
893
908
|
words (List[str]): A list of words to transform.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_network
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import Any, Dict, List, Tuple, Union
|
@@ -8,19 +8,21 @@ from typing import Any, Dict, List, Tuple, Union
|
|
8
8
|
import networkx as nx
|
9
9
|
import numpy as np
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
13
|
-
from
|
11
|
+
from ..._log import params
|
12
|
+
from .._graph import Graph
|
13
|
+
from ._utils import get_domain_colors, to_rgba
|
14
14
|
|
15
15
|
|
16
16
|
class Network:
|
17
|
-
"""
|
17
|
+
"""
|
18
|
+
A class for plotting network graphs with customizable options.
|
18
19
|
|
19
20
|
The Network class provides methods to plot network graphs with flexible node and edge properties.
|
20
21
|
"""
|
21
22
|
|
22
23
|
def __init__(self, graph: Graph, ax: Any = None) -> None:
|
23
|
-
"""
|
24
|
+
"""
|
25
|
+
Initialize the Plotter class.
|
24
26
|
|
25
27
|
Args:
|
26
28
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -41,7 +43,8 @@ class Network:
|
|
41
43
|
node_alpha: Union[float, None] = 1.0,
|
42
44
|
edge_alpha: Union[float, None] = 1.0,
|
43
45
|
) -> None:
|
44
|
-
"""
|
46
|
+
"""
|
47
|
+
Plot the network graph with customizable node colors, sizes, edge widths, and node edge widths.
|
45
48
|
|
46
49
|
Args:
|
47
50
|
node_size (int or np.ndarray, optional): Size of the nodes. Can be a single integer or an array of sizes. Defaults to 50.
|
@@ -124,7 +127,8 @@ class Network:
|
|
124
127
|
node_alpha: Union[float, None] = None,
|
125
128
|
edge_alpha: Union[float, None] = None,
|
126
129
|
) -> None:
|
127
|
-
"""
|
130
|
+
"""
|
131
|
+
Plot a subnetwork of selected nodes with customizable node and edge attributes.
|
128
132
|
|
129
133
|
Args:
|
130
134
|
nodes (List, Tuple, or np.ndarray): List of node labels to include in the subnetwork. Accepts nested lists.
|
@@ -211,7 +215,8 @@ class Network:
|
|
211
215
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
212
216
|
random_seed: int = 888,
|
213
217
|
) -> np.ndarray:
|
214
|
-
"""
|
218
|
+
"""
|
219
|
+
Adjust the colors of nodes in the network graph based on significance.
|
215
220
|
|
216
221
|
Args:
|
217
222
|
cmap (str, optional): Colormap to use for coloring the nodes. Defaults to "gist_rainbow".
|
@@ -270,7 +275,8 @@ class Network:
|
|
270
275
|
def get_annotated_node_sizes(
|
271
276
|
self, significant_size: int = 50, nonsignificant_size: int = 25
|
272
277
|
) -> np.ndarray:
|
273
|
-
"""
|
278
|
+
"""
|
279
|
+
Adjust the sizes of nodes in the network graph based on whether they are significant or not.
|
274
280
|
|
275
281
|
Args:
|
276
282
|
significant_size (int): Size for significant nodes. Defaults to 50.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_plotter
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import List, Tuple, Union
|
@@ -8,18 +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
|
15
|
-
from
|
16
|
-
from
|
17
|
-
from
|
18
|
-
from risk.network.plotter.utils.layout import calculate_bounding_box
|
11
|
+
from ..._log import params
|
12
|
+
from .._graph._graph import Graph
|
13
|
+
from ._canvas import Canvas
|
14
|
+
from ._contour import Contour
|
15
|
+
from ._labels import Labels
|
16
|
+
from ._network import Network
|
17
|
+
from ._utils import calculate_bounding_box, to_rgba
|
19
18
|
|
20
19
|
|
21
20
|
class Plotter(Canvas, Network, Contour, Labels):
|
22
|
-
"""
|
21
|
+
"""
|
22
|
+
A class for visualizing network graphs with customizable options.
|
23
23
|
|
24
24
|
The Plotter class uses a Graph object and provides methods to plot the network with
|
25
25
|
flexible node and edge properties. It also supports plotting labels, contours, drawing the network's
|
@@ -34,7 +34,8 @@ class Plotter(Canvas, Network, Contour, Labels):
|
|
34
34
|
background_alpha: Union[float, None] = 1.0,
|
35
35
|
pad: float = 0.3,
|
36
36
|
) -> None:
|
37
|
-
"""
|
37
|
+
"""
|
38
|
+
Initialize the Plotter with a Graph object and plotting parameters.
|
38
39
|
|
39
40
|
Args:
|
40
41
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -63,7 +64,8 @@ class Plotter(Canvas, Network, Contour, Labels):
|
|
63
64
|
background_alpha: Union[float, None],
|
64
65
|
pad: float,
|
65
66
|
) -> plt.Axes:
|
66
|
-
"""
|
67
|
+
"""
|
68
|
+
Set up the plot with figure size and background color.
|
67
69
|
|
68
70
|
Args:
|
69
71
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -115,7 +117,8 @@ class Plotter(Canvas, Network, Contour, Labels):
|
|
115
117
|
return ax
|
116
118
|
|
117
119
|
def savefig(self, *args, pad_inches: float = 0.5, dpi: int = 100, **kwargs) -> None:
|
118
|
-
"""
|
120
|
+
"""
|
121
|
+
Save the current plot to a file with additional export options.
|
119
122
|
|
120
123
|
Args:
|
121
124
|
*args: Positional arguments passed to `plt.savefig`.
|
@@ -132,7 +135,8 @@ class Plotter(Canvas, Network, Contour, Labels):
|
|
132
135
|
plt.savefig(*args, **kwargs)
|
133
136
|
|
134
137
|
def show(self, *args, **kwargs) -> None:
|
135
|
-
"""
|
138
|
+
"""
|
139
|
+
Display the current plot.
|
136
140
|
|
137
141
|
Args:
|
138
142
|
*args: Positional arguments passed to `plt.show`.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_utils/_colors
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import Any, Dict, List, Tuple, Union
|
@@ -9,7 +9,7 @@ import matplotlib
|
|
9
9
|
import matplotlib.colors as mcolors
|
10
10
|
import numpy as np
|
11
11
|
|
12
|
-
from
|
12
|
+
from ..._graph import Graph
|
13
13
|
|
14
14
|
|
15
15
|
def get_annotated_domain_colors(
|
@@ -24,7 +24,8 @@ def get_annotated_domain_colors(
|
|
24
24
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
25
25
|
random_seed: int = 888,
|
26
26
|
) -> List[Tuple]:
|
27
|
-
"""
|
27
|
+
"""
|
28
|
+
Get colors for the domains based on node annotation, or use a specified color.
|
28
29
|
|
29
30
|
Args:
|
30
31
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -85,7 +86,8 @@ def get_domain_colors(
|
|
85
86
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
86
87
|
random_seed: int = 888,
|
87
88
|
) -> np.ndarray:
|
88
|
-
"""
|
89
|
+
"""
|
90
|
+
Generate composite colors for domains based on significance or specified colors.
|
89
91
|
|
90
92
|
Args:
|
91
93
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -135,7 +137,8 @@ def _get_domain_ids_to_colors(
|
|
135
137
|
ids_to_colors: Union[Dict[int, Any], None] = None,
|
136
138
|
random_seed: int = 888,
|
137
139
|
) -> Dict[int, Any]:
|
138
|
-
"""
|
140
|
+
"""
|
141
|
+
Get colors for each domain.
|
139
142
|
|
140
143
|
Args:
|
141
144
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -174,7 +177,8 @@ def _get_composite_node_colors(
|
|
174
177
|
blend_colors: bool = False,
|
175
178
|
blend_gamma: float = 2.2,
|
176
179
|
) -> np.ndarray:
|
177
|
-
"""
|
180
|
+
"""
|
181
|
+
Generate composite colors for nodes based on domain colors and significance values, with optional color blending.
|
178
182
|
|
179
183
|
Args:
|
180
184
|
graph (Graph): The network data and attributes to be visualized.
|
@@ -233,7 +237,8 @@ def _get_colors(
|
|
233
237
|
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
234
238
|
random_seed: int = 888,
|
235
239
|
) -> List[Tuple]:
|
236
|
-
"""
|
240
|
+
"""
|
241
|
+
Generate a list of RGBA colors for domains, ensuring maximally separated colors for nearby domains.
|
237
242
|
|
238
243
|
Args:
|
239
244
|
domain_id_to_node_ids_map (Dict[int, Any]): Mapping from domain IDs to lists of node IDs.
|
@@ -266,7 +271,8 @@ def _get_colors(
|
|
266
271
|
def _blend_colors_perceptually(
|
267
272
|
colors: Union[List, Tuple, np.ndarray], significances: List[float], gamma: float = 2.2
|
268
273
|
) -> Tuple[float, float, float, float]:
|
269
|
-
"""
|
274
|
+
"""
|
275
|
+
Blends a list of RGBA colors using gamma correction for perceptually uniform color mixing.
|
270
276
|
|
271
277
|
Args:
|
272
278
|
colors (List, Tuple, np.ndarray): List of RGBA colors. Can be a list, tuple, or NumPy array of RGBA values.
|
@@ -297,7 +303,8 @@ def _transform_colors(
|
|
297
303
|
max_scale: float = 1.0,
|
298
304
|
scale_factor: float = 1.0,
|
299
305
|
) -> np.ndarray:
|
300
|
-
"""
|
306
|
+
"""
|
307
|
+
Transform colors using power scaling to emphasize high significance sums more. Black colors are replaced with
|
301
308
|
very dark grey to avoid issues with color scaling (rgb(0.1, 0.1, 0.1)).
|
302
309
|
|
303
310
|
Args:
|
@@ -349,7 +356,8 @@ def to_rgba(
|
|
349
356
|
alpha: Union[float, None] = None,
|
350
357
|
num_repeats: Union[int, None] = None,
|
351
358
|
) -> np.ndarray:
|
352
|
-
"""
|
359
|
+
"""
|
360
|
+
Convert color(s) to RGBA format, applying alpha and repeating as needed.
|
353
361
|
|
354
362
|
Args:
|
355
363
|
color (str, List, Tuple, np.ndarray, None): The color(s) to convert. Can be a string (e.g., 'red'), a list or tuple of RGB/RGBA values,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
risk/
|
3
|
-
|
2
|
+
risk/_network/_plotter/_utils/_layout
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
6
|
from typing import Any, Dict, List, Tuple
|
@@ -12,7 +12,8 @@ import numpy as np
|
|
12
12
|
def calculate_bounding_box(
|
13
13
|
node_coordinates: np.ndarray, radius_margin: float = 1.05
|
14
14
|
) -> Tuple[Tuple, float]:
|
15
|
-
"""
|
15
|
+
"""
|
16
|
+
Calculate the bounding box of the network based on node coordinates.
|
16
17
|
|
17
18
|
Args:
|
18
19
|
node_coordinates (np.ndarray): Array of node coordinates (x, y).
|
@@ -37,7 +38,8 @@ def refine_center_iteratively(
|
|
37
38
|
max_iterations: int = 10,
|
38
39
|
tolerance: float = 1e-2,
|
39
40
|
) -> Tuple[np.ndarray, float]:
|
40
|
-
"""
|
41
|
+
"""
|
42
|
+
Refine the center of the graph iteratively to minimize skew in node distribution.
|
41
43
|
|
42
44
|
Args:
|
43
45
|
node_coordinates (np.ndarray): Array of node coordinates (x, y).
|
@@ -72,7 +74,8 @@ def refine_center_iteratively(
|
|
72
74
|
def calculate_centroids(
|
73
75
|
network: nx.Graph, domain_id_to_node_ids_map: Dict[int, Any]
|
74
76
|
) -> List[Tuple[float, float]]:
|
75
|
-
"""
|
77
|
+
"""
|
78
|
+
Calculate the centroid for each domain based on node x and y coordinates in the network.
|
76
79
|
|
77
80
|
Args:
|
78
81
|
network (nx.Graph): The graph representing the network.
|
risk/risk.py
CHANGED
@@ -3,16 +3,15 @@ risk/risk
|
|
3
3
|
~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from risk.network.io import NetworkIO
|
11
|
-
from risk.network.plotter.api import PlotterAPI
|
6
|
+
from ._annotation import AnnotationIO
|
7
|
+
from ._log import params, set_global_verbosity
|
8
|
+
from ._neighborhoods import NeighborhoodsAPI
|
9
|
+
from ._network import GraphAPI, NetworkIO, PlotterAPI
|
12
10
|
|
13
11
|
|
14
12
|
class RISK(NetworkIO, AnnotationIO, NeighborhoodsAPI, GraphAPI, PlotterAPI):
|
15
|
-
"""
|
13
|
+
"""
|
14
|
+
RISK: A class for network analysis and visualization.
|
16
15
|
|
17
16
|
The RISK class integrates functionalities for loading networks, processing annotations,
|
18
17
|
performing network-based statistical analysis to quantify neighborhood relationships,
|
@@ -20,7 +19,8 @@ class RISK(NetworkIO, AnnotationIO, NeighborhoodsAPI, GraphAPI, PlotterAPI):
|
|
20
19
|
"""
|
21
20
|
|
22
21
|
def __init__(self, verbose: bool = True):
|
23
|
-
"""
|
22
|
+
"""
|
23
|
+
Initialize the RISK class with configuration settings.
|
24
24
|
|
25
25
|
Args:
|
26
26
|
verbose (bool): If False, suppresses all log messages to the console. Defaults to True.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
risk/__init__.py,sha256=lyhdzjETYJ9Jg8da35gncJ_u2_QrElRsW5t1c69OIJY,142
|
2
|
+
risk/risk.py,sha256=l7Btltgd-K00rmUV4_jTgJTwikSmMb-9A2IUQN5PnY8,1040
|
3
|
+
risk/_annotation/__init__.py,sha256=LBLL5P_MdfwWaxkHBQHfQTPY-FF8hIGoUGKyHF1Wg4s,159
|
4
|
+
risk/_annotation/_annotation.py,sha256=03vcnkdi4HGH5UUyokUyOdyyjXOLoKSmLFuK7VAl41c,15174
|
5
|
+
risk/_annotation/_io.py,sha256=gEq6STSWFIFjSWoGXJfwxTME4GDJZTOgPeXZABgSdXc,12447
|
6
|
+
risk/_annotation/_nltk_setup.py,sha256=aHHnElLOKiouVDrZ3uON0CSFmBxvzmYfjYPi07v2rJM,3584
|
7
|
+
risk/_log/__init__.py,sha256=LX6BsfcGOH0RbAdQaUmIU-LVMmArDdKwn0jFtj45FYo,205
|
8
|
+
risk/_log/_console.py,sha256=1jSFzY3w0-vVqIBCgc-IhyJPNT6vRg8GSGxhyw_D9MI,4653
|
9
|
+
risk/_log/_parameters.py,sha256=8FkeeBtULDFVw3UijLArK-G3OIjy6YXyRXmPPckK7fU,5893
|
10
|
+
risk/_neighborhoods/__init__.py,sha256=eKwjpEUKSUmAirRZ_qPTVF7MLkvhCn_fulPVq158wM8,185
|
11
|
+
risk/_neighborhoods/_api.py,sha256=6vt25y38wSvEhMvNxy9Rl-CrQc9ARSuvGwexWagg5z0,23344
|
12
|
+
risk/_neighborhoods/_community.py,sha256=Tr-EHO91EWbMmNr_z21UCngiqWOlWIqcjwBig_VXI8c,17850
|
13
|
+
risk/_neighborhoods/_domains.py,sha256=He8G2-E9-yYQB8ChUtMFr51HVlfRj5EaxGu3sGVNUCo,14630
|
14
|
+
risk/_neighborhoods/_neighborhoods.py,sha256=9H7BickJx9GdnOo5d5wpdtXkcWyvzq2w6FAy1rwLBtk,20614
|
15
|
+
risk/_neighborhoods/_stats/__init__.py,sha256=nL83A3unzpCTzRDPanCiqU1RsKPJJNDe46S9igoe3pg,264
|
16
|
+
risk/_neighborhoods/_stats/_tests.py,sha256=-ioHdyrsgW63YnypKFpanatauuKrF3LT7aMZ3b6otrU,12091
|
17
|
+
risk/_neighborhoods/_stats/_permutation/__init__.py,sha256=nfTaW29CK8OZCdFnpMVlHnFaqr1E4AZp6mvhlUazHXM,140
|
18
|
+
risk/_neighborhoods/_stats/_permutation/_permutation.py,sha256=e5qVuYWGhiAn5Jv8VILk-WYMOO4km48cGdRYTOl355M,10661
|
19
|
+
risk/_neighborhoods/_stats/_permutation/_test_functions.py,sha256=lGI_MkdbW4UHI0jWN_T1OattRjXrq_qmzAmOfels670,3165
|
20
|
+
risk/_network/__init__.py,sha256=LbXsJGU2-ydDMw5_qgwizE6YHMljGDuOGc6TO-jk4Pk,126
|
21
|
+
risk/_network/_io.py,sha256=vOSfAWnj1Q4jQSVo9BqY-nwQIoEG-CYZ_Cv2clopVw0,28090
|
22
|
+
risk/_network/_graph/__init__.py,sha256=SFgxgxUiZK4vvw6bdQ04DSMXEr8xjMaQV-Wne6wAIqM,104
|
23
|
+
risk/_network/_graph/_api.py,sha256=zH7n-ulqLcbgHdAfLu1yWErdR5G4LgSqR7DcN2qApco,8520
|
24
|
+
risk/_network/_graph/_graph.py,sha256=x2EWT_ZVwxh7m9a01yG4WMdmAxBxiaxX3CvkqP9QAXE,12486
|
25
|
+
risk/_network/_graph/_stats.py,sha256=6mxZkuL6LJlwKDsBbP22DAVkNUEhq-JZwYMKhFKD08k,7359
|
26
|
+
risk/_network/_graph/_summary.py,sha256=4eGhCArssePDg4LXr3sg5bUpNn7KFK9oPZcCz5lJKEQ,10334
|
27
|
+
risk/_network/_plotter/__init__.py,sha256=qFRtQKSBGIqmUGwmA7VPL7hTHBb9yvRIt0nLISXnwkY,84
|
28
|
+
risk/_network/_plotter/_api.py,sha256=MHZIMTlul2u-Ve5m9r-eUljI2oC3IRklNn7AVlfmzGs,1773
|
29
|
+
risk/_network/_plotter/_canvas.py,sha256=H7rPz4Gv7ED3bDHMif4cf2usdU4ifmxzXeug5A_no68,13599
|
30
|
+
risk/_network/_plotter/_contour.py,sha256=E3ILjlv-VBSbK3ClwObB84TvP1D48_B47ODXwtApjIE,15557
|
31
|
+
risk/_network/_plotter/_labels.py,sha256=8JXzEOIBQefwr1ngF-2ZYCnYLZXs2Erz-R1c28NnsL0,46915
|
32
|
+
risk/_network/_plotter/_network.py,sha256=W9eUUER9_qi1ubGaUfMp12gxAANZP-JNFKcG27I1nAk,14198
|
33
|
+
risk/_network/_plotter/_plotter.py,sha256=F2hw-spUdsXjvuG36o0YFR3Pnd-CZOHYUq4vW0Qxzlk,6011
|
34
|
+
risk/_network/_plotter/_utils/__init__.py,sha256=JXgjKiBWvXx0X2IeFnrOh5YZQGQoELbhJZ0Zh2mFEOo,211
|
35
|
+
risk/_network/_plotter/_utils/_colors.py,sha256=JCliSvz8_-TsjilaRHSEsqdXFBUYlzhXKOSRGdCm9Kw,19177
|
36
|
+
risk/_network/_plotter/_utils/_layout.py,sha256=GyGLc2U1WWUVL1Te9uPi_CLqlW_E4TImXRAL5TeA5D8,3633
|
37
|
+
risk_network-0.0.13b5.dist-info/licenses/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
38
|
+
risk_network-0.0.13b5.dist-info/METADATA,sha256=dkYs8JCdMr945DZ-7bJ95MX0zuxfbkw1VpOhuLtCE_U,6853
|
39
|
+
risk_network-0.0.13b5.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
40
|
+
risk_network-0.0.13b5.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
41
|
+
risk_network-0.0.13b5.dist-info/RECORD,,
|
risk/annotation/__init__.py
DELETED
risk/log/__init__.py
DELETED
risk/neighborhoods/__init__.py
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
risk/neighborhoods/stats
|
3
|
-
~~~~~~~~~~~~~~~~~~~~~~~~
|
4
|
-
"""
|
5
|
-
|
6
|
-
from risk.neighborhoods.stats.permutation import compute_permutation_test
|
7
|
-
from risk.neighborhoods.stats.tests import (
|
8
|
-
compute_binom_test,
|
9
|
-
compute_chi2_test,
|
10
|
-
compute_hypergeom_test,
|
11
|
-
compute_poisson_test,
|
12
|
-
compute_zscore_test,
|
13
|
-
)
|
risk/network/__init__.py
DELETED
risk/network/graph/__init__.py
DELETED
risk/network/plotter/__init__.py
DELETED