diff options
-rw-r--r-- | gn3/computations/correlations.py | 28 | ||||
-rw-r--r-- | tests/unit/computations/test_correlation.py | 8 |
2 files changed, 14 insertions, 22 deletions
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 3563530..065a1ed 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -226,6 +226,7 @@ def tissue_correlation_for_trait_list( primary_tissue_vals: List, target_tissues_values: List, corr_method: str, + trait_id: str, compute_corr_p_value: Callable = compute_corr_coeff_p_value) -> dict: """Given a primary tissue values for a trait and the target tissues values compute the correlation_cooeff and p value the input required are arrays @@ -241,13 +242,12 @@ def tissue_correlation_for_trait_list( target_values=target_tissues_values, corr_method=corr_method) - lit_corr_result = { + tiss_corr_result = {trait_id: { "tissue_corr": tissue_corr_coeffient, "tissue_number": len(primary_tissue_vals), - "p_value": p_value - } + "p_value": p_value}} - return lit_corr_result + return tiss_corr_result def fetch_lit_correlation_data( @@ -432,9 +432,9 @@ def process_trait_symbol_dict(trait_symbol_dict, symbol_tissue_vals_dict) -> Lis return traits_tissue_vals -def experimental_compute_all_tissue_correlation(primary_tissue_dict: dict, - target_tissues_data: dict, - corr_method: str): +def compute_tissue_correlation(primary_tissue_dict: dict, + target_tissues_data: dict, + corr_method: str): """Experimental function that uses multiprocessing\ for computing tissue correlation """ @@ -450,25 +450,17 @@ def experimental_compute_all_tissue_correlation(primary_tissue_dict: 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)) + (primary_tissue_vals, target_tissue_vals, corr_method, trait_id)) 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) + tissues_results.append(result) return sorted( tissues_results, diff --git a/tests/unit/computations/test_correlation.py b/tests/unit/computations/test_correlation.py index c6fa35e..6414c3b 100644 --- a/tests/unit/computations/test_correlation.py +++ b/tests/unit/computations/test_correlation.py @@ -235,12 +235,12 @@ class TestCorrelation(TestCase): primary_tissue_values = [1.1, 1.5, 2.3] target_tissues_values = [1, 2, 3] mock_compute_corr_coeff.side_effect = [(0.4, 0.9), (-0.2, 0.91)] - expected_tissue_results = { - 'tissue_corr': 0.4, 'p_value': 0.9, "tissue_number": 3} - + expected_tissue_results = {"1456_at": {"tissue_corr": 0.4, + "p_value": 0.9, "tissue_number": 3}} tissue_results = tissue_correlation_for_trait_list( primary_tissue_values, target_tissues_values, - corr_method="pearson", compute_corr_p_value=mock_compute_corr_coeff) + corr_method="pearson", trait_id="1456_at", + compute_corr_p_value=mock_compute_corr_coeff) self.assertEqual(tissue_results, expected_tissue_results) |