aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kabui2021-04-17 04:15:41 +0300
committerAlexander Kabui2021-04-17 04:15:41 +0300
commit04965d0157a9b6545dbd1007685f7c3defa26e61 (patch)
treea71ff844a74cce2ce3fd5f86271fd808b7d57b48
parent114f80d96d8bd8742b74a0aefdcbdcd22c42767b (diff)
downloadgenenetwork3-04965d0157a9b6545dbd1007685f7c3defa26e61.tar.gz
add sort for correlation results
refactor return data type for tissue and lit
-rw-r--r--gn3/computations/correlations.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py
index a311b8d..804716c 100644
--- a/gn3/computations/correlations.py
+++ b/gn3/computations/correlations.py
@@ -150,7 +150,11 @@ def compute_all_sample_correlation(this_trait,
corr_results.append({"trait_name_key": corr_result})
- return corr_results
+ sorted_corr_results = sorted(
+ corr_results,
+ key=lambda trait_name: -abs(list(trait_name.values())[0]["corr_coeffient"]))
+ return sorted_corr_results
+
def benchmark_compute_all_sample(this_trait,
target_dataset,
@@ -234,8 +238,8 @@ def tissue_correlation_for_trait_list(
lit_corr_result = {
"tissue_corr": tissue_corr_coeffient,
- "p_value": p_value,
- "tissue_number": len(primary_tissue_vals)
+ "tissue_number": len(primary_tissue_vals),
+ "p_value": p_value
}
return lit_corr_result
@@ -291,6 +295,7 @@ def lit_correlation_for_trait_list(
species=species,
gene_id=trait_gene_id)
+
for (trait_name, target_trait_gene_id) in target_trait_lists:
corr_results = {}
if target_trait_gene_id:
@@ -359,8 +364,11 @@ def compute_all_lit_correlation(conn, trait_lists: List,
target_trait_lists=trait_lists,
species=species,
trait_gene_id=gene_id)
+ sorted_lit_results = sorted(
+ lit_results,
+ key=lambda trait_name: -abs(list(trait_name.values())[0]["lit_corr"]))
- return {"lit_results": lit_results}
+ return sorted_lit_results
def compute_all_tissue_correlation(primary_tissue_dict: dict,
@@ -372,7 +380,7 @@ def compute_all_tissue_correlation(primary_tissue_dict: dict,
"""
- tissues_results = {}
+ tissues_results = []
primary_tissue_vals = primary_tissue_dict["tissue_values"]
traits_symbol_dict = target_tissues_data["trait_symbol_dict"]
@@ -391,9 +399,14 @@ def compute_all_tissue_correlation(primary_tissue_dict: dict,
target_tissues_values=target_tissue_vals,
corr_method=corr_method)
- tissues_results[trait_id] = tissue_result
+ 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 tissues_results
+ return sorted_tissues_results
def process_trait_symbol_dict(trait_symbol_dict, symbol_tissue_vals_dict) -> List: