diff options
Diffstat (limited to 'wqflask')
3 files changed, 30 insertions, 32 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 f1cf3733..b0496bfe 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -34,6 +34,7 @@ from utility import corr_result_helpers from utility import hmac from wqflask.correlation import correlation_functions + from utility.benchmark import Bench from utility.type_checking import is_str @@ -93,7 +94,6 @@ class CorrelationResults: self.p_range_lower = get_float(start_vars, 'p_range_lower', -1.0) self.p_range_upper = get_float(start_vars, 'p_range_upper', 1.0) - if ('loc_chr' in start_vars and 'min_loc_mb' in start_vars and 'max_loc_mb' in start_vars): @@ -198,7 +198,6 @@ class CorrelationResults: if chr_info.name == trait_object.chr: chr_as_int = order_id - if (float(self.correlation_data[trait][0]) >= self.p_range_lower and float(self.correlation_data[trait][0]) <= self.p_range_upper): |