aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2020-10-28 11:46:11 -0500
committerzsloan2020-10-28 11:46:11 -0500
commit48dabdace3ceeae9372269694f3b3d41ab16cab8 (patch)
tree5438912b0fdcc4748d100fe4d754e47391404f62
parent4dac73ae7f3cabe037e44892a12600f0e4625ca5 (diff)
downloadgenenetwork2-48dabdace3ceeae9372269694f3b3d41ab16cab8.tar.gz
Fixed trait page export to work with Scroller + added metadata for non-Phenotype traits and column headers
* wqflask/wqflask/show_trait/export_trait_data.py - Added metadata for non-Phenotype traits and column headers (which didn't previously exist) * wqflask/wqflask/static/new/javascript/show_trait.js - Changed export_sample_table_data to use DataTables API instead of just selecting from the DOM with JQuery
-rw-r--r--wqflask/wqflask/show_trait/export_trait_data.py18
-rw-r--r--wqflask/wqflask/static/new/javascript/show_trait.js73
2 files changed, 72 insertions, 19 deletions
diff --git a/wqflask/wqflask/show_trait/export_trait_data.py b/wqflask/wqflask/show_trait/export_trait_data.py
index 48feb492..379b746c 100644
--- a/wqflask/wqflask/show_trait/export_trait_data.py
+++ b/wqflask/wqflask/show_trait/export_trait_data.py
@@ -14,10 +14,16 @@ def export_sample_table(targs):
final_sample_data = meta_data
+ column_headers = ["Name", "Value"]
+ if any(sample["se"] for sample in sample_data['primary_samples']):
+ column_headers.append("SE")
+ if any(sample["num_cases"] for sample in sample_data['primary_samples']):
+ column_headers.append("N")
+
+ final_sample_data.append(column_headers)
for sample_group in ['primary_samples', 'other_samples']:
for row in sample_data[sample_group]:
sorted_row = dict_to_sorted_list(row)
- print("sorted_row is:", pf(sorted_row))
final_sample_data.append(sorted_row)
return trait_name, final_sample_data
@@ -39,7 +45,15 @@ def get_export_metadata(trait_id, dataset_name):
metadata.append(["Title: " + (this_trait.title if this_trait.title else "N/A")])
metadata.append(["Journal: " + (this_trait.journal if this_trait.journal else "N/A")])
metadata.append(["Dataset Link: http://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&InfoPageName=" + dataset.name])
- metadata.append([])
+ else:
+ metadata.append(["Record ID: " + trait_id])
+ metadata.append(["Trait URL: " + "http://genenetwork.org/show_trait?trait_id=" + trait_id + "&dataset=" + dataset_name])
+ if this_trait.symbol:
+ metadata.append(["Symbol: " + this_trait.symbol])
+ metadata.append(["Dataset: " + dataset.name])
+ metadata.append(["Group: " + dataset.group.name])
+
+ metadata.append([])
return metadata
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 397adb52..a34811f8 100644
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -885,26 +885,65 @@ $('#qnorm').click(switch_qnorm_data);
get_sample_table_data = function(table_name) {
var samples;
samples = [];
- $('#' + table_name).find('.value_se').each((function(_this) {
- return function(_index, element) {
- var attribute_info, key, row_data, _ref;
- row_data = {};
- row_data.name = $.trim($(element).find('.column_name-Sample').text());
- row_data.value = $(element).find('.edit-sample-value:eq(0)').val();
- if ($(element).find('.edit-sample-se').length > 0) {
- row_data.se = $(element).find('.edit-sample-se').val();
+
+ var se_exists = false;
+ var n_exists = false;
+
+ if ($('#' + table_name).length){
+ table_api = $('#' + table).DataTable();
+ sample_vals = [];
+
+ name_nodes = table_api.column(2).nodes().to$();
+ val_nodes = table_api.column(3).nodes().to$();
+ if (js_data.se_exists){
+ var_nodes = table_api.column(5).nodes().to$();
+ if (js_data.has_num_cases) {
+ n_nodes = table_api.column(6).nodes().to$();
}
- if ($(element).find('.edit_sample_num_cases').length > 0) {
- row_data.num_cases = $(element).find('.edit_sample_num_cases').val();
+ } else {
+ if (js_data.has_num_cases){
+ n_nodes = table_api.column(4).nodes().to$();
}
- attr_keys = Object.keys(js_data.attributes).sort()
- for (i=0; i < attr_keys.length; i++) {
- attribute_info = js_data.attributes[attr_keys[i]];
- row_data[attribute_info.name] = $.trim($(element).find('.column_name-' + attribute_info.name.replace(" ", "_").replace("/", "\\/")).text());
+ }
+
+ for (_j = 0; _j < val_nodes.length; _j++){
+ sample_val = val_nodes[_j].childNodes[0].value
+ sample_name = $.trim(name_nodes[_j].childNodes[0].textContent)
+ if (is_number(sample_val) && sample_val !== "") {
+ sample_val = parseFloat(sample_val);
+ if (typeof var_nodes == 'undefined'){
+ sample_var = null;
+ } else {
+ sample_var = var_nodes[_j].childNodes[0].value;
+ if (is_number(sample_var)) {
+ sample_var = parseFloat(sample_var);
+ se_exists = true;
+ } else {
+ sample_var = null;
+ }
+ }
+ if (typeof n_nodes == 'undefined'){
+ sample_n = null;
+ } else {
+ sample_n = n_nodes[_j].childNodes[0].value;
+ if (is_number(sample_n)) {
+ n_exists = true;
+ sample_n = parseInt(sample_n);
+ } else {
+ sample_n = null;
+ }
+ }
+ row_dict = {
+ name: sample_name,
+ value: sample_val,
+ se: sample_var,
+ num_cases: sample_n
+ }
+ samples.push(row_dict)
}
- return samples.push(row_data);
- };
- })(this));
+ }
+ }
+
return samples;
};
export_sample_table_data = function() {