diff options
author | Lei Yan | 2013-05-30 23:14:50 +0000 |
---|---|---|
committer | Lei Yan | 2013-05-30 23:14:50 +0000 |
commit | 466be48f92d4943995c7a3e7bcb9fd1efd775bf6 (patch) | |
tree | 3afd09770d889176cf96b9be4425daddda00626d /wqflask/wqflask | |
parent | cb639316fe007c8bcad731976e8b095dee59115e (diff) | |
download | genenetwork2-466be48f92d4943995c7a3e7bcb9fd1efd775bf6.tar.gz |
Rewrote some code in get_trait_info in dataset.py
Added spearman correlation to show_corr_results and template
Diffstat (limited to 'wqflask/wqflask')
-rw-r--r-- | wqflask/wqflask/correlation/show_corr_results.py | 36 | ||||
-rw-r--r-- | wqflask/wqflask/templates/correlation_page.html | 52 |
2 files changed, 56 insertions, 32 deletions
diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index aa20eba1..5d40c835 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -30,7 +30,6 @@ from __future__ import absolute_import, print_function, division import string -from math import * import cPickle import os import time @@ -106,6 +105,7 @@ class CorrelationResults(object): corr_samples_group = start_vars['corr_samples_group'] self.sample_data = {} + self.corr_method = start_vars['corr_sample_method'] #The two if statements below append samples to the sample list based upon whether the user #rselected Primary Samples Only, Other Samples Only, or All Samples @@ -123,27 +123,31 @@ class CorrelationResults(object): #if statement if the user selected All Samples) if corr_samples_group != 'samples_primary': self.process_samples(start_vars, self.this_trait.data.keys(), primary_samples) + self.target_dataset = data_set.create_dataset(start_vars['corr_dataset']) self.target_dataset.get_trait_data() + self.correlation_data = {} for trait, values in self.target_dataset.trait_data.iteritems(): - trait_values = [] + this_trait_values = [] target_values = [] for index, sample in enumerate(self.target_dataset.samplelist): - target_value = values[index] - if sample in self.sample_data.keys(): - this_value = self.sample_data[sample] - trait_values.append(this_value) - target_values.append(target_value) - (trait_values, target_values) = normalize_values(trait_values, target_values) - correlation = scipy.stats.pearsonr(trait_values, target_values) - #correlation = cal_correlation(trait_values, target_values) - self.correlation_data[trait] = correlation[0] - #print ('correlation result: %s %s' % (trait, correlation)) - - for trait in self.correlation_data: - print("correlation: ", self.correlation_data[trait]) - + if sample in self.sample_data: + sample_value = self.sample_data[sample] + target_sample_value = values[index] + this_trait_values.append(sample_value) + target_values.append(target_sample_value) + + this_trait_values, target_values = normalize_values(this_trait_values, target_values) + if self.corr_method == 'pearson': + sample_r, sample_p = scipy.stats.pearsonr(this_trait_values, target_values) + else: + sample_r, sample_p = scipy.stats.spearmanr(this_trait_values, target_values) + self.correlation_data[trait] = [sample_r, sample_p] + self.correlation_data = collections.OrderedDict( + sorted(self.correlation_data.items(), + key=lambda t: -abs(t[1][0]))) + #XZ, 09/18/2008: get all information about the user selected database. #target_db_name = fd.corr_dataset diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index be750a0c..68fe81ed 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -1,21 +1,42 @@ {% extends "base.html" %} -{% block content %} -<table id="corr_results" class="table table-hover table-striped table-bordered"> - <thead> - <tr> - <td>Correlation</td> - </tr> - </thead> - <tbody> - {% for trait in correlation_data %} - <tr> - <td>{{ correlation_data[trait] }}</td> - </tr> - {% endfor %} - </tbody> -</table> +{% block css %} + <link rel="stylesheet" type="text/css" href="/static/packages/jqplot/jquery.jqplot.min.css" /> + <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> + <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" /> + <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" /> {% endblock %} +{% block content %} + <header class="jumbotron subhead" id="overview"> + <div class="container"> + <h1>Correlation</h1> + </div> + </header> + + <table id="corr_results" class="table table-hover table-striped table-bordered"> + <thead> + <tr> + <th>Trait</th> + {% if corr_method == 'pearson' %} + <th>Sample r</th> + <th>Sample p(r)</th> + {% else %} + <th>Sample rho</th> + <th>Sample p(rho)</th> + {% endif %} + </tr> + </thead> + <tbody> + {% for trait in correlation_data %} + <tr> + <td>{{ trait }}</td> + <td>{{ correlation_data[trait][0] }}</td> + <td>{{ correlation_data[trait][1] }}</td> + </tr> + {% endfor %} + </tbody> + </table> +{% endblock %} {% block js %} <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script> @@ -23,7 +44,6 @@ <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script> <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> - <script type="text/javascript" charset="utf-8"> $(document).ready( function () { console.time("Creating table"); |