risk-network 0.0.7b6__py3-none-any.whl → 0.0.7b7__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 CHANGED
@@ -7,4 +7,4 @@ RISK: RISK Infers Spatial Kinships
7
7
 
8
8
  from risk.risk import RISK
9
9
 
10
- __version__ = "0.0.7-beta.6"
10
+ __version__ = "0.0.7-beta.7"
@@ -4,6 +4,7 @@ risk/stats/permutation/permutation
4
4
  """
5
5
 
6
6
  from multiprocessing import get_context, Manager
7
+ from multiprocessing.managers import ValueProxy
7
8
  from tqdm import tqdm
8
9
  from typing import Any, Callable, Dict
9
10
 
@@ -111,7 +112,6 @@ def _run_permutation_test(
111
112
  # Initialize count matrices for depletion and enrichment
112
113
  counts_depletion = np.zeros(observed_neighborhood_scores.shape)
113
114
  counts_enrichment = np.zeros(observed_neighborhood_scores.shape)
114
-
115
115
  # Determine the number of permutations to run in each worker process
116
116
  subset_size = num_permutations // max_workers
117
117
  remainder = num_permutations % max_workers
@@ -121,7 +121,6 @@ def _run_permutation_test(
121
121
  manager = Manager()
122
122
  progress_counter = manager.Value("i", 0)
123
123
  total_progress = num_permutations
124
-
125
124
  # Execute the permutation test using multiprocessing
126
125
  with ctx.Pool(max_workers) as pool:
127
126
  with tqdm(total=total_progress, desc="Total progress", position=0) as progress:
@@ -135,7 +134,8 @@ def _run_permutation_test(
135
134
  neighborhood_score_func,
136
135
  subset_size + (1 if i < remainder else 0),
137
136
  progress_counter,
138
- rng, # Pass the RNG to each process
137
+ max_workers,
138
+ rng, # Pass the random number generator to each worker
139
139
  )
140
140
  for i in range(max_workers)
141
141
  ]
@@ -152,10 +152,10 @@ def _run_permutation_test(
152
152
  # Ensure progress bar reaches 100%
153
153
  progress.update(total_progress - progress.n)
154
154
 
155
- # Accumulate results from each worker
156
- for local_counts_depletion, local_counts_enrichment in results.get():
157
- counts_depletion = np.add(counts_depletion, local_counts_depletion)
158
- counts_enrichment = np.add(counts_enrichment, local_counts_enrichment)
155
+ # Accumulate results from each worker
156
+ for local_counts_depletion, local_counts_enrichment in results.get():
157
+ counts_depletion = np.add(counts_depletion, local_counts_depletion)
158
+ counts_enrichment = np.add(counts_enrichment, local_counts_enrichment)
159
159
 
160
160
  return counts_depletion, counts_enrichment
161
161
 
@@ -167,7 +167,8 @@ def _permutation_process_subset(
167
167
  observed_neighborhood_scores: np.ndarray,
168
168
  neighborhood_score_func: Callable,
169
169
  subset_size: int,
170
- progress_counter,
170
+ progress_counter: ValueProxy,
171
+ max_workers: int,
171
172
  rng: np.random.Generator,
172
173
  ) -> tuple:
173
174
  """Process a subset of permutations for the permutation test.
@@ -179,7 +180,8 @@ def _permutation_process_subset(
179
180
  observed_neighborhood_scores (np.ndarray): Observed neighborhood scores.
180
181
  neighborhood_score_func (Callable): Function to calculate neighborhood scores.
181
182
  subset_size (int): Number of permutations to run in this subset.
182
- progress_counter: Shared counter for tracking progress.
183
+ progress_counter (multiprocessing.managers.ValueProxy): Shared counter for tracking progress.
184
+ max_workers (int): Number of workers for multiprocessing.
183
185
  rng (np.random.Generator): Random number generator object.
184
186
 
185
187
  Returns:
@@ -188,10 +190,11 @@ def _permutation_process_subset(
188
190
  # Initialize local count matrices for this worker
189
191
  local_counts_depletion = np.zeros(observed_neighborhood_scores.shape)
190
192
  local_counts_enrichment = np.zeros(observed_neighborhood_scores.shape)
191
- # NOTE: Limit the number of threads used by NumPy's BLAS implementation to 1.
192
- # This can help prevent oversubscription of CPU resources during multiprocessing,
193
- # ensuring that each process doesn't use more than one CPU core.
194
- with threadpool_limits(limits=1, user_api="blas"):
193
+ # NOTE: Limit the number of threads used by NumPy's BLAS implementation to 1 when more than one worker is used.
194
+ # This can help prevent oversubscription of CPU resources during multiprocessing, ensuring that each process
195
+ # doesn't use more than one CPU core.
196
+ limits = None if max_workers == 1 else 1
197
+ with threadpool_limits(limits=limits, user_api="blas"):
195
198
  for _ in range(subset_size):
196
199
  # Permute the annotation matrix using the RNG
197
200
  annotation_matrix_permut = annotation_matrix[rng.permutation(idxs)]
@@ -209,7 +212,6 @@ def _permutation_process_subset(
209
212
  local_counts_enrichment,
210
213
  permuted_neighborhood_scores >= observed_neighborhood_scores,
211
214
  )
212
-
213
215
  # Update the shared progress counter
214
216
  progress_counter.value += 1
215
217
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: risk-network
3
- Version: 0.0.7b6
3
+ Version: 0.0.7b7
4
4
  Summary: A Python package for biological network analysis
5
5
  Author: Ira Horecka
6
6
  Author-email: Ira Horecka <ira89@icloud.com>
@@ -1,4 +1,4 @@
1
- risk/__init__.py,sha256=usWMc5kXOn1-bcSacSXIi_nGKYj4cIQyRvSzvAWGbMI,112
1
+ risk/__init__.py,sha256=0dNrjhRgqzBRG5Rqy_GKy_8ETWm10xSCYvaOm6fdI0Q,112
2
2
  risk/constants.py,sha256=XInRaH78Slnw_sWgAsBFbUHkyA0h0jL0DKGuQNbOvjM,550
3
3
  risk/risk.py,sha256=6666BzdMTgOaQl98ZKiJ19c6XBot26eTJ0iIlk-ZCZQ,20515
4
4
  risk/annotations/__init__.py,sha256=vUpVvMRE5if01Ic8QY6M2Ae3EFGJHdugEe9PdEkAW4Y,138
@@ -21,10 +21,10 @@ risk/stats/hypergeom.py,sha256=DcGYjmfcgt1qshNZPJt5IHGIHtxw9tWRS1r6QJ6V3dI,2378
21
21
  risk/stats/poisson.py,sha256=CnLk65CHViR4YhAaN3ix37iyLm_YQYGo851bSnGyyxY,1950
22
22
  risk/stats/stats.py,sha256=kvShov-94W6ffgDUTb522vB9hDJQSyTsYif_UIaFfSM,7059
23
23
  risk/stats/permutation/__init__.py,sha256=neJp7FENC-zg_CGOXqv-iIvz1r5XUKI9Ruxhmq7kDOI,105
24
- risk/stats/permutation/permutation.py,sha256=bFcgTJZI8cLODvGoW4QtMeBnuUs2HibJ42OZyC74Tz0,9427
24
+ risk/stats/permutation/permutation.py,sha256=kmSZ7bQ-AD0TFiQDgIwfxTeqHa4pjp7fIcOzAqyhUNY,9714
25
25
  risk/stats/permutation/test_functions.py,sha256=HuDIM-V1jkkfE1rlaIqrWWBSKZt3dQ1f-YEDjWpnLSE,2343
26
- risk_network-0.0.7b6.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
- risk_network-0.0.7b6.dist-info/METADATA,sha256=BQRgen5tB4jtWEWvm6VXkYPX3WudtzPpsxtFUtz3Ej0,43142
28
- risk_network-0.0.7b6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
- risk_network-0.0.7b6.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
- risk_network-0.0.7b6.dist-info/RECORD,,
26
+ risk_network-0.0.7b7.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
27
+ risk_network-0.0.7b7.dist-info/METADATA,sha256=LDTOo8S-g09TbNgixGR4nCBkyaHW_usy0zE8kNsqTRg,43142
28
+ risk_network-0.0.7b7.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ risk_network-0.0.7b7.dist-info/top_level.txt,sha256=NX7C2PFKTvC1JhVKv14DFlFAIFnKc6Lpsu1ZfxvQwVw,5
30
+ risk_network-0.0.7b7.dist-info/RECORD,,