diff options
author | zsloan | 2020-02-14 13:16:26 -0600 |
---|---|---|
committer | zsloan | 2020-02-14 13:16:26 -0600 |
commit | 2c435fd252026e7c719810a2423f66c246fdae67 (patch) | |
tree | 13ec062420b7e176e4d1fa7bf9f1ef3ae35938d6 /wqflask | |
parent | a7a0d268095a06c66233a5dc08461d66db5f14b7 (diff) | |
download | genenetwork2-2c435fd252026e7c719810a2423f66c246fdae67.tar.gz |
Added log10 transform and add +1 when there are values between 0 and 1 for both log transforms
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/static/new/javascript/show_trait.js | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 7fb718cd..96b7c305 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -632,13 +632,16 @@ $('.reset').click(function() { edit_data_change(); }); -log_normalize_data = function() { +log2_normalize_data = function(zero_to_one_vals_exist) { return $('.trait_value_input').each((function(_this) { return function(_index, element) { - current_value = parseFloat($(element).data("value")) + 1; + current_value = $(element).data("value") if(isNaN(current_value)) { return current_value } else { + if (zero_to_one_vals_exist){ + current_value = parseFloat(current_value) + 1; + } $(element).val(Math.log2(current_value).toFixed(3)); return Math.log2(current_value).toFixed(3) } @@ -646,6 +649,24 @@ log_normalize_data = function() { })(this)); }; +log10_normalize_data = function(zero_to_one_vals_exist) { + return $('.trait_value_input').each((function(_this) { + return function(_index, element) { + current_value = $(element).data("value") + if(isNaN(current_value)) { + return current_value + } else { + if (zero_to_one_vals_exist){ + current_value = parseFloat(current_value) + 1; + } + $(element).val(Math.log10(current_value).toFixed(3)); + return Math.log10(current_value).toFixed(3) + } + }; + })(this)); +}; + + sqrt_normalize_data = function() { return $('.edit_sample_value').each((function(_this) { return function(_index, element) { @@ -703,12 +724,36 @@ zscore_data = function() { })(this)); }; +check_for_zero_to_one_vals = function() { + zero_to_one_vals_exist = false + $('.trait_value_input').each(function() { + current_value = $(this).data("value") + if(isNaN(current_value)) { + return; + } else { + current_value = parseFloat(current_value) + if (0 < current_value && current_value < 1){ + zero_to_one_vals_exist = true + return false; + } + } + }); + return zero_to_one_vals_exist +} + normalize_data = function() { - if ($('#norm_method option:selected').val() == 'log2'){ - if ($('input[name="transform"]').val() != "log2") { - log_normalize_data() + if ($('#norm_method option:selected').val() == 'log2' || $('#norm_method option:selected').val() == 'log10'){ + zero_to_one_vals_exist = check_for_zero_to_one_vals(); + if ($('input[name="transform"]').val() != "log2" && $('#norm_method option:selected').val() == 'log2') { + log2_normalize_data(zero_to_one_vals_exist) $('input[name="transform"]').val("log2") $('span[name="transform_text"]').text(" - log2 transformed") + } else { + if ($('input[name="transform"]').val() != "log10" && $('#norm_method option:selected').val() == 'log10'){ + log10_normalize_data(zero_to_one_vals_exist) + $('input[name="transform"]').val("log10") + $('span[name="transform_text"]').text(" - log10 transformed") + } } } else if ($('#norm_method option:selected').val() == 'sqrt'){ |