diff options
author | Alexander Kabui | 2021-04-20 01:40:17 +0300 |
---|---|---|
committer | Alexander Kabui | 2021-04-20 01:40:17 +0300 |
commit | 61ec8882abaea2e1ad4c88daabcc1969a76230dc (patch) | |
tree | 82cab803c34f08652c07563d9ca30b120dc4f719 /gn3 | |
parent | d266ca9d59093c253ce7b56f9a14119869eb0003 (diff) | |
download | genenetwork3-61ec8882abaea2e1ad4c88daabcc1969a76230dc.tar.gz |
add experiment function for computing tissue correlation using multiprocessing
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/computations/correlations.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 8410995..66a2034 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -429,3 +429,50 @@ def process_trait_symbol_dict(trait_symbol_dict, symbol_tissue_vals_dict) -> Lis traits_tissue_vals.append(target_tissue_dict) return traits_tissue_vals + + +def experimental_compute_all_tissue_correlation(primary_tissue_dict: dict, + target_tissues_data: dict, + corr_method: str): + """Experimental function that uses multiprocessing\ + for computing tissue correlation + """ + + tissues_results = [] + + primary_tissue_vals = primary_tissue_dict["tissue_values"] + traits_symbol_dict = target_tissues_data["trait_symbol_dict"] + symbol_tissue_vals_dict = target_tissues_data["symbol_tissue_vals_dict"] + + target_tissues_list = process_trait_symbol_dict( + traits_symbol_dict, symbol_tissue_vals_dict) + processed_values = [] + + for target_tissue_obj in target_tissues_list: + trait_id = target_tissue_obj.get("trait_id") + + target_tissue_vals = target_tissue_obj.get("tissue_values") + processed_values.append( + (primary_tissue_vals, target_tissue_vals, corr_method)) + + tissue_results = [] + with multiprocessing.Pool() as pool: + results = pool.starmap( + tissue_correlation_for_trait_list, processed_values) + for result in results: + tissue_result_dict = {"trait_name": result} + tissues_results.append(tissue_result_dict) + + # tissue_result = tissue_correlation_for_trait_list( + # primary_tissue_vals=primary_tissue_vals, + # target_tissues_values=target_tissue_vals, + # corr_method=corr_method) + + # tissue_result_dict = {trait_id: tissue_result} + # tissues_results.append(tissue_result_dict) + + sorted_tissues_results = sorted( + tissues_results, + key=lambda trait_name: -abs(list(trait_name.values())[0]["tissue_corr"])) + + return sorted_tissues_results |