risk-network 0.0.9b29__py3-none-any.whl → 0.0.9b31__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/stats/stat_tests.py +31 -43
- {risk_network-0.0.9b29.dist-info → risk_network-0.0.9b31.dist-info}/METADATA +1 -1
- {risk_network-0.0.9b29.dist-info → risk_network-0.0.9b31.dist-info}/RECORD +7 -7
- {risk_network-0.0.9b29.dist-info → risk_network-0.0.9b31.dist-info}/LICENSE +0 -0
- {risk_network-0.0.9b29.dist-info → risk_network-0.0.9b31.dist-info}/WHEEL +0 -0
- {risk_network-0.0.9b29.dist-info → risk_network-0.0.9b31.dist-info}/top_level.txt +0 -0
risk/__init__.py
CHANGED
risk/stats/stat_tests.py
CHANGED
@@ -3,7 +3,6 @@ risk/stats/stat_tests
|
|
3
3
|
~~~~~~~~~~~~~~~~~~~~~
|
4
4
|
"""
|
5
5
|
|
6
|
-
from concurrent.futures import ThreadPoolExecutor
|
7
6
|
from typing import Any, Dict
|
8
7
|
|
9
8
|
import numpy as np
|
@@ -121,62 +120,51 @@ def compute_hypergeom_test(
|
|
121
120
|
annotations: csr_matrix,
|
122
121
|
null_distribution: str = "network",
|
123
122
|
) -> Dict[str, Any]:
|
124
|
-
"""
|
123
|
+
"""
|
124
|
+
Compute hypergeometric test for enrichment and depletion in neighborhoods with selectable null distribution.
|
125
125
|
|
126
126
|
Args:
|
127
127
|
neighborhoods (csr_matrix): Sparse binary matrix representing neighborhoods.
|
128
128
|
annotations (csr_matrix): Sparse binary matrix representing annotations.
|
129
|
-
null_distribution (str, optional): Type of null distribution ('network' or 'annotations').
|
130
|
-
Defaults to "network".
|
129
|
+
null_distribution (str, optional): Type of null distribution ('network' or 'annotations'). Defaults to "network".
|
131
130
|
|
132
131
|
Returns:
|
133
132
|
Dict[str, Any]: Dictionary containing depletion and enrichment p-values.
|
134
133
|
"""
|
135
134
|
# Get the total number of nodes in the network
|
136
135
|
total_nodes = neighborhoods.shape[1]
|
137
|
-
# Calculate neighborhood and annotation sums
|
138
|
-
neighborhood_sums = neighborhoods.sum(axis=0).A1 # A1 returns a 1D array
|
139
|
-
annotation_sums = annotations.sum(axis=0).A1
|
140
136
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
neighborhood_sums = neighborhoods.sum(axis=0).A1
|
147
|
-
annotation_sums = annotations.sum(axis=0).A1
|
148
|
-
elif null_distribution == "network":
|
137
|
+
# Compute sums
|
138
|
+
neighborhood_sums = neighborhoods.sum(axis=0).A.flatten() # Convert to dense array
|
139
|
+
annotation_sums = annotations.sum(axis=0).A.flatten() # Convert to dense array
|
140
|
+
|
141
|
+
if null_distribution == "network":
|
149
142
|
background_population = total_nodes
|
143
|
+
elif null_distribution == "annotations":
|
144
|
+
annotated_nodes = annotations.sum(axis=1).A.flatten() > 0 # Boolean mask
|
145
|
+
background_population = annotated_nodes.sum()
|
146
|
+
neighborhood_sums = neighborhoods[annotated_nodes].sum(axis=0).A.flatten()
|
147
|
+
annotation_sums = annotations[annotated_nodes].sum(axis=0).A.flatten()
|
150
148
|
else:
|
151
|
-
raise ValueError(
|
152
|
-
|
153
|
-
# Sparse matrix multiplication for observed counts
|
154
|
-
annotated_in_neighborhood = neighborhoods.T @ annotations # Result is sparse
|
155
|
-
|
156
|
-
def compute_pvals_for_column(col_idx: int):
|
157
|
-
"""Compute depletion and enrichment p-values for a single annotation column."""
|
158
|
-
observed_counts = annotated_in_neighborhood[:, col_idx].toarray().flatten()
|
159
|
-
ann_total = annotation_sums[col_idx]
|
160
|
-
# Compute depletion and enrichment p-values
|
161
|
-
depletion_pvals = hypergeom.cdf(
|
162
|
-
observed_counts, background_population, ann_total, neighborhood_sums
|
163
|
-
)
|
164
|
-
enrichment_pvals = hypergeom.sf(
|
165
|
-
observed_counts - 1, background_population, ann_total, neighborhood_sums
|
149
|
+
raise ValueError(
|
150
|
+
"Invalid null_distribution value. Choose either 'network' or 'annotations'."
|
166
151
|
)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
#
|
177
|
-
|
178
|
-
|
179
|
-
|
152
|
+
|
153
|
+
# Observed counts
|
154
|
+
annotated_in_neighborhood = neighborhoods.T @ annotations # Sparse result
|
155
|
+
annotated_in_neighborhood = annotated_in_neighborhood.toarray() # Convert to dense
|
156
|
+
# Align shapes for broadcasting
|
157
|
+
neighborhood_sums = neighborhood_sums.reshape(-1, 1)
|
158
|
+
annotation_sums = annotation_sums.reshape(1, -1)
|
159
|
+
background_population = np.array(background_population).reshape(1, 1)
|
160
|
+
|
161
|
+
# Compute hypergeometric p-values
|
162
|
+
depletion_pvals = hypergeom.cdf(
|
163
|
+
annotated_in_neighborhood, background_population, annotation_sums, neighborhood_sums
|
164
|
+
)
|
165
|
+
enrichment_pvals = hypergeom.sf(
|
166
|
+
annotated_in_neighborhood - 1, background_population, annotation_sums, neighborhood_sums
|
167
|
+
)
|
180
168
|
|
181
169
|
return {"depletion_pvals": depletion_pvals, "enrichment_pvals": enrichment_pvals}
|
182
170
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
risk/__init__.py,sha256=
|
1
|
+
risk/__init__.py,sha256=u9we76elYKA9qWrJZg4C-XZbyChmetziqTr0kOIDH18,127
|
2
2
|
risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
|
3
3
|
risk/risk.py,sha256=s827_lRknFseOP9O4zW8sP-IcCd2EzrpV_tnVY_tz5s,1104
|
4
4
|
risk/annotations/__init__.py,sha256=parsbcux1U4urpUqh9AdzbDWuLj9HlMidycMPkpSQFo,179
|
@@ -30,12 +30,12 @@ risk/network/plotter/utils/colors.py,sha256=VU1sLPRC99ll6EGK4vRNgLMUXU8lja1vjiXU
|
|
30
30
|
risk/network/plotter/utils/layout.py,sha256=OPqV8jzV9dpnOhYU4SYMSfsIXalVzESrlBSI_Y43OGU,3640
|
31
31
|
risk/stats/__init__.py,sha256=2zdLv3tUHKyAjwAo7LprVXRaak1cHgrpYMVMSik6JM4,324
|
32
32
|
risk/stats/significance.py,sha256=6cKv2xBQXWTHZ6HpNWIqlNfKKS5pG_BcCUdMM3r_zw4,7336
|
33
|
-
risk/stats/stat_tests.py,sha256=
|
33
|
+
risk/stats/stat_tests.py,sha256=MR59l5k0i5AiEIjPFPKIKHcj_nQ2wxvwW4eqYV7jOa0,11776
|
34
34
|
risk/stats/permutation/__init__.py,sha256=OLmYLm2uj96hPsSaUs0vUqFYw6Thwch_aHtpL7L0ZFw,127
|
35
35
|
risk/stats/permutation/permutation.py,sha256=BWjgdBpLVcHvmwHy0bmD4aJFccxifNBSrrCBPppyKf4,10569
|
36
36
|
risk/stats/permutation/test_functions.py,sha256=D3XMPM8CasUNytWSRce22TI6KK6XulYn5uGG4lWxaHs,3120
|
37
|
-
risk_network-0.0.
|
38
|
-
risk_network-0.0.
|
39
|
-
risk_network-0.0.
|
40
|
-
risk_network-0.0.
|
41
|
-
risk_network-0.0.
|
37
|
+
risk_network-0.0.9b31.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
|
38
|
+
risk_network-0.0.9b31.dist-info/METADATA,sha256=cX2PA1RUzQx0gTvycUyJBiolwlIxQKtzuCQQmHnGYn0,47627
|
39
|
+
risk_network-0.0.9b31.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
40
|
+
risk_network-0.0.9b31.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
|
41
|
+
risk_network-0.0.9b31.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|