aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Sloan2012-12-06 16:50:20 -0600
committerZachary Sloan2012-12-06 16:50:20 -0600
commit41721f0d386c034470fe68e0017295474242ab48 (patch)
tree169d5ca3d895326ce2dc1e3f95dae72ccd2cffe1
parent2ec627563efa9fdf4fc74cb4764bfebb5ab90933 (diff)
downloadgenenetwork2-41721f0d386c034470fe68e0017295474242ab48.tar.gz
Added minimum/maximum to basic statistics table
Continued bug-shooting related to getting show_trait running with phenotype traits
-rwxr-xr-xwqflask/base/data_set.py32
-rw-r--r--wqflask/wqflask/do_search.py5
-rw-r--r--wqflask/wqflask/search_results.py7
-rwxr-xr-xwqflask/wqflask/show_trait/show_trait.py7
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.coffee86
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js10
-rw-r--r--wqflask/wqflask/static/new/javascript/stats.coffee31
-rw-r--r--wqflask/wqflask/static/new/javascript/stats.js18
-rw-r--r--wqflask/wqflask/templates/search_result_page.html4
-rw-r--r--wqflask/wqflask/templates/show_trait.html2
-rw-r--r--wqflask/wqflask/templates/show_trait_details.html2
-rw-r--r--wqflask/wqflask/templates/show_trait_edit_data.html2
12 files changed, 122 insertions, 84 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index 9f0f3fac..2182fe9e 100755
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -30,6 +30,7 @@ from htmlgen import HTMLgen2 as HT
import reaper
import webqtlConfig
+from dbFunction import webqtlDatabaseFunction
from utility import webqtlUtil
from MySQLdb import escape_string as escape
@@ -72,10 +73,12 @@ class DatasetGroup(object):
"""
def __init__(self, dataset):
"""This sets self.group and self.group_id"""
- self.name, self.group_id = g.db.execute(dataset.query).fetchone()
+ self.name, self.id = g.db.execute(dataset.query_for_group).fetchone()
if self.name == 'BXD300':
self.name = "BXD"
+ self.species = webqtlDatabaseFunction.retrieve_species(self.name)
+
self.incparentsf1 = False
self.f1list = None
self.parlist = None
@@ -151,14 +154,25 @@ class DataSet(object):
self.check_confidentiality()
- self.retrieve_name()
+ self.retrieve_other_names()
self.group = DatasetGroup(self) # sets self.group and self.group_id
def get_desc(self):
"""Gets overridden later, at least for Temp...used by trait's get_given_name"""
return None
-
+
+ #@staticmethod
+ #def get_by_trait_id(trait_id):
+ # """Gets the dataset object given the trait id"""
+ #
+ #
+ #
+ # name = g.db.execute(""" SELECT
+ #
+ # """)
+ #
+ # return DataSet(name)
# Delete this eventually
@property
@@ -175,7 +189,7 @@ class DataSet(object):
- def retrieve_name(self):
+ def retrieve_other_names(self):
"""
If the data set name parameter is not found in the 'Name' field of the data set table,
check if it is actually the FullName or ShortName instead.
@@ -326,7 +340,7 @@ class PhenotypeDataSet(DataSet):
def retrieve_sample_data(self, trait):
query = """
SELECT
- Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id
+ Strain.Name, PublishData.value, PublishSE.error, NStrain.count
FROM
(PublishData, Strain, PublishXRef, PublishFreeze)
left join PublishSE on
@@ -340,7 +354,7 @@ class PhenotypeDataSet(DataSet):
PublishFreeze.Id = %d AND PublishData.StrainId = Strain.Id
Order BY
Strain.Name
- """ % (self.trait.name, self.id)
+ """ % (trait.name, self.id)
results = g.db.execute(query).fetchall()
return results
@@ -368,7 +382,7 @@ class GenotypeDataSet(DataSet):
# Todo: Obsolete or rename this field
self.type = 'Geno'
- self.query = '''
+ self.query_for_group = '''
SELECT
InbredSet.Name, InbredSet.Id
FROM
@@ -418,7 +432,7 @@ class GenotypeDataSet(DataSet):
GenoData.StrainId = Strain.Id
Order BY
Strain.Name
- """ % (webqtlDatabaseFunction.retrieve_species_id(self.group), trait.name, self.name)
+ """ % (webqtlDatabaseFunction.retrieve_species_id(self.group.name), trait.name, self.name)
results = g.db.execute(query).fetchall()
return results
@@ -476,7 +490,7 @@ class MrnaAssayDataSet(DataSet):
# Todo: Obsolete or rename this field
self.type = 'ProbeSet'
- self.query = '''
+ self.query_for_group = '''
SELECT
InbredSet.Name, InbredSet.Id
FROM
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py
index 69602748..403f1b5e 100644
--- a/wqflask/wqflask/do_search.py
+++ b/wqflask/wqflask/do_search.py
@@ -177,9 +177,6 @@ class PhenotypeSearch(DoSearch):
from_clause = self.normalize_spaces(from_clause)
- #Get group information for dataset
- self.dataset.get_group()
-
query = (self.base_query +
"""%s
WHERE %s
@@ -189,7 +186,7 @@ class PhenotypeSearch(DoSearch):
PublishFreeze.Id = %s""" % (
from_clause,
where_clause,
- escape(str(self.dataset.group_id)),
+ escape(str(self.dataset.group.id)),
escape(str(self.dataset.id))))
print("query is:", pf(query))
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index b518ab99..5cb8e314 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -4,13 +4,6 @@ from wqflask import app
from flask import render_template
-###################################################
-# #
-# This file uses only spaces for indentation #
-# #
-###################################################
-
-#import string
import os
import cPickle
import re
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index cd61d70c..d1c60877 100755
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -32,13 +32,16 @@ from pprint import pformat as pf
-class ShowTrait(templatePage):
+class ShowTrait(object):
def __init__(self, args):
print("in ShowTrait, args are:", args)
#self.group = args.group
self.trait_id = args['trait_id']
+
self.dataset = create_dataset(args['dataset'])
+
+ #self.dataset = create_dataset(args['dataset'])
self.cell_id = None
#assert self.openMysql(), "No database!"
@@ -817,7 +820,7 @@ class ShowTrait(templatePage):
# ))
pass
- menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1")
+ #menuTable = HT.TableLite(cellpadding=2, Class="collap", width="150", id="target1")
#menuTable.append(HT.TR(HT.TD(addSelectionButton, align="center"),HT.TD(updateButton, align="center"), colspan=3, height=50, style="vertical-align:bottom;"))
#menuTable.append(HT.TR(HT.TD(addSelectionText, align="center"),HT.TD(updateText, align="center"), colspan=3, height=50, style="vertical-align:bottom;"))
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee
index 6e22119f..3d9fcd5a 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.coffee
+++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee
@@ -23,15 +23,15 @@ $ ->
id = "#" + process_id(category, value_type)
console.log("the_id:", id)
in_box = $(id).html
-
+
current_value = parseFloat($(in_box)).toFixed(decimal_places)
-
+
console.log("urgh:", category, value_type)
the_value = sample_sets[category][value_type]()
console.log("After running sample_sets, the_value is:", the_value)
if decimal_places > 0
the_value = the_value.toFixed(decimal_places)
-
+
console.log("*-* the_value:", the_value)
console.log("*-* current_value:", current_value)
if the_value != current_value
@@ -40,16 +40,16 @@ $ ->
update_stat_values = (sample_sets)->
for category in ['samples_primary', 'samples_other', 'samples_all']
change_stats_value(sample_sets, category, "n_of_samples", 0)
- for stat in ["mean", "median", "std_dev", "std_error"]
+ for stat in ["mean", "median", "std_dev", "std_error", "min", "max"]
console.log("Calling change_stats_value")
change_stats_value(sample_sets, category, stat, 2)
- edit_data_change = ->
+ edit_data_change = ->
sample_sets =
samples_primary: new Stats([])
samples_other: new Stats([])
samples_all: new Stats([])
-
+
console.log("at beginning:", sample_sets)
# ##########
@@ -114,6 +114,14 @@ $ ->
{
vn: "std_dev"
pretty: "Standard Deviation (SD)"
+ },
+ {
+ vn: "min"
+ pretty: "Minimum"
+ },
+ {
+ vn: "max"
+ pretty: "Maximum"
}
]
@@ -150,8 +158,8 @@ $ ->
processed += "-"
processed += value
return processed
-
-
+
+
show_hide_outliers = ->
console.log("FOOBAR in beginning of show_hide_outliers")
label = $('#show_hide_outliers').val()
@@ -163,10 +171,10 @@ $ ->
$('#show_hide_outliers').val("Hide Outliers")
console.log("Should be now Hide Outliers")
-
+
##Calculate Correlations Code
-
-
+
+
on_corr_method_change = ->
console.log("in beginning of on_corr_method_change")
corr_method = $('select[name=corr_method]').val()
@@ -179,15 +187,15 @@ $ ->
$("#corr_sample_method_options").show()
$('select[name=corr_method]').change(on_corr_method_change)
-
-
+
+
##End Calculate Correlations Code
-
+
##Populate Samples Attribute Values Code
-
+
create_value_dropdown = (value) ->
return """<option val=#{value}>#{value}</option>"""
-
+
populate_sample_attributes_values_dropdown = ->
console.log("in beginning of psavd")
$('#attribute_values').empty()
@@ -205,14 +213,14 @@ $ ->
if js_data.attribute_names.length > 0
populate_sample_attributes_values_dropdown()
$('#exclude_menu').change(populate_sample_attributes_values_dropdown)
-
+
##End Populate Samples Attribute Values Codess
##Block Samples By Attribute Value Code
block_by_attribute_value = ->
attribute_name = $('#exclude_menu').val()
exclude_by_value = $('#attribute_values').val()
-
+
cell_class = ".column_name-#{attribute_name}"
$(cell_class).each (index, element) =>
if $.trim($(element).text()) == exclude_by_value
@@ -220,11 +228,11 @@ $ ->
$(row).find(".trait_value_input").val("x")
$('#exclude_group').click(block_by_attribute_value)
-
+
##End Block Samples By Attribute Value Code
-
+
##Block Samples By Index Code
-
+
block_by_index = ->
index_string = $('#remove_samples_field').val()
index_list = []
@@ -241,7 +249,7 @@ $ ->
index = parseInt(index_set)
console.log("index:", index)
index_list.push(index)
- #catch(erro)
+ #catch(erro)
# alert("Syntax error")
console.log("index_list:", index_list)
for index in index_list
@@ -251,33 +259,33 @@ $ ->
$('#Primary_'+index.toString()).find('.trait_value_input').val("x")
else if $('#block_group').val() == "other"
console.log("block_group:", $('#block_group').val())
- console.log("row:", $('#Other_'+index.toString()))
+ console.log("row:", $('#Other_'+index.toString()))
$('#Other_'+index.toString()).find('.trait_value_input').val("x")
-
+
$('#block_by_index').click(block_by_index)
##End Block Samples By Index Code
-
+
##Hide Sample Rows With No Value (value of 'x') Code
-
+
hide_no_value = ->
$('.value_se').each (_index, element) =>
if $(element).find('.trait_value_input').val() == 'x'
$(element).hide()
-
+
$('#hide_no_value').click(hide_no_value)
##End Hide Sample Rows With No Value Code
-
+
##Block Outliers Code
block_outliers = ->
$('.outlier').each (_index, element) =>
$(element).find('.trait_value_input').val('x')
-
+
$('#block_outliers').click(block_outliers)
-
+
##End Block Outliers Code
-
+
##Reset Table Values Code
reset_samples_table = ->
$('.trait_value_input').each (_index, element) =>
@@ -289,9 +297,9 @@ $ ->
$('#reset').click(reset_samples_table)
##End Reset Table Values Code
-
+
##Get Sample Data From Table Code
-
+
get_sample_table_data = ->
samples = {}
primary_samples = []
@@ -315,27 +323,27 @@ $ ->
##End Get Sample Data from Table Code
##Export Sample Table Data Code
-
+
export_sample_table_data = ->
sample_data = get_sample_table_data()
console.log("sample_data is:", sample_data)
json_sample_data = JSON.stringify(sample_data)
console.log("json_sample_data is:", json_sample_data)
-
+
$('input[name=export_data]').val(json_sample_data)
console.log("export_data is", $('input[name=export_data]').val())
-
+
format = $('#export_format').val()
if format == "excel"
$('#trait_data_form').attr('action', '/export_trait_excel')
else
$('#trait_data_form').attr('action', '/export_trait_csv')
console.log("action is:", $('#trait_data_form').attr('action'))
-
+
$('#trait_data_form').submit()
$('#export').click(export_sample_table_data)
-
+
##End Export Sample Table Data Code
@@ -344,7 +352,7 @@ $ ->
console.log("after registering block_outliers")
_.mixin(_.str.exports()); # Add string fuctions directly to underscore
- $('#value_table').change(edit_data_change)
+ $('#edit_sample_lists').change(edit_data_change)
console.log("loaded")
#console.log("basic_table is:", basic_table)
# Add back following two lines later
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 919bc766..84282aef 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -53,7 +53,7 @@
change_stats_value(sample_sets, category, "n_of_samples", 0);
_results.push((function() {
var _j, _len1, _ref1, _results1;
- _ref1 = ["mean", "median", "std_dev", "std_error"];
+ _ref1 = ["mean", "median", "std_dev", "std_error", "min", "max"];
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
stat = _ref1[_j];
@@ -126,6 +126,12 @@
}, {
vn: "std_dev",
pretty: "Standard Deviation (SD)"
+ }, {
+ vn: "min",
+ pretty: "Minimum"
+ }, {
+ vn: "max",
+ pretty: "Maximum"
}
];
console.log("rows are:", rows);
@@ -362,7 +368,7 @@
$('#block_outliers').click(block_outliers);
console.log("after registering block_outliers");
_.mixin(_.str.exports());
- $('#value_table').change(edit_data_change);
+ $('#edit_sample_lists').change(edit_data_change);
console.log("loaded");
make_table();
edit_data_change();
diff --git a/wqflask/wqflask/static/new/javascript/stats.coffee b/wqflask/wqflask/static/new/javascript/stats.coffee
index 677dc258..118ee7a8 100644
--- a/wqflask/wqflask/static/new/javascript/stats.coffee
+++ b/wqflask/wqflask/static/new/javascript/stats.coffee
@@ -1,20 +1,20 @@
class Stats
constructor: (@the_values) ->
-
+
add_value: (value) ->
@the_values.push(value)
-
+
n_of_samples: ->
return @the_values.length
-
+
sum: ->
total = 0
total += value for value in @the_values
return total
-
+
mean: ->
return @sum() / @n_of_samples()
-
+
median: ->
is_odd = @the_values.length % 2
median_position = Math.floor(@the_values.length / 2)
@@ -24,7 +24,7 @@ class Stats
else
return (the_values_sorted[median_position] +
the_values_sorted[median_position - 1]) / 2
-
+
std_dev: ->
sum = 0
for value in @the_values
@@ -32,15 +32,22 @@ class Stats
sum += step_a
step_b = sum / @the_values.length
return Math.sqrt(step_b)
-
+
std_error: ->
return @std_dev() / Math.sqrt(@n_of_samples())
+ min: ->
+ return Math.min(@the_values...)
+
+ max: ->
+ return Math.max(@the_values...)
+
bxd_only = new Stats([3, 5, 7, 8])
-console.log("[red] bxd_only mean:", bxd_only.mean())
-console.log("[green] bxd_only median:", bxd_only.median())
-console.log("[purple] bxd_only std_dev:", bxd_only.std_dev())
-console.log("[magenta] bxd_only std_error:", bxd_only.std_error())
+console.log("[xred] bxd_only mean:", bxd_only.mean())
+console.log("[xgreen] bxd_only median:", bxd_only.median())
+console.log("[xpurple] bxd_only std_dev:", bxd_only.std_dev())
+console.log("[xmagenta] bxd_only std_error:", bxd_only.std_error())
+console.log("[xyellow] bxd_only min:", bxd_only.min())
-window.Stats = Stats \ No newline at end of file
+window.Stats = Stats
diff --git a/wqflask/wqflask/static/new/javascript/stats.js b/wqflask/wqflask/static/new/javascript/stats.js
index f95d03d4..620f7d5d 100644
--- a/wqflask/wqflask/static/new/javascript/stats.js
+++ b/wqflask/wqflask/static/new/javascript/stats.js
@@ -62,19 +62,29 @@
return this.std_dev() / Math.sqrt(this.n_of_samples());
};
+ Stats.prototype.min = function() {
+ return Math.min.apply(Math, this.the_values);
+ };
+
+ Stats.prototype.max = function() {
+ return Math.max.apply(Math, this.the_values);
+ };
+
return Stats;
})();
bxd_only = new Stats([3, 5, 7, 8]);
- console.log("[red] bxd_only mean:", bxd_only.mean());
+ console.log("[xred] bxd_only mean:", bxd_only.mean());
+
+ console.log("[xgreen] bxd_only median:", bxd_only.median());
- console.log("[green] bxd_only median:", bxd_only.median());
+ console.log("[xpurple] bxd_only std_dev:", bxd_only.std_dev());
- console.log("[purple] bxd_only std_dev:", bxd_only.std_dev());
+ console.log("[xmagenta] bxd_only std_error:", bxd_only.std_error());
- console.log("[magenta] bxd_only std_error:", bxd_only.std_error());
+ console.log("[xyellow] bxd_only min:", bxd_only.min());
window.Stats = Stats;
diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html
index 35ff4e8e..11f68bba 100644
--- a/wqflask/wqflask/templates/search_result_page.html
+++ b/wqflask/wqflask/templates/search_result_page.html
@@ -51,9 +51,9 @@
</TD>
<TD>
<a href="{{ url_for('show_trait_page',
- dataset = dataset.name,
trait_id = this_trait.name,
- group = dataset.group)}}">
+ dataset = dataset.name
+ )}}">
{{ this_trait.name }}
</a>
</TD>
diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html
index 163be69c..28341186 100644
--- a/wqflask/wqflask/templates/show_trait.html
+++ b/wqflask/wqflask/templates/show_trait.html
@@ -18,7 +18,7 @@
<div class="container">
<div class="page-header">
- <h1>{{ this_trait.species.capitalize() }} -
+ <h1>{{ dataset.group.species.capitalize() }} -
{{ dataset.group.name }} -
{{ this_trait.symbol }}
</h1>
diff --git a/wqflask/wqflask/templates/show_trait_details.html b/wqflask/wqflask/templates/show_trait_details.html
index e45886b4..e04fdd66 100644
--- a/wqflask/wqflask/templates/show_trait_details.html
+++ b/wqflask/wqflask/templates/show_trait_details.html
@@ -8,7 +8,7 @@
<dt>Database</dt>
<dd>
<a href="{{ this_trait.database.url }}" target="_blank">
- {{ this_trait.database.name }}
+ {{ dataset.name }}
</a>
</dd>
diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html
index 6c9b1073..9023b34d 100644
--- a/wqflask/wqflask/templates/show_trait_edit_data.html
+++ b/wqflask/wqflask/templates/show_trait_edit_data.html
@@ -77,7 +77,7 @@
<table id="stats_table" class="table table-hover"></table>
</div>
- <div>
+ <div id="edit_sample_lists">
{% for sample_type in sample_groups %}
<div>
<h3>{{ sample_type.header }}</h3>