From 6d87fc08c130937c3f35fb9bbf6d2c68bc825e97 Mon Sep 17 00:00:00 2001 From: Alexander Kabui Date: Wed, 15 Dec 2021 09:50:24 +0300 Subject: init mp calculate 1 --- gn3/computations/correlations.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 -- cgit v1.2.3