aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Sloan2012-09-19 17:06:42 -0500
committerZachary Sloan2012-09-19 17:06:42 -0500
commit1e081d88b96660c69d2de9e6b00a54f800348cde (patch)
tree32e515376a0103a15c2103a84fd60717c3aeae3f
parent6e89a31cf7e654fb1b99d6fa86e7cdabb68cb243 (diff)
downloadgenenetwork2-1e081d88b96660c69d2de9e6b00a54f800348cde.tar.gz
Made pearson/spearman options disappear if lit correlation is chosen, began to address how to deal with Trait object in CorrelationPage
-rwxr-xr-xwqflask/base/webqtlTrait.py34
-rw-r--r--wqflask/wqflask/correlation/CorrelationPage.py33
-rw-r--r--wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee4
-rw-r--r--wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js7
-rw-r--r--wqflask/wqflask/templates/trait_data_and_analysis.html9
-rw-r--r--wqflask/wqflask/views.py2
6 files changed, 68 insertions, 21 deletions
diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py
index 337493ef..8240eafc 100755
--- a/wqflask/base/webqtlTrait.py
+++ b/wqflask/base/webqtlTrait.py
@@ -660,3 +660,37 @@ class webqtlTrait:
else:
return dict(name = self.db.fullname,
url = webqtlConfig.INFOPAGEHREF % self.db.name)
+
+ def calculate_correlation(self, values, method):
+ """Calculate the correlation value and p value according to the method specified"""
+
+ #ZS: This takes the list of values of the trait our selected trait is being correlated against and removes the values of the samples our trait has no value for
+ #There's probably a better way of dealing with this, but I'll have to ask Christian
+ updated_raw_values = []
+ updated_values = []
+ for i in range(len(values)):
+ if values[i] != "None":
+ updated_raw_values.append(self.raw_values[i])
+ updated_values.append(values[i])
+
+ self.raw_values = updated_raw_values
+ values = updated_values
+
+ if method == METHOD_SAMPLE_PEARSON or method == METHOD_LIT or method == METHOD_TISSUE_PEARSON:
+ corr, nOverlap = webqtlUtil.calCorrelation(self.raw_values, values, len(values))
+ else:
+ corr, nOverlap = webqtlUtil.calCorrelationRank(self.raw_values, values, len(values))
+
+ self.correlation = corr
+ self.overlap = nOverlap
+
+ if self.overlap < 3:
+ self.p_value = 1.0
+ else:
+ #ZS - This is probably the wrong way to deal with this. Correlation values of 1.0 definitely exist (the trait correlated against itself), so zero division needs to br prevented.
+ if abs(self.correlation) >= 1.0:
+ self.p_value = 0.0
+ else:
+ ZValue = 0.5*log((1.0+self.correlation)/(1.0-self.correlation))
+ ZValue = ZValue*sqrt(self.overlap-3)
+ self.p_value = 2.0*(1.0 - reaper.normp(abs(ZValue)))
diff --git a/wqflask/wqflask/correlation/CorrelationPage.py b/wqflask/wqflask/correlation/CorrelationPage.py
index 1f7f2553..a9db493b 100644
--- a/wqflask/wqflask/correlation/CorrelationPage.py
+++ b/wqflask/wqflask/correlation/CorrelationPage.py
@@ -72,7 +72,9 @@ class AuthException(Exception): pass
class Trait(object):
- def __init__(self, name, raw_values = None, lit_corr = None, tissue_corr = None, p_tissue = None):
+
+
+ def __init__(self, name, raw_values = None, lit_corr = None, tissue_corr = None, p_tissue = None):
self.name = name
self.raw_values = raw_values
self.lit_corr = lit_corr
@@ -260,16 +262,16 @@ def auth_user_for_db(db, cursor, target_db_name, privilege, username):
class CorrelationPage(templatePage):
- corrMinInformative = 4
+ corr_min_informative = 4
PAGE_HEADING = "Correlation Table"
- CORRELATION_METHODS = {"1" : "Genetic Correlation (Pearson's r)",
- "2" : "Genetic Correlation (Spearman's rho)",
- "3" : "SGO Literature Correlation",
- "4" : "Tissue Correlation (Pearson's r)",
- "5" : "Tissue Correlation (Spearman's rho)"}
-
- RANK_ORDERS = {"1": 0, "2": 1, "3": 0, "4": 0, "5": 1}
+ #CORRELATION_METHODS = {"1" : "Genetic Correlation (Pearson's r)",
+ # "2" : "Genetic Correlation (Spearman's rho)",
+ # "3" : "SGO Literature Correlation",
+ # "4" : "Tissue Correlation (Pearson's r)",
+ # "5" : "Tissue Correlation (Spearman's rho)"}
+ #
+ #RANK_ORDERS = {"1": 0, "2": 1, "3": 0, "4": 0, "5": 1}
def error(self, message, *args, **kw):
@@ -288,7 +290,7 @@ class CorrelationPage(templatePage):
#print("in CorrelationPage __init__ now fd is:", pf(fd.__dict__))
# Connect to the database
if not self.openMysql():
- returnt
+ return
# Read the genotype from a file
if not fd.genotype:
@@ -329,19 +331,20 @@ class CorrelationPage(templatePage):
print("samplenames is:", pf(self.sample_names))
#CF - If less than a minimum number of strains/cases in common, don't calculate anything
- if len(self.sample_names) < self.corrMinInformative:
- detail = ['Fewer than %d strain data were entered for %s data set. No calculation of correlation has been attempted.' % (self.corrMinInformative, fd.RISet)]
+ if len(self.sample_names) < self.corr_min_informative:
+ detail = ['Fewer than %d strain data were entered for %s data set. No calculation of correlation has been attempted.' % (self.corr_min_informative, fd.RISet)]
self.error(heading=None, detail=detail)
for key, value in self.__dict__.items():
if key.startswith("corr"):
print("[red] %s - %s" % (key, value))
- correlation_method = self.CORRELATION_METHODS[self.method]
- rankOrder = self.RANK_ORDERS[self.method]
+ #correlation_method = self.CORRELATION_METHODS[self.method]
+ #rankOrder = self.RANK_ORDERS[self.method]
# CF - Number of results returned
- self.returnNumber = int(fd.criteria)
+ # Todo: Get rid of self.returnNumber
+ self.returnNumber = self.corr_return_results
self.record_count = 0
diff --git a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee
index 5aef18e5..2952bef5 100644
--- a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee
+++ b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.coffee
@@ -196,6 +196,10 @@ $ ->
console.log("corr_method is:", corr_method)
$('.correlation_desc').hide()
$('#' + corr_method + "_r_desc").show().effect("highlight")
+ if corr_method == "lit"
+ $("#corr_sample_method_options").hide()
+ else
+ $("#corr_sample_method_options").show()
$('select[name=corr_method]').change(on_corr_method_change)
diff --git a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js
index 05b25197..04f43822 100644
--- a/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js
+++ b/wqflask/wqflask/static/new/javascript/trait_data_and_analysis.js
@@ -218,7 +218,12 @@
corr_method = $('select[name=corr_method]').val();
console.log("corr_method is:", corr_method);
$('.correlation_desc').hide();
- return $('#' + corr_method + "_r_desc").show().effect("highlight");
+ $('#' + corr_method + "_r_desc").show().effect("highlight");
+ if (corr_method === "lit") {
+ return $("#corr_sample_method_options").hide();
+ } else {
+ return $("#corr_sample_method_options").show();
+ }
};
$('select[name=corr_method]').change(on_corr_method_change);
console.log("before registering show_hide_outliers");
diff --git a/wqflask/wqflask/templates/trait_data_and_analysis.html b/wqflask/wqflask/templates/trait_data_and_analysis.html
index 05fd457a..16f2e2be 100644
--- a/wqflask/wqflask/templates/trait_data_and_analysis.html
+++ b/wqflask/wqflask/templates/trait_data_and_analysis.html
@@ -762,10 +762,11 @@
</table>
<br>
- Pearson <input type="radio" name="corr_sample_method" value="pearson" checked>
- &nbsp;&nbsp;&nbsp;
- Spearman Rank <input type="radio" name="corr_sample_method" value="spearman">
- <br>
+ <div id="corr_sample_method_options">
+ Pearson <input type="radio" name="corr_sample_method" value="pearson" checked>
+ &nbsp;&nbsp;&nbsp;
+ Spearman Rank <input type="radio" name="corr_sample_method" value="spearman">
+ </div>
<br>
<input type="submit" name="corr_compute" id="corr_compute" class="button" value="Compute"><br><br>
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 1b60f255..0befb74a 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -90,7 +90,7 @@ def corr_compute():
print("Have fd")
template_vars = CorrelationPage.CorrelationPage(fd)
print("Made it to rendering")
- return render_template("corr_compute.html", **template_vars.__dict__)
+ return render_template("correlation_page.html", **template_vars.__dict__)
# Todo: Can we simplify this? -Sam