aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2019-03-04 10:37:46 -0600
committerzsloan2019-03-04 10:37:46 -0600
commitfe94046b9fbd5b5d1f85920fc4263eb5c4aa1328 (patch)
tree8e5eb088247ded2cd64976360aeb5dfc2ea5dfe3
parentf9b9524367c45a1b362a9e074985b58d6e8e1419 (diff)
downloadgenenetwork2-fe94046b9fbd5b5d1f85920fc4263eb5c4aa1328.tar.gz
- Added z-score transformation
- Added text indicating which transformation has been applied
-rw-r--r--wqflask/wqflask/show_trait/show_trait.py25
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js27
-rw-r--r--wqflask/wqflask/templates/show_trait.html12
-rw-r--r--wqflask/wqflask/templates/show_trait_edit_data.html2
-rw-r--r--wqflask/wqflask/templates/show_trait_transform_and_filter.html1
5 files changed, 51 insertions, 16 deletions
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index 4e4c7705..932260de 100644
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -12,6 +12,7 @@ from collections import OrderedDict
import redis
Redis = redis.StrictRedis()
+import numpy as np
import scipy.stats as ss
from flask import Flask, g
@@ -138,6 +139,7 @@ class ShowTrait(object):
self.make_sample_lists()
self.qnorm_vals = quantile_normalize_vals(self.sample_groups)
+ self.z_scores = get_z_scores(self.sample_groups)
# Todo: Add back in the ones we actually need from below, as we discover we need them
hddn = OrderedDict()
@@ -226,6 +228,7 @@ class ShowTrait(object):
attribute_names = self.sample_groups[0].attributes,
num_values = self.num_values,
qnorm_values = self.qnorm_vals,
+ zscore_values = self.z_scores,
sample_column_width = sample_column_width,
temp_uuid = self.temp_uuid)
self.js_data = js_data
@@ -277,11 +280,15 @@ class ShowTrait(object):
if self.dataset.group.species == "human":
primary_sample_names += other_sample_names
+ if other_sample_names:
+ primary_header = "%s Only" % (self.dataset.group.name)
+ else:
+ primary_header = "Samples"
primary_samples = SampleList(dataset = self.dataset,
sample_names=primary_sample_names,
this_trait=self.this_trait,
sample_group_type='primary',
- header="%s Only" % (self.dataset.group.name))
+ header=primary_header)
if other_sample_names and self.dataset.group.species != "human" and self.dataset.group.name != "CFW":
parent_f1_samples = None
@@ -292,13 +299,11 @@ class ShowTrait(object):
if parent_f1_samples:
other_sample_names = parent_f1_samples + other_sample_names
- logger.debug("other_sample_names:", other_sample_names)
-
other_samples = SampleList(dataset=self.dataset,
sample_names=other_sample_names,
this_trait=self.this_trait,
sample_group_type='other',
- header="Non-%s" % (self.dataset.group.name))
+ header="Other")
self.sample_groups = (primary_samples, other_samples)
else:
@@ -360,17 +365,19 @@ def get_z_scores(sample_groups):
except:
continue
- qnorm_vals = normf(trait_vals)
- qnorm_vals_with_x = []
+ zscores = ss.mstats.zscore(np.array(trait_vals)).tolist()
+ zscores_with_x = []
counter = 0
for sample in sample_type.sample_list:
if sample.display_value == "x":
- qnorm_vals_with_x.append("x")
+ zscores_with_x.append("x")
else:
- qnorm_vals_with_x.append(qnorm_vals[counter])
+ zscores_with_x.append("%0.3f" % zscores[counter])
counter += 1
- qnorm_by_group.append(qnorm_vals_with_x)
+ zscore_by_group.append(zscores_with_x)
+
+ return zscore_by_group
def get_nearest_marker(this_trait, this_db):
this_chr = this_trait.locus_chr
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index e985078b..9bbcd560 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -557,6 +557,7 @@ block_outliers = function() {
$('#block_outliers').click(block_outliers);
reset_samples_table = function() {
$('input[name="transform"]').val("");
+ $('span[name="transform_text"]').text("")
return $('.trait_value_input').each((function(_this) {
return function(_index, element) {
$(element).val($(element).data('value'));
@@ -623,26 +624,52 @@ qnorm_data = function() {
})(this));
};
+zscore_data = function() {
+ return $('.edit_sample_value').each((function(_this) {
+ return function(_index, element) {
+ current_value = parseFloat($(element).data("value")) + 1;
+ if(isNaN(current_value)) {
+ return current_value
+ } else {
+ $(element).val($(element).data("zscore"));
+ return $(element).data("zscore");
+ }
+ };
+ })(this));
+};
+
normalize_data = function() {
if ($('#norm_method option:selected').val() == 'log2'){
if ($('input[name="transform"]').val() != "log2") {
log_normalize_data()
$('input[name="transform"]').val("log2")
+ $('span[name="transform_text"]').text(" - log2 transformed")
}
}
else if ($('#norm_method option:selected').val() == 'sqrt'){
if ($('input[name="transform"]').val() != "sqrt") {
sqrt_normalize_data()
$('input[name="transform"]').val("sqrt")
+ $('span[name="transform_text"]').text(" - Square Root transformed")
}
}
else if ($('#norm_method option:selected').val() == 'invert'){
invert_data()
+ $('input[name="transform"]').val("inverted")
+ $('span[name="transform_text"]').text(" - Inverted")
}
else if ($('#norm_method option:selected').val() == 'qnorm'){
if ($('input[name="transform"]').val() != "qnorm") {
qnorm_data()
$('input[name="transform"]').val("qnorm")
+ $('span[name="transform_text"]').text(" - Quantile Normalized")
+ }
+ }
+ else if ($('#norm_method option:selected').val() == 'zscore'){
+ if ($('input[name="transform"]').val() != "zscore") {
+ zscore_data()
+ $('input[name="transform"]').val("zscore")
+ $('span[name="transform_text"]').text(" - Z-Scores")
}
}
}
diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index 3bd57f89..e4feb817 100644
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -294,9 +294,9 @@
'data': null,
'render': function(data, type, row, meta) {
if (data.value == null) {
- return '<input type="text" data-value="x" data-qnorm="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_value" value="x" size=6 maxlength=6>'
+ return '<input type="text" data-value="x" data-qnorm="x" data-zscore="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_value" value="x" size=6 maxlength=6>'
} else {
- return '<input type="text" data-value="' + data.value.toFixed(3) + '" data-qnorm="' + js_data['qnorm_values'][0][parseInt(data.this_id)] + '" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_value" value="' + data.value.toFixed(3) + '" size=6 maxlength=6>'
+ return '<input type="text" data-value="' + data.value.toFixed(3) + '" data-qnorm="' + js_data['qnorm_values'][0][parseInt(data.this_id)] + '" data-zscore="' + js_data['zscore_values'][0][parseInt(data.this_id)] + '" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_value" value="' + data.value.toFixed(3) + '" size=6 maxlength=6>'
}
}
}{% if sample_groups[0].se_exists() %},
@@ -315,9 +315,9 @@
'data': null,
'render': function(data, type, row, meta) {
if (data.variance == null) {
- return '<input type="text" data-value="x" data-qnorm="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_se" value="x" size=6 maxlength=6>'
+ return '<input type="text" data-value="x" data-qnorm="x" data-zscore="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_se" value="x" size=6 maxlength=6>'
} else {
- return '<input type="text" data-value="' + data.variance.toFixed(3) + '" data-qnorm="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_se" value="' + data.variance.toFixed(3) + '" size=6 maxlength=6>'
+ return '<input type="text" data-value="' + data.variance.toFixed(3) + '" data-qnorm="x" data-zscore="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_se" value="' + data.variance.toFixed(3) + '" size=6 maxlength=6>'
}
}
}{% endif %}{% if has_num_cases %},
@@ -328,9 +328,9 @@
'data': null,
'render': function(data, type, row, meta) {
if (data.num_cases == null) {
- return '<input type="text" data-value="x" data-qnorm="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_num_cases" value="x" size=4 maxlength=4>'
+ return '<input type="text" data-value="x" data-qnorm="x" data-zscore="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_num_cases" value="x" size=4 maxlength=4>'
} else {
- return '<input type="text" data-value="' + data.num_cases + '" data-qnorm="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_num_cases" value="' + data.num_cases + '" size=4 maxlength=4>'
+ return '<input type="text" data-value="' + data.num_cases + '" data-qnorm="x" data-zscore="x" name="value:' + data.name + '" style="text-align: right;" class="trait_value_input edit_sample_num_cases" value="' + data.num_cases + '" size=4 maxlength=4>'
}
}
}{% endif %}{% if sample_groups[0].attributes|length > 0 %}{% for attribute in sample_groups[0].attributes|sort() %},
diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html
index a5e42fdb..667d557c 100644
--- a/wqflask/wqflask/templates/show_trait_edit_data.html
+++ b/wqflask/wqflask/templates/show_trait_edit_data.html
@@ -13,7 +13,7 @@
{% for sample_type in sample_groups %}
{% set outer_loop = loop %}
<div class="sample_group" style="width:{{ trait_table_width }};">
- <h3>{{ sample_type.header }}</h3>
+ <h3>{{ sample_type.header }}<span name="transform_text"></span></h3>
<hr style="margin-top: 4px; margin-bottom: 10px; height: 1px; background-color: #A9A9A9;">
<div id="table_container">
<table class="table-hover table-striped cell-border" id="samples_{{ sample_type.sample_group_type }}" style="float: left; width:100%;">
diff --git a/wqflask/wqflask/templates/show_trait_transform_and_filter.html b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
index 04ceaeaf..6803da58 100644
--- a/wqflask/wqflask/templates/show_trait_transform_and_filter.html
+++ b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
@@ -52,6 +52,7 @@
<input type="button" id="normalize" class="btn btn-default" value="Normalize">
<select id="norm_method" class="select optional span2">
<option value="log2">Log2</option>
+ <option value="zscore">Z-score</option>
<option value="qnorm">Quantile</option>
<option value="sqrt">Square Root</option>
<option value="invert">Invert +/-</option>