risk-network 0.0.8b18__py3-none-any.whl → 0.0.8b20__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 +1 -1
- risk/annotations/annotations.py +4 -3
- risk/annotations/io.py +3 -3
- risk/log/params.py +5 -5
- risk/neighborhoods/community.py +68 -61
- risk/neighborhoods/domains.py +7 -3
- risk/neighborhoods/neighborhoods.py +84 -33
- risk/network/geometry.py +1 -0
- risk/network/graph.py +43 -6
- risk/network/io.py +1 -1
- risk/network/plot/canvas.py +8 -8
- risk/network/plot/contour.py +13 -7
- risk/network/plot/labels.py +47 -41
- risk/network/plot/network.py +19 -13
- risk/network/plot/plotter.py +5 -5
- risk/network/plot/utils/color.py +97 -26
- risk/network/plot/utils/layout.py +1 -1
- risk/risk.py +18 -14
- risk/stats/hypergeom.py +1 -1
- risk/stats/permutation/permutation.py +1 -1
- risk/stats/poisson.py +2 -2
- risk/stats/stats.py +4 -4
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.8b20.dist-info}/METADATA +1 -1
- risk_network-0.0.8b20.dist-info/RECORD +37 -0
- risk_network-0.0.8b18.dist-info/RECORD +0 -37
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.8b20.dist-info}/LICENSE +0 -0
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.8b20.dist-info}/WHEEL +0 -0
- {risk_network-0.0.8b18.dist-info → risk_network-0.0.8b20.dist-info}/top_level.txt +0 -0
risk/network/plot/utils/color.py
CHANGED
@@ -16,7 +16,9 @@ from risk.network.plot.utils.layout import calculate_centroids
|
|
16
16
|
def get_annotated_domain_colors(
|
17
17
|
graph: NetworkGraph,
|
18
18
|
cmap: str = "gist_rainbow",
|
19
|
-
color: Union[str,
|
19
|
+
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
20
|
+
blend_colors: bool = False,
|
21
|
+
blend_gamma: float = 2.2,
|
20
22
|
min_scale: float = 0.8,
|
21
23
|
max_scale: float = 1.0,
|
22
24
|
scale_factor: float = 1.0,
|
@@ -27,8 +29,10 @@ def get_annotated_domain_colors(
|
|
27
29
|
Args:
|
28
30
|
graph (NetworkGraph): The network data and attributes to be visualized.
|
29
31
|
cmap (str, optional): Colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
30
|
-
color (str,
|
32
|
+
color (str, List, Tuple, np.ndarray, or None, optional): Color to use for the domains. Can be a single color or an array of colors.
|
31
33
|
If None, the colormap will be used. Defaults to None.
|
34
|
+
blend_colors (bool, optional): Whether to blend colors for nodes with multiple domains. Defaults to False.
|
35
|
+
blend_gamma (float, optional): Gamma correction factor for perceptual color blending. Defaults to 2.2.
|
32
36
|
min_scale (float, optional): Minimum scale for color intensity when generating domain colors. Defaults to 0.8.
|
33
37
|
max_scale (float, optional): Maximum scale for color intensity when generating domain colors. Defaults to 1.0.
|
34
38
|
scale_factor (float, optional): Factor for adjusting the contrast in the colors generated based on enrichment. Higher values
|
@@ -43,6 +47,8 @@ def get_annotated_domain_colors(
|
|
43
47
|
graph=graph,
|
44
48
|
cmap=cmap,
|
45
49
|
color=color,
|
50
|
+
blend_colors=blend_colors,
|
51
|
+
blend_gamma=blend_gamma,
|
46
52
|
min_scale=min_scale,
|
47
53
|
max_scale=max_scale,
|
48
54
|
scale_factor=scale_factor,
|
@@ -68,7 +74,9 @@ def get_annotated_domain_colors(
|
|
68
74
|
def get_domain_colors(
|
69
75
|
graph: NetworkGraph,
|
70
76
|
cmap: str = "gist_rainbow",
|
71
|
-
color: Union[str,
|
77
|
+
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
78
|
+
blend_colors: bool = False,
|
79
|
+
blend_gamma: float = 2.2,
|
72
80
|
min_scale: float = 0.8,
|
73
81
|
max_scale: float = 1.0,
|
74
82
|
scale_factor: float = 1.0,
|
@@ -79,8 +87,10 @@ def get_domain_colors(
|
|
79
87
|
Args:
|
80
88
|
graph (NetworkGraph): The network data and attributes to be visualized.
|
81
89
|
cmap (str, optional): Name of the colormap to use for generating domain colors. Defaults to "gist_rainbow".
|
82
|
-
color (str,
|
90
|
+
color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use for all domains.
|
83
91
|
If None, the colormap will be used. Defaults to None.
|
92
|
+
blend_colors (bool, optional): Whether to blend colors for nodes with multiple domains. Defaults to False.
|
93
|
+
blend_gamma (float, optional): Gamma correction factor for perceptual color blending. Defaults to 2.2.
|
84
94
|
min_scale (float, optional): Minimum intensity scale for the colors generated by the colormap. Controls the dimmest colors.
|
85
95
|
Defaults to 0.8.
|
86
96
|
max_scale (float, optional): Maximum intensity scale for the colors generated by the colormap. Controls the brightest colors.
|
@@ -95,7 +105,9 @@ def get_domain_colors(
|
|
95
105
|
# Get colors for each domain
|
96
106
|
domain_colors = _get_domain_colors(graph=graph, cmap=cmap, color=color, random_seed=random_seed)
|
97
107
|
# Generate composite colors for nodes
|
98
|
-
node_colors = _get_composite_node_colors(
|
108
|
+
node_colors = _get_composite_node_colors(
|
109
|
+
graph=graph, domain_colors=domain_colors, blend_colors=blend_colors, blend_gamma=blend_gamma
|
110
|
+
)
|
99
111
|
# Transform colors to ensure proper alpha values and intensity
|
100
112
|
transformed_colors = _transform_colors(
|
101
113
|
node_colors,
|
@@ -110,20 +122,20 @@ def get_domain_colors(
|
|
110
122
|
def _get_domain_colors(
|
111
123
|
graph: NetworkGraph,
|
112
124
|
cmap: str = "gist_rainbow",
|
113
|
-
color: Union[str,
|
125
|
+
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
114
126
|
random_seed: int = 888,
|
115
|
-
) -> Dict[
|
127
|
+
) -> Dict[int, Any]:
|
116
128
|
"""Get colors for each domain.
|
117
129
|
|
118
130
|
Args:
|
119
131
|
graph (NetworkGraph): The network data and attributes to be visualized.
|
120
132
|
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
121
|
-
color (str,
|
133
|
+
color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use for the domains.
|
122
134
|
If None, the colormap will be used. Defaults to None.
|
123
135
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
124
136
|
|
125
137
|
Returns:
|
126
|
-
|
138
|
+
Dict[int, Any]: A dictionary mapping domain keys to their corresponding RGBA colors.
|
127
139
|
"""
|
128
140
|
# Get colors for each domain based on node positions
|
129
141
|
domain_colors = _get_colors(
|
@@ -136,12 +148,17 @@ def _get_domain_colors(
|
|
136
148
|
return dict(zip(graph.domain_id_to_node_ids_map.keys(), domain_colors))
|
137
149
|
|
138
150
|
|
139
|
-
def _get_composite_node_colors(
|
140
|
-
|
151
|
+
def _get_composite_node_colors(
|
152
|
+
graph, domain_colors: np.ndarray, blend_colors: bool = False, blend_gamma: float = 2.2
|
153
|
+
) -> np.ndarray:
|
154
|
+
"""Generate composite colors for nodes based on domain colors and enrichment values, with optional color blending.
|
141
155
|
|
142
156
|
Args:
|
143
157
|
graph (NetworkGraph): The network data and attributes to be visualized.
|
144
|
-
domain_colors (np.ndarray): Array of colors corresponding to each domain.
|
158
|
+
domain_colors (np.ndarray): Array or list of RGBA colors corresponding to each domain.
|
159
|
+
blend_colors (bool): Whether to blend colors for nodes with multiple domains. Defaults to False.
|
160
|
+
blend_gamma (float, optional): Gamma correction factor to be used for perceptual color blending.
|
161
|
+
This parameter is only relevant if blend_colors is True. Defaults to 2.2.
|
145
162
|
|
146
163
|
Returns:
|
147
164
|
np.ndarray: Array of composite colors for each node.
|
@@ -150,11 +167,38 @@ def _get_composite_node_colors(graph: NetworkGraph, domain_colors: np.ndarray) -
|
|
150
167
|
num_nodes = len(graph.node_coordinates)
|
151
168
|
# Initialize composite colors array with shape (number of nodes, 4) for RGBA
|
152
169
|
composite_colors = np.zeros((num_nodes, 4))
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
for
|
157
|
-
|
170
|
+
|
171
|
+
# If blending is not required, directly assign domain colors to nodes
|
172
|
+
if not blend_colors:
|
173
|
+
for domain_id, nodes in graph.domain_id_to_node_ids_map.items():
|
174
|
+
color = domain_colors[domain_id]
|
175
|
+
for node in nodes:
|
176
|
+
composite_colors[node] = color
|
177
|
+
|
178
|
+
# If blending is required
|
179
|
+
else:
|
180
|
+
for node, node_info in graph.node_id_to_domain_ids_and_enrichments_map.items():
|
181
|
+
domains = node_info["domains"] # List of domain IDs
|
182
|
+
enrichments = node_info["enrichments"] # List of enrichment values
|
183
|
+
# Filter domains and enrichments to keep only those with corresponding colors in domain_colors
|
184
|
+
filtered_domains_enrichments = [
|
185
|
+
(domain_id, enrichment)
|
186
|
+
for domain_id, enrichment in zip(domains, enrichments)
|
187
|
+
if domain_id in domain_colors
|
188
|
+
]
|
189
|
+
# If no valid domains exist, skip this node
|
190
|
+
if not filtered_domains_enrichments:
|
191
|
+
continue
|
192
|
+
|
193
|
+
# Unpack filtered domains and enrichments
|
194
|
+
filtered_domains, filtered_enrichments = zip(*filtered_domains_enrichments)
|
195
|
+
# Get the colors corresponding to the valid filtered domains
|
196
|
+
colors = [domain_colors[domain_id] for domain_id in filtered_domains]
|
197
|
+
# Blend the colors using the given gamma (default is 2.2 if None)
|
198
|
+
gamma = blend_gamma if blend_gamma is not None else 2.2
|
199
|
+
composite_color = _blend_colors_perceptually(colors, filtered_enrichments, gamma)
|
200
|
+
# Assign the composite color to the node
|
201
|
+
composite_colors[node] = composite_color
|
158
202
|
|
159
203
|
return composite_colors
|
160
204
|
|
@@ -163,7 +207,7 @@ def _get_colors(
|
|
163
207
|
network,
|
164
208
|
domain_id_to_node_ids_map,
|
165
209
|
cmap: str = "gist_rainbow",
|
166
|
-
color: Union[str,
|
210
|
+
color: Union[str, List, Tuple, np.ndarray, None] = None,
|
167
211
|
random_seed: int = 888,
|
168
212
|
) -> List[Tuple]:
|
169
213
|
"""Generate a list of RGBA colors based on domain centroids, ensuring that domains
|
@@ -171,9 +215,9 @@ def _get_colors(
|
|
171
215
|
|
172
216
|
Args:
|
173
217
|
network (NetworkX graph): The graph representing the network.
|
174
|
-
domain_id_to_node_ids_map (
|
218
|
+
domain_id_to_node_ids_map (Dict[int, Any]): Mapping from domain IDs to lists of node IDs.
|
175
219
|
cmap (str, optional): The name of the colormap to use. Defaults to "gist_rainbow".
|
176
|
-
color (str,
|
220
|
+
color (str, List, Tuple, np.ndarray, or None, optional): A specific color or array of colors to use for the domains.
|
177
221
|
If None, the colormap will be used. Defaults to None.
|
178
222
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
179
223
|
|
@@ -237,6 +281,33 @@ def _assign_distant_colors(dist_matrix, num_colors_to_generate):
|
|
237
281
|
return color_positions
|
238
282
|
|
239
283
|
|
284
|
+
def _blend_colors_perceptually(
|
285
|
+
colors: Union[List, Tuple, np.ndarray], enrichments: List[float], gamma: float = 2.2
|
286
|
+
) -> Tuple[float, float, float, float]:
|
287
|
+
"""Blends a list of RGBA colors using gamma correction for perceptually uniform color mixing.
|
288
|
+
|
289
|
+
Args:
|
290
|
+
colors (List, Tuple, np.ndarray): List of RGBA colors. Can be a list, tuple, or NumPy array of RGBA values.
|
291
|
+
enrichments (List[float]): Corresponding list of enrichment values.
|
292
|
+
gamma (float, optional): Gamma correction factor, default is 2.2 (typical for perceptual blending).
|
293
|
+
|
294
|
+
Returns:
|
295
|
+
Tuple[float, float, float, float]: The blended RGBA color.
|
296
|
+
"""
|
297
|
+
# Normalize enrichments so they sum up to 1 (proportions)
|
298
|
+
total_enrichment = sum(enrichments)
|
299
|
+
proportions = [enrichment / total_enrichment for enrichment in enrichments]
|
300
|
+
# Convert colors to gamma-corrected space (apply gamma correction to RGB channels)
|
301
|
+
gamma_corrected_colors = [[channel**gamma for channel in color[:3]] for color in colors]
|
302
|
+
# Blend the colors in gamma-corrected space
|
303
|
+
blended_color = np.dot(proportions, gamma_corrected_colors)
|
304
|
+
# Convert back from gamma-corrected space to linear space (by applying inverse gamma correction)
|
305
|
+
blended_color = [channel ** (1 / gamma) for channel in blended_color]
|
306
|
+
# Average the alpha channel separately (no gamma correction on alpha)
|
307
|
+
alpha = np.dot(proportions, [color[3] for color in colors])
|
308
|
+
return tuple(blended_color + [alpha])
|
309
|
+
|
310
|
+
|
240
311
|
def _transform_colors(
|
241
312
|
colors: np.ndarray,
|
242
313
|
enrichment_sums: np.ndarray,
|
@@ -283,14 +354,14 @@ def _transform_colors(
|
|
283
354
|
|
284
355
|
|
285
356
|
def to_rgba(
|
286
|
-
color: Union[str,
|
357
|
+
color: Union[str, List, Tuple, np.ndarray],
|
287
358
|
alpha: Union[float, None] = None,
|
288
359
|
num_repeats: Union[int, None] = None,
|
289
360
|
) -> np.ndarray:
|
290
361
|
"""Convert color(s) to RGBA format, applying alpha and repeating as needed.
|
291
362
|
|
292
363
|
Args:
|
293
|
-
color (str,
|
364
|
+
color (str, List, Tuple, np.ndarray): The color(s) to convert. Can be a string (e.g., 'red'), a list or tuple of RGB/RGBA values,
|
294
365
|
or an `np.ndarray` of colors.
|
295
366
|
alpha (float, None, optional): Alpha value (transparency) to apply. If provided, it overrides any existing alpha values found
|
296
367
|
in color.
|
@@ -306,7 +377,7 @@ def to_rgba(
|
|
306
377
|
if isinstance(c, str):
|
307
378
|
# Convert color names or hex values (e.g., 'red', '#FF5733') to RGBA
|
308
379
|
rgba = np.array(mcolors.to_rgba(c))
|
309
|
-
elif isinstance(c, (
|
380
|
+
elif isinstance(c, (List, Tuple, np.ndarray)) and len(c) in [3, 4]:
|
310
381
|
# Convert RGB (3) or RGBA (4) values to RGBA format
|
311
382
|
rgba = np.array(mcolors.to_rgba(c))
|
312
383
|
else:
|
@@ -325,8 +396,8 @@ def to_rgba(
|
|
325
396
|
# Handle a single color (string or RGB/RGBA list/tuple)
|
326
397
|
if (
|
327
398
|
isinstance(color, str)
|
328
|
-
or isinstance(color, (
|
329
|
-
and not any(isinstance(c, (str,
|
399
|
+
or isinstance(color, (List, Tuple, np.ndarray))
|
400
|
+
and not any(isinstance(c, (str, List, Tuple, np.ndarray)) for c in color)
|
330
401
|
):
|
331
402
|
rgba_color = convert_to_rgba(color)
|
332
403
|
if num_repeats:
|
@@ -336,7 +407,7 @@ def to_rgba(
|
|
336
407
|
return np.array([rgba_color]) # Return a single color wrapped in a numpy array
|
337
408
|
|
338
409
|
# Handle a list/array of colors
|
339
|
-
elif isinstance(color, (
|
410
|
+
elif isinstance(color, (List, Tuple, np.ndarray)):
|
340
411
|
rgba_colors = np.array(
|
341
412
|
[convert_to_rgba(c) for c in color]
|
342
413
|
) # Convert each color in the list to RGBA
|
@@ -35,7 +35,7 @@ def calculate_centroids(network, domain_id_to_node_ids_map):
|
|
35
35
|
|
36
36
|
Args:
|
37
37
|
network (NetworkX graph): The graph representing the network.
|
38
|
-
domain_id_to_node_ids_map (
|
38
|
+
domain_id_to_node_ids_map (Dict[int, Any]): Mapping from domain IDs to lists of node IDs.
|
39
39
|
|
40
40
|
Returns:
|
41
41
|
List[Tuple[float, float]]: List of centroids (x, y) for each domain.
|
risk/risk.py
CHANGED
@@ -68,7 +68,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
68
68
|
|
69
69
|
Args:
|
70
70
|
network (nx.Graph): The network graph.
|
71
|
-
annotations (
|
71
|
+
annotations (Dict[str, Any]): The annotations associated with the network.
|
72
72
|
distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "louvain".
|
73
73
|
louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
|
74
74
|
edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
|
@@ -76,7 +76,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
76
76
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
77
77
|
|
78
78
|
Returns:
|
79
|
-
|
79
|
+
Dict[str, Any]: Computed significance of neighborhoods.
|
80
80
|
"""
|
81
81
|
log_header("Running hypergeometric test")
|
82
82
|
# Log neighborhood analysis parameters
|
@@ -121,7 +121,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
121
121
|
|
122
122
|
Args:
|
123
123
|
network (nx.Graph): The network graph.
|
124
|
-
annotations (
|
124
|
+
annotations (Dict[str, Any]): The annotations associated with the network.
|
125
125
|
distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "louvain".
|
126
126
|
louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
|
127
127
|
edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
|
@@ -129,7 +129,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
129
129
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
130
130
|
|
131
131
|
Returns:
|
132
|
-
|
132
|
+
Dict[str, Any]: Computed significance of neighborhoods.
|
133
133
|
"""
|
134
134
|
log_header("Running Poisson test")
|
135
135
|
# Log neighborhood analysis parameters
|
@@ -177,7 +177,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
177
177
|
|
178
178
|
Args:
|
179
179
|
network (nx.Graph): The network graph.
|
180
|
-
annotations (
|
180
|
+
annotations (Dict[str, Any]): The annotations associated with the network.
|
181
181
|
distance_metric (str, optional): Distance metric for neighborhood analysis. Defaults to "louvain".
|
182
182
|
louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
|
183
183
|
edge_length_threshold (float, optional): Edge length threshold for neighborhood analysis. Defaults to 0.5.
|
@@ -188,7 +188,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
188
188
|
max_workers (int, optional): Maximum number of workers for parallel computation. Defaults to 1.
|
189
189
|
|
190
190
|
Returns:
|
191
|
-
|
191
|
+
Dict[str, Any]: Computed significance of neighborhoods.
|
192
192
|
"""
|
193
193
|
log_header("Running permutation test")
|
194
194
|
# Log neighborhood analysis parameters
|
@@ -253,7 +253,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
253
253
|
Args:
|
254
254
|
network (nx.Graph): The network graph.
|
255
255
|
annotations (pd.DataFrame): DataFrame containing annotation data for the network.
|
256
|
-
neighborhoods (
|
256
|
+
neighborhoods (Dict[str, Any]): Neighborhood enrichment data.
|
257
257
|
tail (str, optional): Type of significance tail ("right", "left", "both"). Defaults to "right".
|
258
258
|
pval_cutoff (float, optional): p-value cutoff for significance. Defaults to 0.01.
|
259
259
|
fdr_cutoff (float, optional): FDR cutoff for significance. Defaults to 0.9999.
|
@@ -362,7 +362,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
362
362
|
|
363
363
|
Args:
|
364
364
|
graph (NetworkGraph): The graph to plot.
|
365
|
-
figsize (
|
365
|
+
figsize (Tuple, optional): Size of the figure. Defaults to (10, 10).
|
366
366
|
background_color (str, optional): Background color of the plot. Defaults to "white".
|
367
367
|
background_alpha (float, None, optional): Transparency level of the background color. If provided, it overrides
|
368
368
|
any existing alpha values found in background_color. Defaults to 1.0.
|
@@ -395,9 +395,13 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
395
395
|
Args:
|
396
396
|
network (nx.Graph): The network graph.
|
397
397
|
annotations (pd.DataFrame): The matrix of annotations associated with the network.
|
398
|
-
distance_metric (str, optional):
|
398
|
+
distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
|
399
|
+
metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'label_propagation',
|
400
|
+
'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
|
399
401
|
louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
|
400
|
-
edge_length_threshold (float, optional): Edge length threshold for
|
402
|
+
edge_length_threshold (float, List, Tuple, or np.ndarray, optional): Edge length threshold(s) for creating subgraphs.
|
403
|
+
Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
|
404
|
+
Defaults to 0.5.
|
401
405
|
random_seed (int, optional): Seed for random number generation. Defaults to 888.
|
402
406
|
|
403
407
|
Returns:
|
@@ -437,13 +441,13 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
437
441
|
|
438
442
|
Args:
|
439
443
|
network (nx.Graph): The network graph.
|
440
|
-
annotations (
|
441
|
-
neighborhoods (
|
444
|
+
annotations (Dict[str, Any]): Annotations data for the network.
|
445
|
+
neighborhoods (Dict[str, Any]): Neighborhood enrichment data.
|
442
446
|
min_cluster_size (int, optional): Minimum size for clusters. Defaults to 5.
|
443
447
|
max_cluster_size (int, optional): Maximum size for clusters. Defaults to 1000.
|
444
448
|
|
445
449
|
Returns:
|
446
|
-
|
450
|
+
Dict[str, Any]: Top annotations identified within the network.
|
447
451
|
"""
|
448
452
|
# Extract necessary data from annotations and neighborhoods
|
449
453
|
ordered_annotations = annotations["ordered_annotations"]
|
@@ -470,7 +474,7 @@ class RISK(NetworkIO, AnnotationsIO):
|
|
470
474
|
"""Define domains in the network based on enrichment data.
|
471
475
|
|
472
476
|
Args:
|
473
|
-
neighborhoods (
|
477
|
+
neighborhoods (Dict[str, Any]): Enrichment data for neighborhoods.
|
474
478
|
top_annotations (pd.DataFrame): Enrichment matrix for top annotations.
|
475
479
|
linkage_criterion (str): Clustering criterion for defining domains.
|
476
480
|
linkage_method (str): Clustering method to use.
|
risk/stats/hypergeom.py
CHANGED
@@ -20,7 +20,7 @@ def compute_hypergeom_test(
|
|
20
20
|
null_distribution (str, optional): Type of null distribution ('network' or 'annotations'). Defaults to "network".
|
21
21
|
|
22
22
|
Returns:
|
23
|
-
|
23
|
+
Dict[str, Any]: Dictionary containing depletion and enrichment p-values.
|
24
24
|
"""
|
25
25
|
# Get the total number of nodes in the network
|
26
26
|
total_node_count = neighborhoods.shape[0]
|
@@ -35,7 +35,7 @@ def compute_permutation_test(
|
|
35
35
|
max_workers (int, optional): Number of workers for multiprocessing. Defaults to 1.
|
36
36
|
|
37
37
|
Returns:
|
38
|
-
|
38
|
+
Dict[str, Any]: Dictionary containing depletion and enrichment p-values.
|
39
39
|
"""
|
40
40
|
# Ensure that the matrices are in the correct format and free of NaN values
|
41
41
|
neighborhoods = neighborhoods.astype(np.float32)
|
risk/stats/poisson.py
CHANGED
@@ -3,7 +3,7 @@ risk/stats/poisson
|
|
3
3
|
~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
|
-
from typing import
|
6
|
+
from typing import Any, Dict
|
7
7
|
|
8
8
|
import numpy as np
|
9
9
|
from scipy.stats import poisson
|
@@ -20,7 +20,7 @@ def compute_poisson_test(
|
|
20
20
|
null_distribution (str, optional): Type of null distribution ('network' or 'annotations'). Defaults to "network".
|
21
21
|
|
22
22
|
Returns:
|
23
|
-
|
23
|
+
Dict[str, Any]: Dictionary containing depletion and enrichment p-values.
|
24
24
|
"""
|
25
25
|
# Matrix multiplication to get the number of annotated nodes in each neighborhood
|
26
26
|
annotated_in_neighborhood = neighborhoods @ annotations
|
risk/stats/stats.py
CHANGED
@@ -3,7 +3,7 @@ risk/stats/stats
|
|
3
3
|
~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
|
-
from typing import Union
|
6
|
+
from typing import Any, Dict, Union
|
7
7
|
|
8
8
|
import numpy as np
|
9
9
|
from statsmodels.stats.multitest import fdrcorrection
|
@@ -15,7 +15,7 @@ def calculate_significance_matrices(
|
|
15
15
|
tail: str = "right",
|
16
16
|
pval_cutoff: float = 0.05,
|
17
17
|
fdr_cutoff: float = 0.05,
|
18
|
-
) ->
|
18
|
+
) -> Dict[str, Any]:
|
19
19
|
"""Calculate significance matrices based on p-values and specified tail.
|
20
20
|
|
21
21
|
Args:
|
@@ -26,8 +26,8 @@ def calculate_significance_matrices(
|
|
26
26
|
fdr_cutoff (float, optional): Cutoff for FDR significance if applied. Defaults to 0.05.
|
27
27
|
|
28
28
|
Returns:
|
29
|
-
|
30
|
-
|
29
|
+
Dict[str, Any]: Dictionary containing the enrichment matrix, binary significance matrix,
|
30
|
+
and the matrix of significant enrichment values.
|
31
31
|
"""
|
32
32
|
if fdr_cutoff < 1.0:
|
33
33
|
# Apply FDR correction to depletion p-values
|
@@ -0,0 +1,37 @@
|
|
1
|
+
risk/__init__.py,sha256=MOWrmv2B-I1GTr0sgWTb-CLgeMWceWa6q2E6oeGC2CA,113
|
2
|
+
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
|
+
risk/risk.py,sha256=_ufeTLOAAT4QwrRysvDJOQeE0qMvpp3BSSayfFLhGJE,21720
|
4
|
+
risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
|
5
|
+
risk/annotations/annotations.py,sha256=KHGeF5vBDmX711nA08DfhxI9z7Z1Oaeo91ueWhM6vs8,11370
|
6
|
+
risk/annotations/io.py,sha256=powWzeimVdE0WCwlBCXyu5otMyZZHQujC0DS3m5DC0c,9505
|
7
|
+
risk/log/__init__.py,sha256=aDUz5LMFQsz0UlsQI2EdXtiBKRLfml1UMeZKC7QQIGU,134
|
8
|
+
risk/log/config.py,sha256=m8pzj-hN4vI_2JdJUfyOoSvzT8_lhoIfBt27sKbnOes,4535
|
9
|
+
risk/log/params.py,sha256=rvyg86RnkHwotST7x42RgsiYfq2HB-9BZxp6KkT_04o,6415
|
10
|
+
risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
|
11
|
+
risk/neighborhoods/community.py,sha256=MAgIblbuisEPwVU6mFZd4Yd9NUKlaHK99suw51r1Is0,7065
|
12
|
+
risk/neighborhoods/domains.py,sha256=DbhUFsvbr8wuvrNr7a0PaAJO-cdv6U3-T4CXB4-j5Qw,10930
|
13
|
+
risk/neighborhoods/neighborhoods.py,sha256=OPGNfeGQR533vWjger7f34ZPSgw9250LQXcTEIAhQvg,21165
|
14
|
+
risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
|
15
|
+
risk/network/geometry.py,sha256=Y3Brp0XYWoBL2VHJX7I-gW5x-q7lGiEMqr2kqtutgkQ,6811
|
16
|
+
risk/network/graph.py,sha256=-91JL84LYbdWohzybKFQ3NdWnervxP-wwbpaUOdRVLE,8576
|
17
|
+
risk/network/io.py,sha256=w_9fUcZUVXAPRKGhLBc7xhIJs8l83szHiBQTdaNN0gk,22942
|
18
|
+
risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
|
19
|
+
risk/network/plot/canvas.py,sha256=hdrmGd2TCuii8wn6jDQfyJTI5YXDNGYFLiU4TyqAYbE,10778
|
20
|
+
risk/network/plot/contour.py,sha256=xxTf6iNSlpe2S8aalt2mzivmR0wuGUOh_F3-IL6UbEU,15027
|
21
|
+
risk/network/plot/labels.py,sha256=bFsP9NA3Fp0GhX62ArRP9tSqPCgUthKE9aFe0imoPcI,45115
|
22
|
+
risk/network/plot/network.py,sha256=nfTmQxx1YwS3taXwq8WSCfu6nfKFOyxj7T5605qLXVM,13615
|
23
|
+
risk/network/plot/plotter.py,sha256=iTPMiTnTTatM_-q1Ox_bjt5Pvv-Lo8gceiYB6TVzDcw,5770
|
24
|
+
risk/network/plot/utils/color.py,sha256=HtUaGnqJPVNbRyUhQMlBonfHc_2Ci8BtTI3y424p8Cs,19626
|
25
|
+
risk/network/plot/utils/layout.py,sha256=5DpRLvabgnPWwVJ-J3W6oFBBvbjCrudvvW4HDOzzoTo,1960
|
26
|
+
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
27
|
+
risk/stats/hypergeom.py,sha256=oc39f02ViB1vQ-uaDrxG_tzAT6dxQBRjc88EK2EGn78,2282
|
28
|
+
risk/stats/poisson.py,sha256=polLgwS08MTCNzupYdmMUoEUYrJOjAbcYtYwjlfeE5Y,1803
|
29
|
+
risk/stats/stats.py,sha256=07yMULKlCurK62x674SHKJavZtz9ge2K2ZsHix_z_pw,7088
|
30
|
+
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
31
|
+
risk/stats/permutation/permutation.py,sha256=meBNSrbRa9P8WJ54n485l0H7VQJlMSfHqdN4aCKYCtQ,10105
|
32
|
+
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
33
|
+
risk_network-0.0.8b20.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
34
|
+
risk_network-0.0.8b20.dist-info/METADATA,sha256=UnAgNaBf77W4-Vo5YGPJktwy5WQaEwWU2ByhSbyfEVg,47498
|
35
|
+
risk_network-0.0.8b20.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
36
|
+
risk_network-0.0.8b20.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
37
|
+
risk_network-0.0.8b20.dist-info/RECORD,,
|
@@ -1,37 +0,0 @@
|
|
1
|
-
risk/__init__.py,sha256=EoQiOdiY9moo1L8d1ybzWAGTSGsM9MzK9H_PfU8miI4,113
|
2
|
-
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
|
-
risk/risk.py,sha256=slJXca_a726_D7oXwe765HaKTv3ZrOvhttyrWdCGPkA,21231
|
4
|
-
risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
|
5
|
-
risk/annotations/annotations.py,sha256=7ilzXxrlHqN75J3q8WeHz0n79D-jAtUQx5czvC9wfIM,11303
|
6
|
-
risk/annotations/io.py,sha256=TTXVJQgUGAlKpnGBcx7Dow146IGyozA03nSbl3S7M5M,9475
|
7
|
-
risk/log/__init__.py,sha256=aDUz5LMFQsz0UlsQI2EdXtiBKRLfml1UMeZKC7QQIGU,134
|
8
|
-
risk/log/config.py,sha256=m8pzj-hN4vI_2JdJUfyOoSvzT8_lhoIfBt27sKbnOes,4535
|
9
|
-
risk/log/params.py,sha256=DUmsqPo9hi3rQHFgLTunP14I-vVoyQSFZbx5aSYmVts,6363
|
10
|
-
risk/neighborhoods/__init__.py,sha256=tKKEg4lsbqFukpgYlUGxU_v_9FOqK7V0uvM9T2QzoL0,206
|
11
|
-
risk/neighborhoods/community.py,sha256=stYYBXeZlGLMV-k8ckQeIqThT6v9y-S3hETobAo9590,6817
|
12
|
-
risk/neighborhoods/domains.py,sha256=D5MUIghbwyKKCAE8PN_HXvsO9NxLTGejQmyEqetD1Bk,10743
|
13
|
-
risk/neighborhoods/neighborhoods.py,sha256=M-wL4xB_BUTlSZg90swygO5NdrZ6hFUFqs6jsiZaqHk,18260
|
14
|
-
risk/network/__init__.py,sha256=iEPeJdZfqp0toxtbElryB8jbz9_t_k4QQ3iDvKE8C_0,126
|
15
|
-
risk/network/geometry.py,sha256=H1yGVVqgbfpzBzJwEheDLfvGLSA284jGQQTn612L4Vc,6759
|
16
|
-
risk/network/graph.py,sha256=x5cur1meitkR0YuE5vGxX0s_IFa5wkx8z44f_C1vK7U,6509
|
17
|
-
risk/network/io.py,sha256=u0PPcKjp6Xze--7eDOlvalYkjQ9S2sjiC-ac2476PUI,22942
|
18
|
-
risk/network/plot/__init__.py,sha256=MfmaXJgAZJgXZ2wrhK8pXwzETlcMaLChhWXKAozniAo,98
|
19
|
-
risk/network/plot/canvas.py,sha256=JnjPQaryRb_J6LP36BT2-rlsbJO3T4tTBornL8Oqqbs,10778
|
20
|
-
risk/network/plot/contour.py,sha256=8uwJ7K-Z6VMyr_uQ5VUyoQSqDHA7zDvR_nYAmLn60-I,14647
|
21
|
-
risk/network/plot/labels.py,sha256=ttEUiKkDq024v4MI-ZADW3sT7uRNQ6aL3kNB598Em90,44468
|
22
|
-
risk/network/plot/network.py,sha256=9blVFeCp5x5XoGhPwOOdADegXC4gC72c2vrM2u4QPe0,13235
|
23
|
-
risk/network/plot/plotter.py,sha256=lN-_GDXRk9V3IFu8q7QmPjJGBZiP0QYwSvU6dVVDV2E,5770
|
24
|
-
risk/network/plot/utils/color.py,sha256=_ZLIw_uv--nTXhUhZVaF0iCaYmfURTn_WnoFYdUcPrc,15575
|
25
|
-
risk/network/plot/utils/layout.py,sha256=znssSqe2VZzzSz47hLZtTuXwMTpHR9b8lkQPL0BX7OA,1950
|
26
|
-
risk/stats/__init__.py,sha256=WcgoETQ-hS0LQqKRsAMIPtP15xZ-4eul6VUBuUx4Wzc,220
|
27
|
-
risk/stats/hypergeom.py,sha256=o6Qnj31gCAKxr2uQirXrbv7XvdDJGEq69MFW-ubx_hA,2272
|
28
|
-
risk/stats/poisson.py,sha256=8x9hB4DCukq4gNIlIKO-c_jYG1-BTwTX53oLauFyfj8,1793
|
29
|
-
risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
|
30
|
-
risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
|
31
|
-
risk/stats/permutation/permutation.py,sha256=D84Rcpt6iTQniK0PfQGcw9bLcHbMt9p-ARcurUnIXZQ,10095
|
32
|
-
risk/stats/permutation/test_functions.py,sha256=lftOude6hee0pyR80HlBD32522JkDoN5hrKQ9VEbuoY,2345
|
33
|
-
risk_network-0.0.8b18.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
34
|
-
risk_network-0.0.8b18.dist-info/METADATA,sha256=CYJnBG0E8gmlzPx15UYKAjbbsC3zs2Mmsq42NPzi1mY,47498
|
35
|
-
risk_network-0.0.8b18.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
36
|
-
risk_network-0.0.8b18.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
37
|
-
risk_network-0.0.8b18.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|