risk-network 0.0.9b32__tar.gz → 0.0.9b34__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.9b32/risk_network.egg-info → risk_network-0.0.9b34}/PKG-INFO +1 -1
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/__init__.py +1 -1
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/neighborhoods/api.py +3 -3
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/geometry.py +1 -7
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/io.py +22 -66
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/utils/colors.py +1 -1
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/permutation/test_functions.py +6 -10
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/stat_tests.py +3 -3
- {risk_network-0.0.9b32 → risk_network-0.0.9b34/risk_network.egg-info}/PKG-INFO +1 -1
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/LICENSE +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/MANIFEST.in +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/README.md +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/pyproject.toml +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/annotations/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/annotations/annotations.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/annotations/io.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/constants.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/log/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/log/console.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/log/parameters.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/neighborhoods/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/neighborhoods/community.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/neighborhoods/domains.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/neighborhoods/neighborhoods.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/graph/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/graph/api.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/graph/graph.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/graph/summary.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/api.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/canvas.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/contour.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/labels.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/network.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/plotter.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/network/plotter/utils/layout.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/risk.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/permutation/__init__.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/permutation/permutation.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk/stats/significance.py +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk_network.egg-info/SOURCES.txt +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk_network.egg-info/dependency_links.txt +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk_network.egg-info/requires.txt +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/risk_network.egg-info/top_level.txt +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/setup.cfg +0 -0
- {risk_network-0.0.9b32 → risk_network-0.0.9b34}/setup.py +0 -0
@@ -280,7 +280,7 @@ class NeighborhoodsAPI:
|
|
280
280
|
null_distribution: str = "network",
|
281
281
|
random_seed: int = 888,
|
282
282
|
) -> Dict[str, Any]:
|
283
|
-
"""Load significant neighborhoods for the network using the
|
283
|
+
"""Load significant neighborhoods for the network using the z-score test.
|
284
284
|
|
285
285
|
Args:
|
286
286
|
network (nx.Graph): The network graph.
|
@@ -299,8 +299,8 @@ class NeighborhoodsAPI:
|
|
299
299
|
Returns:
|
300
300
|
Dict[str, Any]: Computed significance of neighborhoods.
|
301
301
|
"""
|
302
|
-
log_header("Running
|
303
|
-
# Compute neighborhood significance using the
|
302
|
+
log_header("Running z-score test")
|
303
|
+
# Compute neighborhood significance using the z-score test
|
304
304
|
return self._load_neighborhoods_by_statistical_test(
|
305
305
|
network=network,
|
306
306
|
annotations=annotations,
|
@@ -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,27 +260,34 @@ 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
|
-
|
293
|
-
attribute_table = attribute_table[[source_label, target_label, self.weight_label]]
|
294
|
-
else:
|
265
|
+
try:
|
266
|
+
# Attempt to filter the attribute_table with the given labels
|
295
267
|
attribute_table = attribute_table[[source_label, target_label]]
|
268
|
+
except KeyError as e:
|
269
|
+
# Find which key(s) caused the issue
|
270
|
+
missing_keys = [
|
271
|
+
key
|
272
|
+
for key in [source_label, target_label]
|
273
|
+
if key not in attribute_table.columns
|
274
|
+
]
|
275
|
+
# Raise the KeyError with details about the issue and available options
|
276
|
+
available_columns = ", ".join(attribute_table.columns)
|
277
|
+
raise KeyError(
|
278
|
+
f"The column(s) '{', '.join(missing_keys)}' do not exist in the table. "
|
279
|
+
f"Available columns are: {available_columns}."
|
280
|
+
) from e
|
296
281
|
|
297
282
|
attribute_table = attribute_table.dropna().reset_index(drop=True)
|
283
|
+
|
298
284
|
# Create a graph
|
299
285
|
G = nx.Graph()
|
300
|
-
# Add edges and nodes
|
286
|
+
# Add edges and nodes
|
301
287
|
for _, row in attribute_table.iterrows():
|
302
288
|
source = row[source_label]
|
303
289
|
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)
|
309
|
-
|
290
|
+
G.add_edge(source, target)
|
310
291
|
if source not in G:
|
311
292
|
G.add_node(source) # Optionally add x, y coordinates here if available
|
312
293
|
if target not in G:
|
@@ -334,8 +315,6 @@ class NetworkIO:
|
|
334
315
|
compute_sphere: bool = True,
|
335
316
|
surface_depth: float = 0.0,
|
336
317
|
min_edges_per_node: int = 0,
|
337
|
-
include_edge_weight: bool = True,
|
338
|
-
weight_label: str = "weight",
|
339
318
|
) -> nx.Graph:
|
340
319
|
"""Load a network from a Cytoscape JSON (.cyjs) file.
|
341
320
|
|
@@ -346,8 +325,6 @@ class NetworkIO:
|
|
346
325
|
compute_sphere (bool, optional): Whether to map nodes to a sphere. Defaults to True.
|
347
326
|
surface_depth (float, optional): Surface depth for the sphere. Defaults to 0.0.
|
348
327
|
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
328
|
|
352
329
|
Returns:
|
353
330
|
NetworkX graph: Loaded and processed network.
|
@@ -356,8 +333,6 @@ class NetworkIO:
|
|
356
333
|
compute_sphere=compute_sphere,
|
357
334
|
surface_depth=surface_depth,
|
358
335
|
min_edges_per_node=min_edges_per_node,
|
359
|
-
include_edge_weight=include_edge_weight,
|
360
|
-
weight_label=weight_label,
|
361
336
|
)
|
362
337
|
return networkio._load_cytoscape_json_network(
|
363
338
|
filepath=filepath,
|
@@ -403,12 +378,7 @@ class NetworkIO:
|
|
403
378
|
# Use the original source and target labels if available, otherwise fall back to default labels
|
404
379
|
source = edge_data.get(f"{source_label}_original", edge_data.get(source_label))
|
405
380
|
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)
|
381
|
+
G.add_edge(source, target)
|
412
382
|
|
413
383
|
# Ensure nodes exist in the graph and add them if not present
|
414
384
|
if source not in G:
|
@@ -478,24 +448,14 @@ class NetworkIO:
|
|
478
448
|
logger.debug(f"Final edge count: {num_final_edges}")
|
479
449
|
|
480
450
|
def _assign_edge_weights(self, G: nx.Graph) -> None:
|
481
|
-
"""Assign weights to the
|
451
|
+
"""Assign default edge weights to the graph.
|
482
452
|
|
483
453
|
Args:
|
484
454
|
G (nx.Graph): A NetworkX graph object.
|
485
455
|
"""
|
486
456
|
# Set default weight for all edges in bulk
|
487
|
-
default_weight = 1
|
457
|
+
default_weight = 1
|
488
458
|
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
459
|
|
500
460
|
def _validate_nodes(self, G: nx.Graph) -> None:
|
501
461
|
"""Validate the graph structure and attributes with attribute fallback for positions and labels.
|
@@ -567,7 +527,6 @@ class NetworkIO:
|
|
567
527
|
G,
|
568
528
|
compute_sphere=self.compute_sphere,
|
569
529
|
surface_depth=self.surface_depth,
|
570
|
-
include_edge_weight=self.include_edge_weight,
|
571
530
|
)
|
572
531
|
|
573
532
|
def _log_loading(
|
@@ -585,9 +544,6 @@ class NetworkIO:
|
|
585
544
|
logger.debug(f"Filetype: {filetype}")
|
586
545
|
if filepath:
|
587
546
|
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
547
|
logger.debug(f"Minimum edges per node: {self.min_edges_per_node}")
|
592
548
|
logger.debug(f"Projection: {'Sphere' if self.compute_sphere else 'Plane'}")
|
593
549
|
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
|
|
@@ -46,23 +46,19 @@ def compute_neighborhood_score_by_stdev(
|
|
46
46
|
neighborhood_score = neighborhoods_matrix @ annotation_matrix # Sparse matrix multiplication
|
47
47
|
# Calculate the number of elements in each neighborhood (sum of rows)
|
48
48
|
N = neighborhoods_matrix.sum(axis=1).A.flatten() # Convert to 1D array
|
49
|
-
|
50
|
-
|
51
|
-
N = np.where(N == 0, np.nan, N)
|
52
|
-
|
49
|
+
# Avoid division by zero by replacing zeros in N with np.nan temporarily
|
50
|
+
N[N == 0] = np.nan
|
53
51
|
# Compute the mean of the neighborhood scores
|
54
52
|
M = neighborhood_score.multiply(1 / N[:, None]).toarray() # Sparse element-wise division
|
55
53
|
# Compute the mean of squares (EXX) directly using squared annotation matrix
|
56
54
|
annotation_squared = annotation_matrix.multiply(annotation_matrix) # Element-wise squaring
|
57
55
|
EXX = (neighborhoods_matrix @ annotation_squared).multiply(1 / N[:, None]).toarray()
|
58
|
-
|
59
|
-
|
60
|
-
variance = np.maximum(EXX - np.power(M, 2), 0)
|
56
|
+
# Calculate variance as EXX - M^2
|
57
|
+
variance = EXX - np.power(M, 2)
|
61
58
|
# Compute the standard deviation as the square root of the variance
|
62
59
|
neighborhood_stdev = np.sqrt(variance)
|
63
|
-
# Replace np.nan back with zeros
|
60
|
+
# Replace np.nan back with zeros in case N was 0 (no elements in the neighborhood)
|
64
61
|
neighborhood_stdev[np.isnan(neighborhood_stdev)] = 0
|
65
|
-
|
66
62
|
return neighborhood_stdev
|
67
63
|
|
68
64
|
|
@@ -215,7 +215,7 @@ def compute_zscore_test(
|
|
215
215
|
null_distribution: str = "network",
|
216
216
|
) -> Dict[str, Any]:
|
217
217
|
"""
|
218
|
-
Compute
|
218
|
+
Compute z-score test for enrichment and depletion in neighborhoods with selectable null distribution.
|
219
219
|
|
220
220
|
Args:
|
221
221
|
neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
|
@@ -257,10 +257,10 @@ def compute_zscore_test(
|
|
257
257
|
* (1 - neighborhood_sums / background_population)
|
258
258
|
)
|
259
259
|
std_dev[std_dev == 0] = np.nan # Avoid division by zero
|
260
|
-
# Compute
|
260
|
+
# Compute z-scores
|
261
261
|
z_scores = (observed - expected) / std_dev
|
262
262
|
|
263
|
-
# Convert
|
263
|
+
# Convert z-scores to depletion and enrichment p-values
|
264
264
|
enrichment_pvals = norm.sf(z_scores) # Upper tail
|
265
265
|
depletion_pvals = norm.cdf(z_scores) # Lower tail
|
266
266
|
|
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
|