risk-network 0.0.16b1__py3-none-any.whl → 0.0.16b2__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.
Files changed (53) hide show
  1. risk/__init__.py +2 -2
  2. risk/{_annotation → annotation}/__init__.py +2 -2
  3. risk/{_annotation → annotation}/_nltk_setup.py +3 -3
  4. risk/{_annotation/_annotation.py → annotation/annotation.py} +13 -13
  5. risk/{_annotation/_io.py → annotation/io.py} +4 -4
  6. risk/cluster/__init__.py +8 -0
  7. risk/{_neighborhoods → cluster}/_community.py +37 -37
  8. risk/cluster/api.py +273 -0
  9. risk/{_neighborhoods/_neighborhoods.py → cluster/cluster.py} +127 -98
  10. risk/{_neighborhoods/_domains.py → cluster/label.py} +18 -12
  11. risk/{_log → log}/__init__.py +2 -2
  12. risk/{_log/_console.py → log/console.py} +2 -2
  13. risk/{_log/_parameters.py → log/parameters.py} +20 -10
  14. risk/network/__init__.py +8 -0
  15. risk/network/graph/__init__.py +7 -0
  16. risk/{_network/_graph → network/graph}/_stats.py +2 -2
  17. risk/{_network/_graph → network/graph}/_summary.py +13 -13
  18. risk/{_network/_graph/_api.py → network/graph/api.py} +37 -39
  19. risk/{_network/_graph/_graph.py → network/graph/graph.py} +5 -5
  20. risk/{_network/_io.py → network/io.py} +9 -4
  21. risk/network/plotter/__init__.py +6 -0
  22. risk/{_network/_plotter → network/plotter}/_canvas.py +6 -6
  23. risk/{_network/_plotter → network/plotter}/_contour.py +4 -4
  24. risk/{_network/_plotter → network/plotter}/_labels.py +6 -6
  25. risk/{_network/_plotter → network/plotter}/_network.py +7 -7
  26. risk/{_network/_plotter → network/plotter}/_plotter.py +5 -5
  27. risk/network/plotter/_utils/__init__.py +7 -0
  28. risk/{_network/_plotter/_utils/_colors.py → network/plotter/_utils/colors.py} +3 -3
  29. risk/{_network/_plotter/_utils/_layout.py → network/plotter/_utils/layout.py} +2 -2
  30. risk/{_network/_plotter/_api.py → network/plotter/api.py} +5 -5
  31. risk/{_risk.py → risk.py} +9 -8
  32. risk/stats/__init__.py +6 -0
  33. risk/stats/_stats/__init__.py +11 -0
  34. risk/stats/_stats/permutation/__init__.py +6 -0
  35. risk/stats/_stats/permutation/_test_functions.py +72 -0
  36. risk/{_neighborhoods/_stats/_permutation/_permutation.py → stats/_stats/permutation/permutation.py} +35 -37
  37. risk/{_neighborhoods/_stats/_tests.py → stats/_stats/tests.py} +32 -34
  38. risk/stats/api.py +202 -0
  39. {risk_network-0.0.16b1.dist-info → risk_network-0.0.16b2.dist-info}/METADATA +2 -2
  40. risk_network-0.0.16b2.dist-info/RECORD +43 -0
  41. risk/_neighborhoods/__init__.py +0 -8
  42. risk/_neighborhoods/_api.py +0 -354
  43. risk/_neighborhoods/_stats/__init__.py +0 -11
  44. risk/_neighborhoods/_stats/_permutation/__init__.py +0 -6
  45. risk/_neighborhoods/_stats/_permutation/_test_functions.py +0 -72
  46. risk/_network/__init__.py +0 -8
  47. risk/_network/_graph/__init__.py +0 -7
  48. risk/_network/_plotter/__init__.py +0 -6
  49. risk/_network/_plotter/_utils/__init__.py +0 -7
  50. risk_network-0.0.16b1.dist-info/RECORD +0 -41
  51. {risk_network-0.0.16b1.dist-info → risk_network-0.0.16b2.dist-info}/WHEEL +0 -0
  52. {risk_network-0.0.16b1.dist-info → risk_network-0.0.16b2.dist-info}/licenses/LICENSE +0 -0
  53. {risk_network-0.0.16b1.dist-info → risk_network-0.0.16b2.dist-info}/top_level.txt +0 -0
@@ -1,354 +0,0 @@
1
- """
2
- risk/_neighborhoods/_api
3
- ~~~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- import copy
7
- from typing import Any, Dict, List, Tuple, Union
8
-
9
- import networkx as nx
10
- import numpy as np
11
- from scipy.sparse import csr_matrix
12
-
13
- from .._log import log_header, logger, params
14
- from ._neighborhoods import get_network_neighborhoods
15
- from ._stats import (
16
- compute_binom_test,
17
- compute_chi2_test,
18
- compute_hypergeom_test,
19
- compute_permutation_test,
20
- )
21
-
22
-
23
- class NeighborhoodsAPI:
24
- """
25
- Handles the loading of statistical results and annotation significance for neighborhoods.
26
-
27
- The NeighborhoodsAPI class provides methods to load neighborhood results from statistical tests.
28
- """
29
-
30
- def load_neighborhoods_binom(
31
- self,
32
- network: nx.Graph,
33
- annotation: Dict[str, Any],
34
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
35
- louvain_resolution: float = 0.1,
36
- leiden_resolution: float = 1.0,
37
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
38
- null_distribution: str = "network",
39
- random_seed: int = 888,
40
- ) -> Dict[str, Any]:
41
- """
42
- Load significant neighborhoods for the network using the binomial test.
43
-
44
- Args:
45
- network (nx.Graph): The network graph.
46
- annotation (Dict[str, Any]): The annotation associated with the network.
47
- distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
48
- metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'leiden', 'label_propagation',
49
- 'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
50
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
51
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
52
- fraction_shortest_edges (float, List, Tuple, or np.ndarray, optional): Shortest edge rank fraction threshold(s) for creating subgraphs.
53
- Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
54
- Defaults to 0.5.
55
- null_distribution (str, optional): Type of null distribution ('network' or 'annotation'). Defaults to "network".
56
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
57
-
58
- Returns:
59
- Dict[str, Any]: Computed significance of neighborhoods.
60
- """
61
- log_header("Running binomial test")
62
- # Compute neighborhood significance using the binomial test
63
- return self._load_neighborhoods_by_statistical_test(
64
- network=network,
65
- annotation=annotation,
66
- distance_metric=distance_metric,
67
- louvain_resolution=louvain_resolution,
68
- leiden_resolution=leiden_resolution,
69
- fraction_shortest_edges=fraction_shortest_edges,
70
- null_distribution=null_distribution,
71
- random_seed=random_seed,
72
- statistical_test_key="binom",
73
- statistical_test_function=compute_binom_test,
74
- )
75
-
76
- def load_neighborhoods_chi2(
77
- self,
78
- network: nx.Graph,
79
- annotation: Dict[str, Any],
80
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
81
- louvain_resolution: float = 0.1,
82
- leiden_resolution: float = 1.0,
83
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
84
- null_distribution: str = "network",
85
- random_seed: int = 888,
86
- ) -> Dict[str, Any]:
87
- """
88
- Load significant neighborhoods for the network using the chi-squared test.
89
-
90
- Args:
91
- network (nx.Graph): The network graph.
92
- annotation (Dict[str, Any]): The annotation associated with the network.
93
- distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
94
- metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'leiden', 'label_propagation',
95
- 'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
96
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
97
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
98
- fraction_shortest_edges (float, List, Tuple, or np.ndarray, optional): Shortest edge rank fraction threshold(s) for creating subgraphs.
99
- Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
100
- Defaults to 0.5.
101
- null_distribution (str, optional): Type of null distribution ('network' or 'annotation'). Defaults to "network".
102
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
103
-
104
- Returns:
105
- Dict[str, Any]: Computed significance of neighborhoods.
106
- """
107
- log_header("Running chi-squared test")
108
- # Compute neighborhood significance using the chi-squared test
109
- return self._load_neighborhoods_by_statistical_test(
110
- network=network,
111
- annotation=annotation,
112
- distance_metric=distance_metric,
113
- louvain_resolution=louvain_resolution,
114
- leiden_resolution=leiden_resolution,
115
- fraction_shortest_edges=fraction_shortest_edges,
116
- null_distribution=null_distribution,
117
- random_seed=random_seed,
118
- statistical_test_key="chi2",
119
- statistical_test_function=compute_chi2_test,
120
- )
121
-
122
- def load_neighborhoods_hypergeom(
123
- self,
124
- network: nx.Graph,
125
- annotation: Dict[str, Any],
126
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
127
- louvain_resolution: float = 0.1,
128
- leiden_resolution: float = 1.0,
129
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
130
- null_distribution: str = "network",
131
- random_seed: int = 888,
132
- ) -> Dict[str, Any]:
133
- """
134
- Load significant neighborhoods for the network using the hypergeometric test.
135
-
136
- Args:
137
- network (nx.Graph): The network graph.
138
- annotation (Dict[str, Any]): The annotation associated with the network.
139
- distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
140
- metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'leiden', 'label_propagation',
141
- 'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
142
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
143
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
144
- fraction_shortest_edges (float, List, Tuple, or np.ndarray, optional): Shortest edge rank fraction threshold(s) for creating subgraphs.
145
- Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
146
- Defaults to 0.5.
147
- null_distribution (str, optional): Type of null distribution ('network' or 'annotation'). Defaults to "network".
148
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
149
-
150
- Returns:
151
- Dict[str, Any]: Computed significance of neighborhoods.
152
- """
153
- log_header("Running hypergeometric test")
154
- # Compute neighborhood significance using the hypergeometric test
155
- return self._load_neighborhoods_by_statistical_test(
156
- network=network,
157
- annotation=annotation,
158
- distance_metric=distance_metric,
159
- louvain_resolution=louvain_resolution,
160
- leiden_resolution=leiden_resolution,
161
- fraction_shortest_edges=fraction_shortest_edges,
162
- null_distribution=null_distribution,
163
- random_seed=random_seed,
164
- statistical_test_key="hypergeom",
165
- statistical_test_function=compute_hypergeom_test,
166
- )
167
-
168
- def load_neighborhoods_permutation(
169
- self,
170
- network: nx.Graph,
171
- annotation: Dict[str, Any],
172
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
173
- louvain_resolution: float = 0.1,
174
- leiden_resolution: float = 1.0,
175
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
176
- score_metric: str = "sum",
177
- null_distribution: str = "network",
178
- num_permutations: int = 1000,
179
- random_seed: int = 888,
180
- max_workers: int = 1,
181
- ) -> Dict[str, Any]:
182
- """
183
- Load significant neighborhoods for the network using the permutation test.
184
-
185
- Args:
186
- network (nx.Graph): The network graph.
187
- annotation (Dict[str, Any]): The annotation associated with the network.
188
- distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
189
- metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'leiden', 'label_propagation',
190
- 'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
191
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
192
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
193
- fraction_shortest_edges (float, List, Tuple, or np.ndarray, optional): Shortest edge rank fraction threshold(s) for creating subgraphs.
194
- Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
195
- Defaults to 0.5.
196
- score_metric (str, optional): Scoring metric for neighborhood significance. Defaults to "sum".
197
- null_distribution (str, optional): Type of null distribution ('network' or 'annotation'). Defaults to "network".
198
- num_permutations (int, optional): Number of permutations for significance testing. Defaults to 1000.
199
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
200
- max_workers (int, optional): Maximum number of workers for parallel computation. Defaults to 1.
201
-
202
- Returns:
203
- Dict[str, Any]: Computed significance of neighborhoods.
204
- """
205
- log_header("Running permutation test")
206
- # Log and display permutation test settings, which is unique to this test
207
- logger.debug(f"Neighborhood scoring metric: '{score_metric}'")
208
- logger.debug(f"Number of permutations: {num_permutations}")
209
- logger.debug(f"Maximum workers: {max_workers}")
210
- # Compute neighborhood significance using the permutation test
211
- return self._load_neighborhoods_by_statistical_test(
212
- network=network,
213
- annotation=annotation,
214
- distance_metric=distance_metric,
215
- louvain_resolution=louvain_resolution,
216
- leiden_resolution=leiden_resolution,
217
- fraction_shortest_edges=fraction_shortest_edges,
218
- null_distribution=null_distribution,
219
- random_seed=random_seed,
220
- statistical_test_key="permutation",
221
- statistical_test_function=compute_permutation_test,
222
- score_metric=score_metric,
223
- num_permutations=num_permutations,
224
- max_workers=max_workers,
225
- )
226
-
227
- def _load_neighborhoods_by_statistical_test(
228
- self,
229
- network: nx.Graph,
230
- annotation: Dict[str, Any],
231
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
232
- louvain_resolution: float = 0.1,
233
- leiden_resolution: float = 1.0,
234
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
235
- null_distribution: str = "network",
236
- random_seed: int = 888,
237
- statistical_test_key: str = "hypergeom",
238
- statistical_test_function: Any = compute_hypergeom_test,
239
- **kwargs,
240
- ):
241
- """
242
- Load and compute significant neighborhoods for the network using a specified statistical test.
243
-
244
- Args:
245
- network (nx.Graph): The input network graph.
246
- annotation (Dict[str, Any]): Annotation data associated with the network, including a "matrix" key with annotation values.
247
- distance_metric (Union[str, List, Tuple, np.ndarray], optional): The distance metric or clustering method to define neighborhoods.
248
- Can be a string specifying one method (e.g., 'louvain', 'leiden') or a collection of methods.
249
- Defaults to "louvain".
250
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
251
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
252
- fraction_shortest_edges (Union[float, List, Tuple, np.ndarray], optional): Fraction of shortest edges to consider for creating subgraphs.
253
- Can be a single value or a collection of thresholds for flexibility. Defaults to 0.5.
254
- null_distribution (str, optional): The type of null distribution to use ('network' or 'annotation').
255
- Defaults to "network".
256
- random_seed (int, optional): Seed for random number generation to ensure reproducibility. Defaults to 888.
257
- statistical_test_key (str, optional): Key or name of the statistical test to be applied (e.g., "hypergeom", "binom").
258
- Used for logging and debugging. Defaults to "hypergeom".
259
- statistical_test_function (Any, optional): The function implementing the statistical test.
260
- It should accept neighborhoods, annotation, null distribution, and additional kwargs.
261
- Defaults to `compute_hypergeom_test`.
262
- **kwargs: Additional parameters to be passed to the statistical test function.
263
-
264
- Returns:
265
- Dict[str, Any]: A dictionary containing the computed significance values for neighborhoods.
266
- """
267
- # Log null distribution type
268
- logger.debug(f"Null distribution: '{null_distribution}'")
269
- # Log neighborhood analysis parameters
270
- params.log_neighborhoods(
271
- distance_metric=distance_metric,
272
- louvain_resolution=louvain_resolution,
273
- leiden_resolution=leiden_resolution,
274
- fraction_shortest_edges=fraction_shortest_edges,
275
- statistical_test_function=statistical_test_key,
276
- null_distribution=null_distribution,
277
- random_seed=random_seed,
278
- **kwargs,
279
- )
280
-
281
- # Make a copy of the network to avoid modifying the original
282
- network = copy.copy(network)
283
- # Load neighborhoods based on the network and distance metric
284
- neighborhoods = self._load_neighborhoods(
285
- network,
286
- distance_metric,
287
- louvain_resolution=louvain_resolution,
288
- leiden_resolution=leiden_resolution,
289
- fraction_shortest_edges=fraction_shortest_edges,
290
- random_seed=random_seed,
291
- )
292
- # Apply statistical test function to compute neighborhood significance
293
- neighborhood_significance = statistical_test_function(
294
- neighborhoods=neighborhoods,
295
- annotation=annotation["matrix"],
296
- null_distribution=null_distribution,
297
- **kwargs,
298
- )
299
-
300
- # Return the computed neighborhood significance
301
- return neighborhood_significance
302
-
303
- def _load_neighborhoods(
304
- self,
305
- network: nx.Graph,
306
- distance_metric: Union[str, List, Tuple, np.ndarray] = "louvain",
307
- louvain_resolution: float = 0.1,
308
- leiden_resolution: float = 1.0,
309
- fraction_shortest_edges: Union[float, List, Tuple, np.ndarray] = 0.5,
310
- random_seed: int = 888,
311
- ) -> csr_matrix:
312
- """
313
- Load significant neighborhoods for the network.
314
-
315
- Args:
316
- network (nx.Graph): The network graph.
317
- distance_metric (str, List, Tuple, or np.ndarray, optional): The distance metric(s) to use. Can be a string for one
318
- metric or a list/tuple/ndarray of metrics ('greedy_modularity', 'louvain', 'leiden', 'label_propagation',
319
- 'markov_clustering', 'walktrap', 'spinglass'). Defaults to 'louvain'.
320
- louvain_resolution (float, optional): Resolution parameter for Louvain clustering. Defaults to 0.1.
321
- leiden_resolution (float, optional): Resolution parameter for Leiden clustering. Defaults to 1.0.
322
- fraction_shortest_edges (float, List, Tuple, or np.ndarray, optional): Shortest edge rank fraction threshold(s) for creating subgraphs.
323
- Can be a single float for one threshold or a list/tuple of floats corresponding to multiple thresholds.
324
- Defaults to 0.5.
325
- random_seed (int, optional): Seed for random number generation. Defaults to 888.
326
-
327
- Returns:
328
- csr_matrix: Sparse neighborhood matrix calculated based on the selected distance metric.
329
- """
330
- # Display the chosen distance metric
331
- if distance_metric == "louvain":
332
- for_print_distance_metric = f"louvain (resolution={louvain_resolution})"
333
- elif distance_metric == "leiden":
334
- for_print_distance_metric = f"leiden (resolution={leiden_resolution})"
335
- else:
336
- for_print_distance_metric = distance_metric
337
-
338
- # Log and display neighborhood settings
339
- logger.debug(f"Distance metric: '{for_print_distance_metric}'")
340
- logger.debug(f"Edge length threshold: {fraction_shortest_edges}")
341
- logger.debug(f"Random seed: {random_seed}")
342
-
343
- # Compute neighborhoods
344
- neighborhoods = get_network_neighborhoods(
345
- network,
346
- distance_metric,
347
- fraction_shortest_edges,
348
- louvain_resolution=louvain_resolution,
349
- leiden_resolution=leiden_resolution,
350
- random_seed=random_seed,
351
- )
352
-
353
- # Return the sparse neighborhood matrix
354
- return neighborhoods
@@ -1,11 +0,0 @@
1
- """
2
- risk/_neighborhoods/_stats
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- from ._permutation import compute_permutation_test
7
- from ._tests import (
8
- compute_binom_test,
9
- compute_chi2_test,
10
- compute_hypergeom_test,
11
- )
@@ -1,6 +0,0 @@
1
- """
2
- risk/_neighborhoods/_stats/_permutation
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- from ._permutation import compute_permutation_test
@@ -1,72 +0,0 @@
1
- """
2
- risk/_neighborhoods/_stats/_permutation/_test_functions
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- import numpy as np
7
- from scipy.sparse import csr_matrix
8
-
9
- # NOTE: Cython optimizations provided minimal performance benefits.
10
- # The final version with Cython is archived in the `cython_permutation` branch.
11
-
12
- # DISPATCH_TEST_FUNCTIONS can be found at the end of the file.
13
-
14
-
15
- def compute_neighborhood_score_by_sum(
16
- neighborhoods_matrix: csr_matrix, annotation_matrix: csr_matrix
17
- ) -> np.ndarray:
18
- """
19
- Compute the sum of attribute values for each neighborhood using sparse matrices.
20
-
21
- Args:
22
- neighborhoods_matrix (csr_matrix): Sparse binary matrix representing neighborhoods.
23
- annotation_matrix (csr_matrix): Sparse matrix representing annotation values.
24
-
25
- Returns:
26
- np.ndarray: Dense array of summed attribute values for each neighborhood.
27
- """
28
- # Calculate the neighborhood score as the dot product of neighborhoods and annotation
29
- neighborhood_score = neighborhoods_matrix @ annotation_matrix # Sparse matrix multiplication
30
- # Convert the result to a dense array for downstream calculations
31
- neighborhood_score_dense = neighborhood_score.toarray()
32
- return neighborhood_score_dense
33
-
34
-
35
- def compute_neighborhood_score_by_stdev(
36
- neighborhoods_matrix: csr_matrix, annotation_matrix: csr_matrix
37
- ) -> np.ndarray:
38
- """
39
- Compute the standard deviation of neighborhood scores for sparse matrices.
40
-
41
- Args:
42
- neighborhoods_matrix (csr_matrix): Sparse binary matrix representing neighborhoods.
43
- annotation_matrix (csr_matrix): Sparse matrix representing annotation values.
44
-
45
- Returns:
46
- np.ndarray: Standard deviation of the neighborhood scores.
47
- """
48
- # Calculate the neighborhood score as the dot product of neighborhoods and annotation
49
- neighborhood_score = neighborhoods_matrix @ annotation_matrix # Sparse matrix multiplication
50
- # Calculate the number of elements in each neighborhood (sum of rows)
51
- N = neighborhoods_matrix.sum(axis=1).A.flatten() # Convert to 1D array
52
- # Avoid division by zero by replacing zeros in N with np.nan temporarily
53
- N[N == 0] = np.nan
54
- # Compute the mean of the neighborhood scores
55
- M = neighborhood_score.multiply(1 / N[:, None]).toarray() # Sparse element-wise division
56
- # Compute the mean of squares (EXX) directly using squared annotation matrix
57
- annotation_squared = annotation_matrix.multiply(annotation_matrix) # Element-wise squaring
58
- EXX = (neighborhoods_matrix @ annotation_squared).multiply(1 / N[:, None]).toarray()
59
- # Calculate variance as EXX - M^2
60
- variance = EXX - np.power(M, 2)
61
- # Compute the standard deviation as the square root of the variance
62
- neighborhood_stdev = np.sqrt(variance)
63
- # Replace np.nan back with zeros in case N was 0 (no elements in the neighborhood)
64
- neighborhood_stdev[np.isnan(neighborhood_stdev)] = 0
65
- return neighborhood_stdev
66
-
67
-
68
- # Dictionary to dispatch statistical test functions based on the score metric
69
- DISPATCH_TEST_FUNCTIONS = {
70
- "sum": compute_neighborhood_score_by_sum,
71
- "stdev": compute_neighborhood_score_by_stdev,
72
- }
risk/_network/__init__.py DELETED
@@ -1,8 +0,0 @@
1
- """
2
- risk/_network
3
- ~~~~~~~~~~~~~
4
- """
5
-
6
- from ._graph import GraphAPI
7
- from ._io import NetworkAPI
8
- from ._plotter import PlotterAPI
@@ -1,7 +0,0 @@
1
- """
2
- risk/_network/_graph
3
- ~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- from ._api import GraphAPI
7
- from ._graph import Graph
@@ -1,6 +0,0 @@
1
- """
2
- risk/_network/_plotter
3
- ~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- from ._api import PlotterAPI
@@ -1,7 +0,0 @@
1
- """
2
- risk/_network/_plotter/_utils
3
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
- """
5
-
6
- from ._colors import get_annotated_domain_colors, get_domain_colors, to_rgba
7
- from ._layout import calculate_bounding_box, calculate_centroids
@@ -1,41 +0,0 @@
1
- risk/__init__.py,sha256=yv_r0c0z4l4vV4P0053XkOGZfAdW1Fbxa_jSYS7a0yQ,143
2
- risk/_risk.py,sha256=VULCdM41BlWKM1ou4Qc579ffZ9dMZkfhAwKYgbaEeKM,1054
3
- risk/_annotation/__init__.py,sha256=zr7w1DHkmvrkKFGKdPhrcvZHV-xsfd5TZOaWtFiP4Dc,164
4
- risk/_annotation/_annotation.py,sha256=MWbimFSR6FT0SahJ5Ixbe0VMZ5osmgeOgyQqX8ntbec,15045
5
- risk/_annotation/_io.py,sha256=xic3dkEA54X82HbyWfCiXrUpAhPWFPBZ69R8jw31omQ,12457
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=kwCJo8fW1v11fNlCZmC_2XH4TG2ZrIL2j2PvBJrlyj8,18236
12
- risk/_neighborhoods/_community.py,sha256=Tr-EHO91EWbMmNr_z21UCngiqWOlWIqcjwBig_VXI8c,17850
13
- risk/_neighborhoods/_domains.py,sha256=Q3MUWW9KjuERpxs4H1dNFhalDjdatMkWSnB12BerUDU,16580
14
- risk/_neighborhoods/_neighborhoods.py,sha256=9hpQCYG0d9fZLYj-fVACgLJBtw3dW8C-0YbE2OWuX-M,21436
15
- risk/_neighborhoods/_stats/__init__.py,sha256=iu22scpdgTHm6N_hAN81iXIoZCRPFuFAxf71jYWwsUU,213
16
- risk/_neighborhoods/_stats/_tests.py,sha256=KWwNWyKJ3Rrb1cI5qJcKv9YhU1-7sJoI-yMR1RqvHOQ,7557
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=YrAMfhL0CMWQb3sY-mn1VxK44zZAWeFAvHrBONH9I-A,127
21
- risk/_network/_io.py,sha256=wmokwNViz24Gv6o3OFRTYHftYYz4sN64VigGrdEGzy8,28057
22
- risk/_network/_graph/__init__.py,sha256=SFgxgxUiZK4vvw6bdQ04DSMXEr8xjMaQV-Wne6wAIqM,104
23
- risk/_network/_graph/_api.py,sha256=sp3_mLJDP_xQexYBjyM17iyzLb2oGmiC050kcw-jVho,8474
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=RISQHy6Ur37e6F8ZM9X-IwNOit-hUiUxSCUZU_8-1Tw,10198
27
- risk/_network/_plotter/__init__.py,sha256=qFRtQKSBGIqmUGwmA7VPL7hTHBb9yvRIt0nLISXnwkY,84
28
- risk/_network/_plotter/_api.py,sha256=OaV1CCRGsz98wEEzyEhaq2CqEuZh6t2qS7g_rY6HJJs,1727
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.16b1.dist-info/licenses/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
38
- risk_network-0.0.16b1.dist-info/METADATA,sha256=_CFQPvw-w4VBuXqn_4TxFyTQ6EQsO2KxVMBWhkBhpiI,5390
39
- risk_network-0.0.16b1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
- risk_network-0.0.16b1.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
41
- risk_network-0.0.16b1.dist-info/RECORD,,