aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Kabui2021-04-19 00:24:36 +0300
committerAlexander Kabui2021-04-19 00:24:36 +0300
commit50c0ee93a59eecd40a6fbd19139671c94003c21b (patch)
treeda1ae3e9706f95f763ca0e04a1b87a898e143c71
parentba2fa2025bdc381346afc8ec3203f229ed3551d6 (diff)
downloadgenenetwork2-50c0ee93a59eecd40a6fbd19139671c94003c21b.tar.gz
fix for correlation_demo template
-rw-r--r--wqflask/wqflask/correlation/correlation_gn3_api.py53
-rw-r--r--wqflask/wqflask/templates/demo_correlation_page.html23
2 files changed, 44 insertions, 32 deletions
diff --git a/wqflask/wqflask/correlation/correlation_gn3_api.py b/wqflask/wqflask/correlation/correlation_gn3_api.py
index 75bd5561..ba606b92 100644
--- a/wqflask/wqflask/correlation/correlation_gn3_api.py
+++ b/wqflask/wqflask/correlation/correlation_gn3_api.py
@@ -9,9 +9,10 @@ from base.trait import create_trait
from base.trait import retrieve_sample_data
# gn3 lib
from gn3.computations.correlations import compute_all_sample_correlation
-from gn3.computations.correlations import benchmark_compute_all_sample
from gn3.computations.correlations import map_shared_keys_to_values
from gn3.computations.correlations import compute_all_tissue_correlation
+from gn3.computations.correlations import compute_all_lit_correlation
+from gn3.db_utils import database_connector
GN3_CORRELATION_API = "http://127.0.0.1:8202/api/correlation"
@@ -36,10 +37,6 @@ def process_samples(start_vars, sample_names, excluded_samples=None):
def create_target_this_trait(start_vars):
"""this function creates the required trait and target dataset for correlation"""
- print("creating the dataset and trait")
- import time
-
- initial_time = time.time()
this_dataset = data_set.create_dataset(dataset_name=start_vars['dataset'])
target_dataset = data_set.create_dataset(
@@ -48,17 +45,10 @@ def create_target_this_trait(start_vars):
this_trait = create_trait(dataset=this_dataset,
name=start_vars['trait_id'])
-
# target_dataset.get_trait_data(list(self.sample_data.keys()))
# this_trait = retrieve_sample_data(this_trait, this_dataset)
- print(f"Starting to creat the target dataset ")
- dataset_start_time = time.time()
sample_data = ()
-
-
-
- time_taken = time.time() - initial_time
return (this_dataset, this_trait, target_dataset, sample_data)
@@ -77,6 +67,7 @@ def compute_correlation(start_vars, method="pearson"):
corr_input_data = {}
if corr_type == "sample":
+ initial_time = time.time()
# corr_input_data = {
# "target_dataset": target_dataset.trait_data,
# "target_samplelist": target_dataset.samplelist,
@@ -85,50 +76,44 @@ def compute_correlation(start_vars, method="pearson"):
# "trait_id": start_vars["trait_id"]
# }
# }
-
- sample_data = process_samples(start_vars, this_dataset.group.samplelist)
+ sample_data = process_samples(
+ start_vars, this_dataset.group.samplelist)
target_dataset.get_trait_data(list(sample_data.keys()))
this_trait = retrieve_sample_data(this_trait, this_dataset)
-
+ print("Creating dataset and trait took",time.time()-initial_time)
this_trait_data = {
"trait_sample_data": sample_data,
"trait_id": start_vars["trait_id"]
}
-
initial_time = time.time()
- print("Calling sample correlation")
results = map_shared_keys_to_values(
target_dataset.samplelist, target_dataset.trait_data)
correlation_results = compute_all_sample_correlation(corr_method=method,
this_trait=this_trait_data,
target_dataset=results)
- print("Time taken is>>>>",time.time()-initial_time)
+ print("doing sample correlation took",time.time()-initial_time)
# requests_url = f"{GN3_CORRELATION_API}/sample_x/{method}"
return correlation_results
elif corr_type == "tissue":
trait_symbol_dict = this_dataset.retrieve_genes("Symbol")
- time_to_retrieve = time.time()
primary_tissue_data, target_tissue_data = get_tissue_correlation_input(
this_trait, trait_symbol_dict)
- print("Time taken to retrieve this is",time.time()-time_to_retrieve)
corr_input_data = {
"primary_tissue": primary_tissue_data,
"target_tissues_dict": target_tissue_data
}
- print("Calling tissue correlation")
initial_time = time.time()
correlation_results = compute_all_tissue_correlation(primary_tissue_dict=corr_input_data["primary_tissue"],
target_tissues_data=corr_input_data["target_tissues_dict"],
corr_method=method)
+ print("time taken for compute tissue is",time.time()-initial_time)
- time_taken = time.time()
- print("Time taken is ??????",time_taken-initial_time)
# requests_url = f"{GN3_CORRELATION_API}/tissue_corr/{method}"
return correlation_results
@@ -137,15 +122,23 @@ def compute_correlation(start_vars, method="pearson"):
(this_trait_geneid, geneid_dict, species) = do_lit_correlation(
this_trait, this_dataset, target_dataset)
- requests_url = f"{GN3_CORRELATION_API}/lit_corr/{species}/{this_trait_geneid}"
- corr_input_data = geneid_dict
+ conn, _cursor_object = database_connector()
+ initial_time = time.time()
+ with conn:
- print("Sending this request")
- corr_results = requests.post(requests_url, json=corr_input_data)
+ lit_corr_results = compute_all_lit_correlation(
+ conn=conn, trait_lists=list(geneid_dict.items()),
+ species=species, gene_id=this_trait_geneid)
- data = corr_results.json()
+ return lit_corr_results
+ print("the time taken is",time.time()-initial_time)
+ # requests_url = f"{GN3_CORRELATION_API}/lit_corr/{species}/{this_trait_geneid}"
+ # corr_input_data = geneid_dict
+ # corr_results = requests.post(requests_url, json=corr_input_data)
- return data
+ # data = corr_results.json()
+
+ # return data
def do_lit_correlation(this_trait, this_dataset, target_dataset):
@@ -164,11 +157,11 @@ def get_tissue_correlation_input(this_trait, trait_symbol_dict):
"""Gets tissue expression values for the primary trait and target tissues values"""
primary_trait_tissue_vals_dict = correlation_functions.get_trait_symbol_and_tissue_values(
symbol_list=[this_trait.symbol])
-
if this_trait.symbol.lower() in primary_trait_tissue_vals_dict:
primary_trait_tissue_values = primary_trait_tissue_vals_dict[this_trait.symbol.lower(
)]
+ time_to_to_fetch_all = time.time()
corr_result_tissue_vals_dict = correlation_functions.get_trait_symbol_and_tissue_values(
symbol_list=list(trait_symbol_dict.values()))
primary_tissue_data = {
diff --git a/wqflask/wqflask/templates/demo_correlation_page.html b/wqflask/wqflask/templates/demo_correlation_page.html
index d2979f9d..67e3c57c 100644
--- a/wqflask/wqflask/templates/demo_correlation_page.html
+++ b/wqflask/wqflask/templates/demo_correlation_page.html
@@ -22,9 +22,28 @@
{% for key,value in corr_result.items()%}
<div class="container-content">
<div><p>{{key}}</p></div>
- {%for o_key,o_value in value.items()%}
+ <!-- 'p_value': 5.909407416079734e-11, 'num_overlap': 67 -->
+ {% if "corr_coeffient" in value %}
+ <div><p>{{value["corr_coeffient"]}}</p></div>
+ {%elif "tissue_corr" in value %}
+ <div><p>{{value["tissue_corr"]}}</p></div>
+ {%elif "lit_corr" in value %}
+ {{value["lit_corr"]}}
+ {% endif %}
+ {%if "tissue_number" in value %}
+ <div>{{value["tissue_number"]}}</div>
+ {%elif "num_overlap" in value %}
+ <div><p>{{value["num_overlap"]}}</p></div>
+ {% endif %}
+ <div><p>{{value["p_value"]}}</p></div>
+
+
+
+<!-- {{value["num_overlap"]}}
+ {{value["p_value"]}} -->
+<!-- {%for o_key,o_value in value.items()%}
<div><p>{{o_value}}</p></div>
- {%endfor%}
+ {%endfor%} -->
{% endfor %}
</div>
{% endfor %}