aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2020-11-24 16:14:20 -0600
committerzsloan2020-11-24 16:14:20 -0600
commit77dc4a4e7c68a10f9b7d743e02a0738cab870c68 (patch)
tree59a15ba30b62c8ee3eaca8c5aea3b0f6d5c09435 /wqflask
parentbe315778db1d34f903312b5ac6bcc80dd848a5be (diff)
downloadgenenetwork2-77dc4a4e7c68a10f9b7d743e02a0738cab870c68.tar.gz
- Fixed the "Block by Attribute Value" feature
- Changed the "Block by Attribute Value" feature and the "Filter by Value" feature to only work on columns that are numeric or have a small number of distinct values (respectively)
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js117
-rw-r--r--wqflask/wqflask/templates/show_trait_transform_and_filter.html56
2 files changed, 123 insertions, 50 deletions
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 3df8784e..87c35984 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -568,14 +568,29 @@ create_value_dropdown = function(value) {
populate_sample_attributes_values_dropdown = function() {
var attribute_info, key, sample_attributes, selected_attribute, value, _i, _len, _ref, _ref1, _results;
$('#attribute_values').empty();
- sample_attributes = {};
- attr_keys = Object.keys(js_data.attributes).sort();
- for (i=0; i < attr_keys.length; i++) {
- attribute_info = js_data.attributes[attr_keys[i]];
- sample_attributes[attribute_info.name] = attribute_info.distinct_values;
- }
- selected_attribute = $('#exclude_menu').val().replace("_", " ");
- _ref1 = sample_attributes[selected_attribute];
+ sample_attributes = [];
+
+ var attributes_as_list = Object.keys(js_data.attributes).map(function(key) {
+ return [key, js_data.attributes[key].name];
+ });
+
+ attributes_as_list.sort(function(first, second) {
+ if (second[1] > first[1]){
+ return -1
+ }
+ if (first[1] > second[1]){
+ return 1
+ }
+ return 0
+ });
+
+ for (i=0; i < attributes_as_list.length; i++) {
+ attribute_info = js_data.attributes[attributes_as_list[i][0]]
+ sample_attributes.push(attribute_info.distinct_values);
+ }
+
+ selected_attribute = $('#exclude_column').val()
+ _ref1 = sample_attributes[selected_attribute - 1];
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
value = _ref1[_i];
@@ -590,23 +605,35 @@ if (Object.keys(js_data.attributes).length){
populate_sample_attributes_values_dropdown();
}
-$('#exclude_menu').change(populate_sample_attributes_values_dropdown);
+$('#exclude_column').change(populate_sample_attributes_values_dropdown);
block_by_attribute_value = function() {
var attribute_name, cell_class, exclude_by_value;
- attribute_name = $('#exclude_menu').val();
+
+ let exclude_group = $('#exclude_by_attr_group').val();
+ let exclude_column = $('#exclude_column').val();
+
+ if (exclude_group === "other") {
+ var table_api = $('#samples_other').DataTable();
+ } else {
+ var table_api = $('#samples_primary').DataTable();
+ }
+
exclude_by_value = $('#attribute_values').val();
- cell_class = ".column_name-" + attribute_name;
- return $(cell_class).each((function(_this) {
- return function(index, element) {
- var row;
- if ($.trim($(element).text()) === exclude_by_value) {
- row = $(element).parent('tr');
- return $(row).find(".trait-value-input").val("x");
- }
- };
- })(this));
+
+ let val_nodes = table_api.column(3).nodes().to$();
+ let exclude_val_nodes = table_api.column(attribute_start_pos + parseInt(exclude_column)).nodes().to$();
+
+ for (i = 0; i < exclude_val_nodes.length; i++) {
+ let this_col_value = exclude_val_nodes[i].childNodes[0].data;
+ let this_val_node = val_nodes[i].childNodes[0];
+
+ if (this_col_value == exclude_by_value){
+ this_val_node.value = "x";
+ }
+ }
};
-$('#exclude_group').click(block_by_attribute_value);
+$('#exclude_by_attr').click(block_by_attribute_value);
+
block_by_index = function() {
var end_index, error, index, index_list, index_set, index_string, start_index, _i, _j, _k, _len, _len1, _ref;
index_string = $('#remove_samples_field').val();
@@ -647,37 +674,57 @@ block_by_index = function() {
filter_by_value = function() {
let filter_logic = $('#filter_logic').val();
+ let filter_column = $('#filter_column').val();
let filter_value = $('#filter_value').val();
+ let block_group = $('#filter_group').val();
- block_group = $('#filter_group').val();
if (block_group === "other") {
- table_api = $('#samples_other').DataTable();
+ var table_api = $('#samples_other').DataTable();
} else {
- table_api = $('#samples_primary').DataTable();
+ var table_api = $('#samples_primary').DataTable();
}
let val_nodes = table_api.column(3).nodes().to$();
- for (i = 0; i < val_nodes.length; i++) {
- let this_node = val_nodes[i].childNodes[0];
- if(!isNaN(this_node.value) && !isNaN(filter_value)) {
+ if (filter_column == "value"){
+ var filter_val_nodes = table_api.column(3).nodes().to$();
+ }
+ else if (filter_column == "stderr"){
+ var filter_val_nodes = table_api.column(5).nodes().to$();
+ }
+ else if (!isNaN(filter_column)){
+ var filter_val_nodes = table_api.column(attribute_start_pos + parseInt(filter_column)).nodes().to$();
+ }
+ else {
+ return false
+ }
+
+ for (i = 0; i < filter_val_nodes.length; i++) {
+ if (filter_column == "value" || filter_column == "stderr"){
+ var this_col_value = filter_val_nodes[i].childNodes[0].value;
+ } else {
+ var this_col_value = filter_val_nodes[i].childNodes[0].data;
+ }
+ let this_val_node = val_nodes[i].childNodes[0];
+
+ if(!isNaN(this_col_value) && !isNaN(filter_value)) {
if (filter_logic == "greater_than"){
- if (parseFloat(this_node.value) <= parseFloat(filter_value)){
- this_node.value = "x";
+ if (parseFloat(this_col_value) <= parseFloat(filter_value)){
+ this_val_node.value = "x";
}
}
else if (filter_logic == "less_than"){
- if (parseFloat(this_node.value) >= parseFloat(filter_value)){
- this_node.value = "x";
+ if (parseFloat(this_col_value) >= parseFloat(filter_value)){
+ this_val_node.value = "x";
}
}
else if (filter_logic == "greater_or_equal"){
- if (parseFloat(this_node.value) < parseFloat(filter_value)){
- this_node.value = "x";
+ if (parseFloat(this_col_value) < parseFloat(filter_value)){
+ this_val_node.value = "x";
}
}
else if (filter_logic == "less_or_equal"){
- if (parseFloat(this_node.value) > parseFloat(filter_value)){
- this_node.value = "x";
+ if (parseFloat(this_col_value) > parseFloat(filter_value)){
+ this_val_node.value = "x";
}
}
}
diff --git a/wqflask/wqflask/templates/show_trait_transform_and_filter.html b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
index 22c52d8c..d7eac378 100644
--- a/wqflask/wqflask/templates/show_trait_transform_and_filter.html
+++ b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
@@ -20,8 +20,48 @@
<div id="remove_samples_invalid" class="alert alert-error" style="display:none;">
Please check that your input is formatted correctly, e.g. <strong>3, 5-10, 12</strong>
</div>
+ {% if sample_groups[0].attributes %}
+ <div class="input-append block-div-2">
+ <label for="exclude_column">Block samples by group:</label>
+ <select id="exclude_column" size=1>
+ {% for attribute in sample_groups[0].attributes %}
+ {% if sample_groups[0].attributes[attribute].distinct_values|length <= 10 %}
+ <option value="{{ loop.index }}">
+ {{ sample_groups[0].attributes[attribute].name }}
+ </option>
+ {% endif %}
+ {% endfor %}
+ </select>
+ <select id="attribute_values" size=1>
+ </select>
+ <select id="exclude_by_attr_group" size="1">
+ <option value="primary">
+ {{ sample_group_types['samples_primary'] }}
+ </option>
+ <option value="other">
+ {{ sample_group_types['samples_other'] }}
+ </option>
+ </select>
+ <input type="button" id="exclude_by_attr" class="btn btn-danger" value="Block">
+ </div>
+ {% endif %}
<div id="filterMenuSpan" class="input-append block-div-2">
- <label for="filter_samples_field">Filter samples by value </label>
+ <label for="filter_samples_field">Filter samples by {% if not sample_groups[0].attributes %}value{% endif %} </label>
+ {% if sample_groups[0].attributes %}
+ <select id="filter_column">
+ <option value="value">Value</option>
+ {% if js_data.se_exists %}
+ <option value="stderr">SE</option>
+ {% endif %}
+ {% for attribute in sample_groups[0].attributes %}
+
+ <option value="{{ loop.index }}">
+ {{ sample_groups[0].attributes[attribute].name }}
+ </option>
+
+ {% endfor %}
+ </select>
+ {% endif %}
<select id="filter_logic" size="1">
<option value="greater_than">></option>
<option value="less_than"><</option>
@@ -39,20 +79,6 @@
</select>
<input type="button" id="filter_by_value" class="btn btn-danger" value="Filter">
</div>
- {% if sample_groups[0].attributes %}
- <div class="input-append block-div-2">
- <label for="exclude_menu">Block samples by group:</label>
- <select id="exclude_menu" size=1>
- {% for attribute in sample_groups[0].attributes %}
- <option value="{{ sample_groups[0].attributes[attribute].name.replace(' ', '_') }}">
- {{ sample_groups[0].attributes[attribute].name }}</option>
- {% endfor %}
- </select>
- <select id="attribute_values" size=1>
- </select>
- <input type="button" id="exclude_group" class="btn" value="Block">
- </div>
- {% endif %}
<div>
<input type="button" id="hide_no_value" class="btn btn-default" value="Hide No Value">
<input type="button" id="block_outliers" class="btn btn-default" value="Block Outliers">