aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2020-12-01 22:42:44 -0600
committerGitHub2020-12-01 22:42:44 -0600
commit3a9c4bf295d0d2b4aafda0d816c5052bebd2f94a (patch)
tree4909047b7593d00706a0dba691eafaa4b67456fa
parent5943d5b81c4376d2063d9b1ba014dae919005868 (diff)
parent77dc4a4e7c68a10f9b7d743e02a0738cab870c68 (diff)
downloadgenenetwork2-3a9c4bf295d0d2b4aafda0d816c5052bebd2f94a.tar.gz
Merge pull request #490 from zsloan/feature/filter_samples_by_value
Feature/filter samples by value
-rw-r--r--wqflask/wqflask/static/new/css/show_trait.css4
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js138
-rw-r--r--wqflask/wqflask/templates/show_trait_transform_and_filter.html59
3 files changed, 169 insertions, 32 deletions
diff --git a/wqflask/wqflask/static/new/css/show_trait.css b/wqflask/wqflask/static/new/css/show_trait.css
index 5e1a279b..39c6ba53 100644
--- a/wqflask/wqflask/static/new/css/show_trait.css
+++ b/wqflask/wqflask/static/new/css/show_trait.css
@@ -145,11 +145,11 @@ input.corr-location {
display: inline;
}
-div.block-by-index-div {
+div.block-div {
margin-bottom: 10px;
}
-div.block-by-attribute-div {
+div.block-div-2 {
margin-top:10px;
margin-bottom:10px;
}
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index a34811f8..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,25 +605,37 @@ 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, _results;
+ 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();
index_list = [];
_ref = index_string.split(",");
@@ -630,7 +657,7 @@ block_by_index = function() {
index_list.push(index);
}
}
- _results = [];
+
let block_group = $('#block_group').val();
if (block_group === "other") {
table_api = $('#samples_other').DataTable();
@@ -645,6 +672,65 @@ 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();
+
+ if (block_group === "other") {
+ var table_api = $('#samples_other').DataTable();
+ } else {
+ var table_api = $('#samples_primary').DataTable();
+ }
+
+ let val_nodes = table_api.column(3).nodes().to$();
+ 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_col_value) <= parseFloat(filter_value)){
+ this_val_node.value = "x";
+ }
+ }
+ else if (filter_logic == "less_than"){
+ if (parseFloat(this_col_value) >= parseFloat(filter_value)){
+ this_val_node.value = "x";
+ }
+ }
+ else if (filter_logic == "greater_or_equal"){
+ if (parseFloat(this_col_value) < parseFloat(filter_value)){
+ this_val_node.value = "x";
+ }
+ }
+ else if (filter_logic == "less_or_equal"){
+ if (parseFloat(this_col_value) > parseFloat(filter_value)){
+ this_val_node.value = "x";
+ }
+ }
+ }
+ }
+};
+
hide_no_value = function() {
return $('.value_se').each((function(_this) {
return function(_index, element) {
@@ -1528,6 +1614,12 @@ $('#block_by_index').click(function(){
block_by_index();
edit_data_change();
});
+
+$('#filter_by_value').click(function(){
+ filter_by_value();
+ edit_data_change();
+})
+
$('#exclude_group').click(edit_data_change);
$('#block_outliers').click(edit_data_change);
$('#reset').click(edit_data_change);
diff --git a/wqflask/wqflask/templates/show_trait_transform_and_filter.html b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
index 0418d972..d7eac378 100644
--- a/wqflask/wqflask/templates/show_trait_transform_and_filter.html
+++ b/wqflask/wqflask/templates/show_trait_transform_and_filter.html
@@ -4,7 +4,7 @@
<strong>Reset</strong> option as
needed.
</p>
- <div id="blockMenuSpan" class="input-append block-by-index-div">
+ <div id="blockMenuSpan" class="input-append block-div">
<label for="remove_samples_field">Block samples by index:</label>
<input type="text" id="remove_samples_field" placeholder="Example: 3, 5-10, 12">
<select id="block_group" size="1">
@@ -21,19 +21,64 @@
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-by-attribute-div">
- <label for="exclude_menu">Block samples by group:</label>
- <select id="exclude_menu" size=1>
+ <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 %}
- <option value="{{ sample_groups[0].attributes[attribute].name.replace(' ', '_') }}">
- {{ sample_groups[0].attributes[attribute].name }}</option>
+ {% 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>
- <input type="button" id="exclude_group" class="btn" value="Block">
+ <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 {% 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>
+ <option value="greater_or_equal">≥</option>
+ <option value="less_or_equal">≤</option>
+ </select>
+ <input type="text" id="filter_value" placeholder="Example: 3, 10, 15">
+ <select id="filter_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="filter_by_value" class="btn btn-danger" value="Filter">
+ </div>
<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">