aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2021-07-12 12:37:08 +0300
committerGitHub2021-07-12 12:37:08 +0300
commit0055c6d4680e7ab465034a4c2f2020fb5266952d (patch)
tree961cf33072c6089583f87d39539c53e0d5dd986a /wqflask
parent344d6a86d2e468249ec7b583e8c0751f99cd6a5b (diff)
parent8b565a25b643e7ad653cb2c17d6456d073245dc5 (diff)
downloadgenenetwork2-0055c6d4680e7ab465034a4c2f2020fb5266952d.tar.gz
Merge pull request #590 from Alexanderlacuna/bugfix/rpy2-tissue-broken-links
replace rpy2 for tissue correlation
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py20
-rw-r--r--wqflask/wqflask/correlation/correlation_functions.py39
-rw-r--r--wqflask/wqflask/correlation/show_corr_results.py8
-rw-r--r--wqflask/wqflask/templates/base.html2
4 files changed, 36 insertions, 33 deletions
diff --git a/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py
index 2bbeab1f..a8cf6006 100644
--- a/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py
+++ b/wqflask/tests/unit/wqflask/correlation/test_correlation_functions.py
@@ -1,10 +1,30 @@
+"""module contains tests for correlation functions"""
+
import unittest
from unittest import mock
+
from wqflask.correlation.correlation_functions import get_trait_symbol_and_tissue_values
from wqflask.correlation.correlation_functions import cal_zero_order_corr_for_tiss
class TestCorrelationFunctions(unittest.TestCase):
+ """test for correlation helper functions"""
+
+ @mock.patch("wqflask.correlation.correlation_functions.compute_corr_coeff_p_value")
+ def test_tissue_corr_computation(self, mock_tiss_corr_computation):
+ """test for cal_zero_order_corr_for_tiss"""
+
+ primary_values = [9.288, 9.313, 8.988, 9.660, 8.21]
+ target_values = [9.586, 8.498, 9.362, 8.820, 8.786]
+
+ mock_tiss_corr_computation.return_value = (0.51, 0.7)
+
+ results = cal_zero_order_corr_for_tiss(primary_values, target_values)
+ mock_tiss_corr_computation.assert_called_once_with(
+ primary_values=primary_values, target_values=target_values,
+ corr_method="pearson")
+
+ self.assertEqual(len(results), 3)
@mock.patch("wqflask.correlation.correlation_functions.MrnaAssayTissueData")
def test_get_trait_symbol_and_tissue_values(self, mock_class):
diff --git a/wqflask/wqflask/correlation/correlation_functions.py b/wqflask/wqflask/correlation/correlation_functions.py
index c8b9da0e..85b25d60 100644
--- a/wqflask/wqflask/correlation/correlation_functions.py
+++ b/wqflask/wqflask/correlation/correlation_functions.py
@@ -21,15 +21,10 @@
# This module is used by GeneNetwork project (www.genenetwork.org)
#
# Created by GeneNetwork Core Team 2010/08/10
-#
-# Last updated by NL 2011/03/23
-import math
-import string
from base.mrna_assay_tissue_data import MrnaAssayTissueData
-
-from flask import Flask, g
+from gn3.computations.correlations import compute_corr_coeff_p_value
#####################################################################################
@@ -45,31 +40,14 @@ from flask import Flask, g
# the same tissue order
#####################################################################################
-def cal_zero_order_corr_for_tiss(primaryValue=[], targetValue=[], method='pearson'):
-
- N = len(primaryValue)
- # R_primary = rpy2.robjects.FloatVector(list(range(len(primaryValue))))
- # for i in range(len(primaryValue)):
- # R_primary[i] = primaryValue[i]
- # R_target = rpy2.robjects.FloatVector(list(range(len(targetValue))))
- # for i in range(len(targetValue)):
- # R_target[i] = targetValue[i]
+def cal_zero_order_corr_for_tiss(primary_values, target_values, method="pearson"):
+ """function use calls gn3 to compute corr,p_val"""
- # R_corr_test = rpy2.robjects.r['cor.test']
- # if method == 'spearman':
- # R_result = R_corr_test(R_primary, R_target, method='spearman')
- # else:
- # R_result = R_corr_test(R_primary, R_target)
-
- # corr_result = []
- # corr_result.append(R_result[3][0])
- # corr_result.append(N)
- # corr_result.append(R_result[2][0])
-
- return [None, N, None]
- # return corr_result
+ (corr_coeff, p_val) = compute_corr_coeff_p_value(
+ primary_values=primary_values, target_values=target_values, corr_method=method)
+ return (corr_coeff, len(primary_values), p_val)
########################################################################################################
# input: cursor, symbolList (list), dataIdDict(Dict): key is symbol
@@ -80,8 +58,9 @@ def cal_zero_order_corr_for_tiss(primaryValue=[], targetValue=[], method='pearso
# then call getSymbolValuePairDict function and merge the results.
########################################################################################################
+
def get_trait_symbol_and_tissue_values(symbol_list=None):
tissue_data = MrnaAssayTissueData(gene_symbols=symbol_list)
- if len(tissue_data.gene_symbols) >0:
+ if len(tissue_data.gene_symbols) > 0:
results = tissue_data.get_symbol_values_pairs()
- return results
+ return results
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py
index bebef9e7..e936f28c 100644
--- a/wqflask/wqflask/correlation/show_corr_results.py
+++ b/wqflask/wqflask/correlation/show_corr_results.py
@@ -25,6 +25,7 @@ from base.data_set import create_dataset
from utility import hmac
+
def set_template_vars(start_vars, correlation_data):
corr_type = start_vars['corr_type']
corr_method = start_vars['corr_sample_method']
@@ -55,11 +56,14 @@ def set_template_vars(start_vars, correlation_data):
correlation_data['corr_method'] = corr_method
correlation_data['filter_cols'] = filter_cols
- correlation_data['header_fields'] = get_header_fields(target_dataset_ob.type, correlation_data['corr_method'])
- correlation_data['formatted_corr_type'] = get_formatted_corr_type(corr_type, corr_method)
+ correlation_data['header_fields'] = get_header_fields(
+ target_dataset_ob.type, correlation_data['corr_method'])
+ correlation_data['formatted_corr_type'] = get_formatted_corr_type(
+ corr_type, corr_method)
return correlation_data
+
def correlation_json_for_table(correlation_data, this_trait, this_dataset, target_dataset_ob):
"""Return JSON data for use with the DataTable in the correlation result page
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index 12dddf89..049ebe6d 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -208,7 +208,7 @@
<a href="http://joss.theoj.org/papers/10.21105/joss.00025"><img src="https://camo.githubusercontent.com/846b750f582ae8f1d0b4f7e8fee78bed705c88ba/687474703a2f2f6a6f73732e7468656f6a2e6f72672f7061706572732f31302e32313130352f6a6f73732e30303032352f7374617475732e737667" alt="JOSS" data-canonical-src="http://joss.theoj.org/papers/10.21105/joss.00025/status.svg" style="max-width:100%;"></a>
</p>
<p>
- Development and source code on <a href="https://github.com/genenetwork/">github</a> with <a href="https://github.com/genenetwork/genenetwork2/issues">issue tracker</a> and <a href="https://github.com/genenetwork/genenetwork2/blob/master/README.md">documentation</a>. Join the <a href="http://listserv.uthsc.edu/mailman/listinfo/genenetwork-dev">mailing list</a> and find us on <span class="broken_link" href="https://webchat.freenode.net/">IRC</span> (#genenetwork channel).
+ Development and source code on <a href="https://github.com/genenetwork/">github</a> with <a href="https://github.com/genenetwork/genenetwork2/issues">issue tracker</a> and <a href="https://github.com/genenetwork/genenetwork2/blob/master/README.md">documentation</a>. Join the <span class="broken_link" href="http://listserv.uthsc.edu/mailman/listinfo/genenetwork-dev">mailing list</span> and find us on <a href="https://webchat.freenode.net#genenetwork">IRC</a> (#genenetwork channel).
{% if version: %}
<p><small>GeneNetwork {{ version }}</small></p>
{% endif %}