From ef38724c31567b56214026999a944f9088fe30b8 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Sun, 28 Jun 2020 11:23:27 -0500 Subject: make stains headers names horizontal --- wqflask/wqflask/templates/snp_browser.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index fb564b28..7019e943 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -195,7 +195,7 @@ {{ header }} {% endfor %} {% for strain in header_fields[1] %} - {% for letter in strain %}
{{ letter }}
{% endfor %} + {{ strain }} {% endfor %} {% else %} {% for header in header_fields %} -- cgit v1.2.3 From 88715630c4d18d962a7473dcac7e34b1b9c098a0 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Sun, 28 Jun 2020 11:24:12 -0500 Subject: add DataTables pagination --- wqflask/wqflask/templates/snp_browser.html | 1 - 1 file changed, 1 deletion(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 7019e943..3b97963c 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -407,7 +407,6 @@ {% endif %} 'order': [[1, "asc" ]], 'sDom': "rtip", - 'iDisplayLength': 500, 'processing': true, 'language': { 'loadingRecords': ' ', -- cgit v1.2.3 From 73e3f354b0bf6accfd884f0fab8ef93f03be7945 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Sun, 28 Jun 2020 11:28:28 -0500 Subject: fix typo in check_if_in_gene function while querying for species_id = 0 --- wqflask/wqflask/snp_browser/snp_browser.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/wqflask/wqflask/snp_browser/snp_browser.py b/wqflask/wqflask/snp_browser/snp_browser.py index 6c3fcf53..a2fb7195 100644 --- a/wqflask/wqflask/snp_browser/snp_browser.py +++ b/wqflask/wqflask/snp_browser/snp_browser.py @@ -526,7 +526,6 @@ class SnpBrowser(object): the_rows.append(this_row) return the_rows - def include_record(self, domain, function, snp_source, conservation_score): """ Decide whether to add this record """ @@ -868,8 +867,6 @@ def get_gene_id_name_dict(species_id, gene_name_list): if len(results) > 0: for item in results: gene_id_name_dict[item[1]] = item[0] - else: - pass return gene_id_name_dict @@ -883,7 +880,7 @@ def check_if_in_gene(species_id, chr, mb): query = """SELECT geneId,geneSymbol FROM GeneList WHERE chromosome = '{0}' AND - (txStart < {1} AND txEnd > {1}); """.format(species_id, chr, mb) + (txStart < {1} AND txEnd > {1}); """.format(chr, mb) result = g.db.execute(query).fetchone() -- cgit v1.2.3 From 429aff0920b1fddf71e4547c35a726b11e6713a0 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Tue, 30 Jun 2020 14:14:53 -0500 Subject: 500 rows per page for DataTables --- wqflask/wqflask/templates/snp_browser.html | 1 + 1 file changed, 1 insertion(+) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 3b97963c..7019e943 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -407,6 +407,7 @@ {% endif %} 'order': [[1, "asc" ]], 'sDom': "rtip", + 'iDisplayLength': 500, 'processing': true, 'language': { 'loadingRecords': ' ', -- cgit v1.2.3 From 776ccfbb2fc5a6e85c7a41efd92b33b0e27de68a Mon Sep 17 00:00:00 2001 From: uditgulati Date: Tue, 30 Jun 2020 14:56:22 -0500 Subject: reduce gap between first and second column in form --- wqflask/wqflask/templates/snp_browser.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 7019e943..73359835 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -15,7 +15,7 @@ -
+
@@ -74,7 +74,7 @@
-
+
@@ -108,7 +108,7 @@
-
+
-- cgit v1.2.3 From 3a792dbe74ab181d2fa9582f67c99b68ffad0c10 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Tue, 30 Jun 2020 15:38:04 -0500 Subject: align numeric data values to right, categorial values to center --- wqflask/wqflask/templates/snp_browser.html | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 73359835..816d5f0f 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -272,7 +272,8 @@ return '' } }, { - 'data': 'index' + 'data': 'index', + 'className': 'dt-body-right' }, { 'data': null, 'render': function(data, type, row, meta) { @@ -283,9 +284,11 @@ } } }, { - 'data': 'chr' + 'data': 'chr', + 'className': 'dt-body-center' }, { - 'data': 'mb_formatted' + 'data': 'mb_formatted', + 'className': 'dt-body-right' }, { 'data': 'alleles' }, {% if empty_columns['snp_source'] == "true" %}{ @@ -298,7 +301,8 @@ } } }, {% endif %} {% if empty_columns['conservation_score'] == "true" %}{ - 'data': 'conservation_score' + 'data': 'conservation_score', + 'className': 'dt-body-right' }, {% endif %} {% if empty_columns['gene_name'] == "true" %}{ 'data': null, 'render': function(data, type, row, meta) { @@ -383,21 +387,26 @@ return '' } }, { - 'data': 'index' + 'data': 'index', + 'className': 'dt-body-right' }, { 'data': 'indel_name' }, { 'data': 'indel_type' }, { - 'data': 'indel_chr' + 'data': 'indel_chr', + 'className': 'dt-body-center' }, { - 'data': 'indel_mb_s' + 'data': 'indel_mb_s', + 'className': 'dt-body-right' }, { - 'data': 'indel_mb_e' + 'data': 'indel_mb_e', + 'className': 'dt-body-right' }, { 'data': 'indel_strand' }, { - 'data': 'indel_size' + 'data': 'indel_size', + 'className': 'dt-body-right' }, { 'data': 'indel_sequence' }, { -- cgit v1.2.3 From f7b7950533f52e418c2be569cca409ae1fb3faf0 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Tue, 30 Jun 2020 16:48:02 -0500 Subject: rotate strain headers 270 deg --- wqflask/wqflask/templates/snp_browser.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 816d5f0f..36f893bc 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -195,7 +195,7 @@ {{ header }} {% endfor %} {% for strain in header_fields[1] %} - {{ strain }} + {% for letter in strain|reverse %}
{{ letter }}
{% endfor %} {% endfor %} {% else %} {% for header in header_fields %} -- cgit v1.2.3 From 7a4068d6d46d923c30316887e1d20f2fa6caa859 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Fri, 10 Jul 2020 10:15:22 -0500 Subject: add export to CSV button to export current page --- wqflask/wqflask/templates/snp_browser.html | 43 +++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 36f893bc..284b55c5 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -107,6 +107,12 @@
+
+ +
+ +
+
@@ -192,14 +198,14 @@ {% if header_fields|length == 2 %} {% for header in header_fields[0] %} - {{ header }} + {{ header }} {% endfor %} {% for strain in header_fields[1] %} - {% for letter in strain|reverse %}
{{ letter }}
{% endfor %} + {% for letter in strain|reverse %}
{{ letter }}
{% endfor %} {% endfor %} {% else %} {% for header in header_fields %} - {{ header }} + {{ header }} {% endfor %} {% endif %} @@ -518,6 +524,37 @@ }); $("input[name=chosen_strains]").val(strain_list.join(",")); }); + + $("input[name=export_csv]").click(function() { + var csv = []; + var rows = document.querySelectorAll("table tr"); + + var headers = []; + var col_header = rows[0].querySelectorAll("th"); + console.log(col_header.length); + for(var i = 1; i < col_header.length; i++) { + console.log(col_header[i].getAttribute("name")); + headers.push(col_header[i].getAttribute("name")); + } + csv.push(headers.join(",")); + + for (var i = 1; i < rows.length; i++) { + var row = [], cols = rows[i].querySelectorAll("td"); + + for (var j = 1; j < cols.length; j++) + row.push(cols[j].innerText); + + csv.push(row.join(",")); + } + + var csvFile = new Blob([csv.join("\n")], {type: "text/csv"}); + var downloadLink = document.createElement("a"); + downloadLink.download = "hello.csv"; + downloadLink.href = window.URL.createObjectURL(csvFile); + downloadLink.style.display = "none"; + document.body.appendChild(downloadLink); + downloadLink.click(); + }); {% endblock %} -- cgit v1.2.3 From f99b69155d35900a75c000fbb79f6bcfb3fa6ff1 Mon Sep 17 00:00:00 2001 From: uditgulati Date: Fri, 10 Jul 2020 10:30:04 -0500 Subject: export only checked rows to csv; update csv file name --- wqflask/wqflask/templates/snp_browser.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 284b55c5..83606804 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -531,25 +531,27 @@ var headers = []; var col_header = rows[0].querySelectorAll("th"); - console.log(col_header.length); for(var i = 1; i < col_header.length; i++) { - console.log(col_header[i].getAttribute("name")); headers.push(col_header[i].getAttribute("name")); } csv.push(headers.join(",")); for (var i = 1; i < rows.length; i++) { var row = [], cols = rows[i].querySelectorAll("td"); + var checkBox = rows[i].querySelector("input"); + console.log(checkBox); - for (var j = 1; j < cols.length; j++) - row.push(cols[j].innerText); + if(checkBox.checked == true) { + for (var j = 1; j < cols.length; j++) + row.push(cols[j].innerText); - csv.push(row.join(",")); + csv.push(row.join(",")); + } } var csvFile = new Blob([csv.join("\n")], {type: "text/csv"}); var downloadLink = document.createElement("a"); - downloadLink.download = "hello.csv"; + downloadLink.download = "variant_data.csv"; downloadLink.href = window.URL.createObjectURL(csvFile); downloadLink.style.display = "none"; document.body.appendChild(downloadLink); -- cgit v1.2.3 From 349b395375703e727465a1f05f4a5e2d4fc64d2a Mon Sep 17 00:00:00 2001 From: uditgulati Date: Sun, 19 Jul 2020 17:21:15 -0500 Subject: add server side processing due to large tables in DataTables; work on server-side processing API pending for sorting, paging etc --- wqflask/wqflask/snp_browser/snp_browser.py | 39 ++++++++++++++++++++++-------- wqflask/wqflask/templates/snp_browser.html | 26 +++++++++++++++----- wqflask/wqflask/views.py | 10 ++++++++ 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/wqflask/wqflask/snp_browser/snp_browser.py b/wqflask/wqflask/snp_browser/snp_browser.py index a2fb7195..9ae8892b 100644 --- a/wqflask/wqflask/snp_browser/snp_browser.py +++ b/wqflask/wqflask/snp_browser/snp_browser.py @@ -4,7 +4,7 @@ import string from PIL import (Image) from utility.logger import getLogger -logger = getLogger(__name__ ) +logger = getLogger(__name__) from base import species from base import webqtlConfig @@ -14,16 +14,16 @@ class SnpBrowser(object): def __init__(self, start_vars): self.strain_lists = get_browser_sample_lists() self.initialize_parameters(start_vars) - self.limit_number = 10000 if self.first_run == "false": self.filtered_results = self.get_browser_results() + self.table_rows = self.get_table_rows() + self.rows_count = len(self.table_rows) - if len(self.filtered_results) <= self.limit_number: - self.table_rows = self.get_table_rows() - else: - self.empty_columns = None - self.table_rows = [] + del self.filtered_results + + if 'sEcho' not in start_vars: + self.table_rows = self.table_rows[:500] if self.limit_strains == "true": self.header_fields, self.empty_field_count = get_header_list(variant_type = self.variant_type, strains = self.chosen_strains, empty_columns = self.empty_columns) @@ -380,7 +380,7 @@ class SnpBrowser(object): the_rows = [] for i, result in enumerate(self.filtered_results): - this_row = [] + this_row = {} if self.variant_type == "SNP": snp_name, rs, chr, mb, alleles, gene, transcript, exon, domain, function, function_details, snp_source, conservation_score, snp_id = result[:14] allele_value_list = result[14:] @@ -520,8 +520,6 @@ class SnpBrowser(object): "source_name": str(source_name) } #this_row = [indel_name, indel_chr, indel_mb_s, indel_mb_e, indel_strand, indel_type, indel_size, indel_sequence, source_name] - else: - this_row = {} the_rows.append(this_row) @@ -643,6 +641,27 @@ class SnpBrowser(object): #for i in range(n_click): # href = url_for('snp_browser', first_run="false", chosen_strains_mouse=self.chosen_strains_mouse, chosen_strains_rat=self.chosen_strains_rat, variant=self.variant_type, species=self.species_name, gene_name=self.gene_name, chr=self.chr, start_mb=self.start_mb, end_mb=self.end_mb, limit_strains=self.limit_strains, domain=self.domain, function=self.function, criteria=self.criteria, score=self.score, diff_alleles=self.diff_alleles) +class SnpPage(object): + + def __init__(self, start_vars): + self.snp_browser = SnpBrowser(start_vars) + # self.table_rows = self.filter_rows() + self.rows_count = self.snp_browser.rows_count + self.sEcho = start_vars['sEcho'] + + def filter_rows(self): + pass + + def get_page(self): + output = {} + output['sEcho'] = str(self.sEcho) + output['iTotalRecords'] = str(self.rows_count) + output['iTotalDisplayRecords'] = str(100) + # logger.info(len(self.table_rows), type(self.table_rows), self.table_rows[0]) + logger.info(self.snp_browser.rows_count, len(self.snp_browser.table_rows)) + output['data'] = self.snp_browser.table_rows[:100] + return output + def get_browser_sample_lists(species_id=1): strain_lists = {} mouse_strain_list = [] diff --git a/wqflask/wqflask/templates/snp_browser.html b/wqflask/wqflask/templates/snp_browser.html index 83606804..f3e928af 100644 --- a/wqflask/wqflask/templates/snp_browser.html +++ b/wqflask/wqflask/templates/snp_browser.html @@ -188,10 +188,7 @@
- {% if filtered_results is defined %} - {% if filtered_results|length > limit_number %} - There are more than 10000 results. Consider limiting your search to a smaller range. - {% else %} + {% if table_rows is defined %} @@ -214,7 +211,6 @@

Loading...
- {% endif %} {% endif %}
@@ -229,11 +225,23 @@