risk-network 0.0.9b31__tar.gz → 0.0.9b33__tar.gz
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_network-0.0.9b31/risk_network.egg-info → risk_network-0.0.9b33}/PKG-INFO +1 -1
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/__init__.py +1 -1
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/geometry.py +1 -7
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/io.py +7 -67
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/utils/colors.py +1 -1
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/permutation/test_functions.py +1 -1
- {risk_network-0.0.9b31 → risk_network-0.0.9b33/risk_network.egg-info}/PKG-INFO +1 -1
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/LICENSE +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/MANIFEST.in +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/README.md +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/pyproject.toml +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/annotations/io.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/constants.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/log/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/log/console.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/log/parameters.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/neighborhoods/api.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/neighborhoods/domains.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/graph/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/graph/api.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/graph/graph.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/graph/summary.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/api.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/canvas.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/contour.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/labels.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/network.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/plotter.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/network/plotter/utils/layout.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/risk.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/permutation/permutation.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/significance.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk/stats/stat_tests.py +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/setup.cfg +0 -0
- {risk_network-0.0.9b31 → risk_network-0.0.9b33}/setup.py +0 -0
@@ -11,7 +11,6 @@ def assign_edge_lengths(
|
|
11
11
|
G: nx.Graph,
|
12
12
|
compute_sphere: bool = True,
|
13
13
|
surface_depth: float = 0.0,
|
14
|
-
include_edge_weight: bool = False,
|
15
14
|
) -> nx.Graph:
|
16
15
|
"""Assign edge lengths in the graph, optionally mapping nodes to a sphere and including edge weights.
|
17
16
|
|
@@ -19,7 +18,6 @@ def assign_edge_lengths(
|
|
19
18
|
G (nx.Graph): The input graph.
|
20
19
|
compute_sphere (bool): Whether to map nodes to a sphere. Defaults to True.
|
21
20
|
surface_depth (float): The surface depth for mapping to a sphere. Defaults to 0.0.
|
22
|
-
include_edge_weight (bool): Whether to include edge weights in the calculation. Defaults to False.
|
23
21
|
|
24
22
|
Returns:
|
25
23
|
nx.Graph: The graph with applied edge lengths.
|
@@ -64,11 +62,7 @@ def assign_edge_lengths(
|
|
64
62
|
distances = compute_distance_vectorized(edge_data, compute_sphere)
|
65
63
|
# Assign distances back to the graph
|
66
64
|
for (u, v), distance in zip(G_depth.edges, distances):
|
67
|
-
|
68
|
-
weight = G.edges[u, v].get("normalized_weight", 1e-6) # Avoid divide-by-zero
|
69
|
-
G.edges[u, v]["length"] = distance / np.sqrt(weight)
|
70
|
-
else:
|
71
|
-
G.edges[u, v]["length"] = distance
|
65
|
+
G.edges[u, v]["length"] = distance
|
72
66
|
|
73
67
|
return G
|
74
68
|
|
@@ -31,8 +31,6 @@ class NetworkIO:
|
|
31
31
|
compute_sphere: bool = True,
|
32
32
|
surface_depth: float = 0.0,
|
33
33
|
min_edges_per_node: int = 0,
|
34
|
-
include_edge_weight: bool = True,
|
35
|
-
weight_label: str = "weight",
|
36
34
|
):
|
37
35
|
"""Initialize the NetworkIO class.
|
38
36
|
|
@@ -40,21 +38,15 @@ class NetworkIO:
|
|
40
38
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
41
39
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
42
40
|
min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
|
43
|
-
include_edge_weight (bool, optional): Whether to include edge weights in calculations. Defaults to True.
|
44
|
-
weight_label (str, optional): Label for edge weights. Defaults to "weight".
|
45
41
|
"""
|
46
42
|
self.compute_sphere = compute_sphere
|
47
43
|
self.surface_depth = surface_depth
|
48
44
|
self.min_edges_per_node = min_edges_per_node
|
49
|
-
self.include_edge_weight = include_edge_weight
|
50
|
-
self.weight_label = weight_label
|
51
45
|
# Log the initialization of the NetworkIO class
|
52
46
|
params.log_network(
|
53
47
|
compute_sphere=compute_sphere,
|
54
48
|
surface_depth=surface_depth,
|
55
49
|
min_edges_per_node=min_edges_per_node,
|
56
|
-
include_edge_weight=include_edge_weight,
|
57
|
-
weight_label=weight_label,
|
58
50
|
)
|
59
51
|
|
60
52
|
@staticmethod
|
@@ -63,8 +55,6 @@ class NetworkIO:
|
|
63
55
|
compute_sphere: bool = True,
|
64
56
|
surface_depth: float = 0.0,
|
65
57
|
min_edges_per_node: int = 0,
|
66
|
-
include_edge_weight: bool = True,
|
67
|
-
weight_label: str = "weight",
|
68
58
|
) -> nx.Graph:
|
69
59
|
"""Load a network from a GPickle file.
|
70
60
|
|
@@ -73,8 +63,6 @@ class NetworkIO:
|
|
73
63
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
74
64
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
75
65
|
min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
|
76
|
-
include_edge_weight (bool, optional): Whether to include edge weights in calculations. Defaults to True.
|
77
|
-
weight_label (str, optional): Label for edge weights. Defaults to "weight".
|
78
66
|
|
79
67
|
Returns:
|
80
68
|
nx.Graph: Loaded and processed network.
|
@@ -83,8 +71,6 @@ class NetworkIO:
|
|
83
71
|
compute_sphere=compute_sphere,
|
84
72
|
surface_depth=surface_depth,
|
85
73
|
min_edges_per_node=min_edges_per_node,
|
86
|
-
include_edge_weight=include_edge_weight,
|
87
|
-
weight_label=weight_label,
|
88
74
|
)
|
89
75
|
return networkio._load_gpickle_network(filepath=filepath)
|
90
76
|
|
@@ -114,8 +100,6 @@ class NetworkIO:
|
|
114
100
|
compute_sphere: bool = True,
|
115
101
|
surface_depth: float = 0.0,
|
116
102
|
min_edges_per_node: int = 0,
|
117
|
-
include_edge_weight: bool = True,
|
118
|
-
weight_label: str = "weight",
|
119
103
|
) -> nx.Graph:
|
120
104
|
"""Load a NetworkX graph.
|
121
105
|
|
@@ -124,8 +108,6 @@ class NetworkIO:
|
|
124
108
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
125
109
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
126
110
|
min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
|
127
|
-
include_edge_weight (bool, optional): Whether to include edge weights in calculations. Defaults to True.
|
128
|
-
weight_label (str, optional): Label for edge weights. Defaults to "weight".
|
129
111
|
|
130
112
|
Returns:
|
131
113
|
nx.Graph: Loaded and processed network.
|
@@ -134,8 +116,6 @@ class NetworkIO:
|
|
134
116
|
compute_sphere=compute_sphere,
|
135
117
|
surface_depth=surface_depth,
|
136
118
|
min_edges_per_node=min_edges_per_node,
|
137
|
-
include_edge_weight=include_edge_weight,
|
138
|
-
weight_label=weight_label,
|
139
119
|
)
|
140
120
|
return networkio._load_networkx_network(network=network)
|
141
121
|
|
@@ -167,8 +147,6 @@ class NetworkIO:
|
|
167
147
|
compute_sphere: bool = True,
|
168
148
|
surface_depth: float = 0.0,
|
169
149
|
min_edges_per_node: int = 0,
|
170
|
-
include_edge_weight: bool = True,
|
171
|
-
weight_label: str = "weight",
|
172
150
|
) -> nx.Graph:
|
173
151
|
"""Load a network from a Cytoscape file.
|
174
152
|
|
@@ -180,8 +158,6 @@ class NetworkIO:
|
|
180
158
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
181
159
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
182
160
|
min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
|
183
|
-
include_edge_weight (bool, optional): Whether to include edge weights in calculations. Defaults to True.
|
184
|
-
weight_label (str, optional): Label for edge weights. Defaults to "weight".
|
185
161
|
|
186
162
|
Returns:
|
187
163
|
nx.Graph: Loaded and processed network.
|
@@ -190,8 +166,6 @@ class NetworkIO:
|
|
190
166
|
compute_sphere=compute_sphere,
|
191
167
|
surface_depth=surface_depth,
|
192
168
|
min_edges_per_node=min_edges_per_node,
|
193
|
-
include_edge_weight=include_edge_weight,
|
194
|
-
weight_label=weight_label,
|
195
169
|
)
|
196
170
|
return networkio._load_cytoscape_network(
|
197
171
|
filepath=filepath,
|
@@ -286,26 +260,17 @@ class NetworkIO:
|
|
286
260
|
|
287
261
|
# Set columns
|
288
262
|
attribute_table.columns = attribute_table.iloc[0]
|
289
|
-
# Skip first four rows
|
263
|
+
# Skip first four rows, select source and target columns, and reset index
|
290
264
|
attribute_table = attribute_table.iloc[4:, :]
|
291
|
-
|
292
|
-
if self.include_edge_weight:
|
293
|
-
attribute_table = attribute_table[[source_label, target_label, self.weight_label]]
|
294
|
-
else:
|
295
|
-
attribute_table = attribute_table[[source_label, target_label]]
|
296
|
-
|
265
|
+
attribute_table = attribute_table[[source_label, target_label]]
|
297
266
|
attribute_table = attribute_table.dropna().reset_index(drop=True)
|
298
267
|
# Create a graph
|
299
268
|
G = nx.Graph()
|
300
|
-
# Add edges and nodes
|
269
|
+
# Add edges and nodes
|
301
270
|
for _, row in attribute_table.iterrows():
|
302
271
|
source = row[source_label]
|
303
272
|
target = row[target_label]
|
304
|
-
|
305
|
-
weight = float(row[self.weight_label])
|
306
|
-
G.add_edge(source, target, weight=weight)
|
307
|
-
else:
|
308
|
-
G.add_edge(source, target)
|
273
|
+
G.add_edge(source, target)
|
309
274
|
|
310
275
|
if source not in G:
|
311
276
|
G.add_node(source) # Optionally add x, y coordinates here if available
|
@@ -334,8 +299,6 @@ class NetworkIO:
|
|
334
299
|
compute_sphere: bool = True,
|
335
300
|
surface_depth: float = 0.0,
|
336
301
|
min_edges_per_node: int = 0,
|
337
|
-
include_edge_weight: bool = True,
|
338
|
-
weight_label: str = "weight",
|
339
302
|
) -> nx.Graph:
|
340
303
|
"""Load a network from a Cytoscape JSON (.cyjs) file.
|
341
304
|
|
@@ -346,8 +309,6 @@ class NetworkIO:
|
|
346
309
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
347
310
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
348
311
|
min_edges_per_node (int, optional): Minimum number of edges per node. Defaults to 0.
|
349
|
-
include_edge_weight (bool, optional): Whether to include edge weights in calculations. Defaults to True.
|
350
|
-
weight_label (str, optional): Label for edge weights. Defaults to "weight".
|
351
312
|
|
352
313
|
Returns:
|
353
314
|
NetworkX graph: Loaded and processed network.
|
@@ -356,8 +317,6 @@ class NetworkIO:
|
|
356
317
|
compute_sphere=compute_sphere,
|
357
318
|
surface_depth=surface_depth,
|
358
319
|
min_edges_per_node=min_edges_per_node,
|
359
|
-
include_edge_weight=include_edge_weight,
|
360
|
-
weight_label=weight_label,
|
361
320
|
)
|
362
321
|
return networkio._load_cytoscape_json_network(
|
363
322
|
filepath=filepath,
|
@@ -403,12 +362,7 @@ class NetworkIO:
|
|
403
362
|
# Use the original source and target labels if available, otherwise fall back to default labels
|
404
363
|
source = edge_data.get(f"{source_label}_original", edge_data.get(source_label))
|
405
364
|
target = edge_data.get(f"{target_label}_original", edge_data.get(target_label))
|
406
|
-
|
407
|
-
if self.weight_label is not None and self.weight_label in edge_data:
|
408
|
-
weight = float(edge_data[self.weight_label])
|
409
|
-
G.add_edge(source, target, weight=weight)
|
410
|
-
else:
|
411
|
-
G.add_edge(source, target)
|
365
|
+
G.add_edge(source, target)
|
412
366
|
|
413
367
|
# Ensure nodes exist in the graph and add them if not present
|
414
368
|
if source not in G:
|
@@ -478,24 +432,14 @@ class NetworkIO:
|
|
478
432
|
logger.debug(f"Final edge count: {num_final_edges}")
|
479
433
|
|
480
434
|
def _assign_edge_weights(self, G: nx.Graph) -> None:
|
481
|
-
"""Assign weights to the
|
435
|
+
"""Assign default edge weights to the graph.
|
482
436
|
|
483
437
|
Args:
|
484
438
|
G (nx.Graph): A NetworkX graph object.
|
485
439
|
"""
|
486
440
|
# Set default weight for all edges in bulk
|
487
|
-
default_weight = 1
|
441
|
+
default_weight = 1
|
488
442
|
nx.set_edge_attributes(G, default_weight, "weight")
|
489
|
-
# Check and assign user-defined edge weights if available
|
490
|
-
weight_attributes = nx.get_edge_attributes(G, self.weight_label)
|
491
|
-
if weight_attributes:
|
492
|
-
nx.set_edge_attributes(G, weight_attributes, "weight")
|
493
|
-
|
494
|
-
# Log missing weights if include_edge_weight is enabled
|
495
|
-
if self.include_edge_weight:
|
496
|
-
missing_weights = len(G.edges) - len(weight_attributes)
|
497
|
-
if missing_weights > 0:
|
498
|
-
logger.debug(f"Total edges missing weights: {missing_weights}")
|
499
443
|
|
500
444
|
def _validate_nodes(self, G: nx.Graph) -> None:
|
501
445
|
"""Validate the graph structure and attributes with attribute fallback for positions and labels.
|
@@ -567,7 +511,6 @@ class NetworkIO:
|
|
567
511
|
G,
|
568
512
|
compute_sphere=self.compute_sphere,
|
569
513
|
surface_depth=self.surface_depth,
|
570
|
-
include_edge_weight=self.include_edge_weight,
|
571
514
|
)
|
572
515
|
|
573
516
|
def _log_loading(
|
@@ -585,9 +528,6 @@ class NetworkIO:
|
|
585
528
|
logger.debug(f"Filetype: {filetype}")
|
586
529
|
if filepath:
|
587
530
|
logger.debug(f"Filepath: {filepath}")
|
588
|
-
logger.debug(f"Edge weight: {'Included' if self.include_edge_weight else 'Excluded'}")
|
589
|
-
if self.include_edge_weight:
|
590
|
-
logger.debug(f"Weight label: {self.weight_label}")
|
591
531
|
logger.debug(f"Minimum edges per node: {self.min_edges_per_node}")
|
592
532
|
logger.debug(f"Projection: {'Sphere' if self.compute_sphere else 'Plane'}")
|
593
533
|
if self.compute_sphere:
|
@@ -360,7 +360,7 @@ def to_rgba(
|
|
360
360
|
|
361
361
|
def convert_to_rgba(c: Union[str, List, Tuple, np.ndarray]) -> np.ndarray:
|
362
362
|
"""Convert a single color to RGBA format, handling strings, hex, and RGB/RGBA lists."""
|
363
|
-
#
|
363
|
+
# NOTE: if no alpha is provided, the default alpha value is 1.0 by mcolors.to_rgba
|
364
364
|
if isinstance(c, str):
|
365
365
|
# Convert color names or hex values (e.g., 'red', '#FF5733') to RGBA
|
366
366
|
rgba = np.array(mcolors.to_rgba(c))
|
@@ -6,7 +6,7 @@ risk/stats/permutation/test_functions
|
|
6
6
|
import numpy as np
|
7
7
|
from scipy.sparse import csr_matrix
|
8
8
|
|
9
|
-
#
|
9
|
+
# NOTE: Cython optimizations provided minimal performance benefits.
|
10
10
|
# The final version with Cython is archived in the `cython_permutation` branch.
|
11
11
|
# DISPATCH_TEST_FUNCTIONS can be found at the end of the file.
|
12
12
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|