about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Kabui2021-04-16 02:37:25 +0300
committerAlexander Kabui2021-04-16 02:37:25 +0300
commit6c14eccb7a10cc598d4fa7ee4036cb44bddd9627 (patch)
treeea60c5a67453edfbf50e049d8874036fff037043
parentf3f68f8eb92c7ec9c42bc20bc8e94c435cc745e2 (diff)
downloadgenenetwork3-6c14eccb7a10cc598d4fa7ee4036cb44bddd9627.tar.gz
benchmark normal function for sample r
-rw-r--r--gn3/api/correlation.py4
-rw-r--r--gn3/computations/correlations.py39
2 files changed, 38 insertions, 5 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 7be8e30..e7e89cf 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -16,8 +16,6 @@ correlation = Blueprint("correlation", __name__)
 def compute_sample_integration(corr_method="pearson"):
     """temporary api to  help integrate genenetwork2  to genenetwork3 """
 
-    # for debug
-    print("Calling this endpoint")
     correlation_input = request.get_json()
 
     target_samplelist = correlation_input.get("target_samplelist")
@@ -76,8 +74,6 @@ def compute_lit_corr(species=None, gene_id=None):
 @correlation.route("/tissue_corr/<string:corr_method>", methods=["POST"])
 def compute_tissue_corr(corr_method="pearson"):
     """Api endpoint fr doing tissue correlation"""
-    # for debug
-    print("The request has been received")
     tissue_input_data = request.get_json()
     primary_tissue_dict = tissue_input_data["primary_tissue"]
     target_tissues_dict = tissue_input_data["target_tissues_dict"]
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py
index fb62b56..90b6c8c 100644
--- a/gn3/computations/correlations.py
+++ b/gn3/computations/correlations.py
@@ -128,7 +128,7 @@ def compute_all_sample_correlation(this_trait,
     corr_results = []
     processed_values = []
     for target_trait in target_dataset:
-        # trait_id = target_trait.get("trait_id")
+        # trait_name = target_trait.get("trait_id")
         target_trait_data = target_trait["trait_sample_data"]
         # this_vals, target_vals = filter_shared_sample_keys(
         #     this_trait_samples, target_trait_data)
@@ -152,6 +152,43 @@ def compute_all_sample_correlation(this_trait,
 
     return corr_results
 
+    def benchmark_compute_all_sample(this_trait,
+                                     target_datasets,
+                                     corr_method="pearson") ->List:
+        """Temp function to benchmark with compute_all_sample_r
+        """
+
+        this_trait_samples = this_trait["trait_sample_data"]
+
+        corr_results = []
+
+        for target_trait in target_dataset:
+            trait_id = target_trait.get("trait_id")
+            target_trait_data = target_trait["trait_sample_data"]
+            this_vals, target_vals = filter_shared_sample_keys(
+                this_trait_samples, target_trait_data)
+
+            sample_correlation = compute_sample_r_correlation(
+                corr_method=corr_method,
+                trait_vals=this_vals,
+                target_samples_vals=target_vals)
+
+            if sample_correlation is not None:
+                (corr_coeffient, p_value, num_overlap) = sample_correlation
+
+            else:
+                continue
+
+            corr_result = {
+                "corr_coeffient": corr_coeffient,
+                "p_value": p_value,
+                "num_overlap": num_overlap
+            }
+
+            corr_results.append({trait_id: corr_result})
+
+        return corr_results
+
 
 def tissue_lit_corr_for_probe_type(corr_type: str, top_corr_results):
     """Function that does either lit_corr_for_trait_list or tissue_corr _for_trait