aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorAlexander Kabui2021-12-15 09:50:24 +0300
committerAlexander Kabui2021-12-15 09:50:24 +0300
commit6d87fc08c130937c3f35fb9bbf6d2c68bc825e97 (patch)
treed2cad5339142db3c01f87c5e30151b6a2f160b05 /gn3/computations
parent4f8042a67cab94384bb30e73ec5139fdd3a4c8b5 (diff)
downloadgenenetwork3-6d87fc08c130937c3f35fb9bbf6d2c68bc825e97.tar.gz
init mp calculate 1
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/correlations.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py
index d38946e..24e9871 100644
--- a/gn3/computations/correlations.py
+++ b/gn3/computations/correlations.py
@@ -422,3 +422,26 @@ def fast_compute_tissue_correlation(primary_tissue_dict: dict,
return sorted(
tissues_results,
key=lambda trait_name: -abs(list(trait_name.values())[0]["tissue_corr"]))
+
+
+def _mp_calculate(x_val, dataset, n_jobs, chunk_size):
+ """corr mp reimplementation
+ credit:https://github.com/bukson/nancorrmp
+ """
+
+ def _compute_correlation_2(x_val, y_val, trait_name):
+ """function to compute correlation"""
+
+ return (trait_name, scipy.stats.pearsonr(x_val, y_val))
+
+ arguments = ((x_val, y_val, trait_name) for (trait_name, y_val) in dataset)
+
+ processes = n_jobs if n_jobs > 0 else None
+
+ worker_function = _compute_correlation_2
+
+ with multiprocessing.pool(processes=processes) as pool:
+ results = list(pool.imap_unordered(
+ worker_function, arguments, chunksize=chunks))
+
+ return results