From 27a08a81107705f213d13fb7334a2b8eb4fd68d2 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 12 Feb 2019 13:20:18 -0600 Subject: Added GeneWeaver linkout Fixed some issues with sorting in various tables Changed header appearance for some pages Fixed bug where basic stats table would sometimes be duplicated or show up with empty fields --- wqflask/base/webqtlCaseData.py | 2 +- .../wqflask/external_tools/send_to_geneweaver.py | 93 +++++++++++++++++++++- wqflask/wqflask/show_trait/SampleList.py | 1 - .../static/new/javascript/search_results.js | 2 +- .../wqflask/static/new/javascript/show_trait.js | 18 +++-- wqflask/wqflask/templates/collections/list.html | 17 ++-- wqflask/wqflask/templates/collections/view.html | 21 ++--- wqflask/wqflask/templates/correlation_page.html | 10 ++- wqflask/wqflask/templates/geneweaver_page.html | 35 ++++++++ wqflask/wqflask/templates/gsearch_gene.html | 8 ++ wqflask/wqflask/templates/gsearch_pheno.html | 8 ++ wqflask/wqflask/templates/search_result_page.html | 16 ++++ wqflask/wqflask/views.py | 22 ++++- 13 files changed, 222 insertions(+), 31 deletions(-) create mode 100644 wqflask/wqflask/templates/geneweaver_page.html diff --git a/wqflask/base/webqtlCaseData.py b/wqflask/base/webqtlCaseData.py index 76f06cc6..aa34024c 100644 --- a/wqflask/base/webqtlCaseData.py +++ b/wqflask/base/webqtlCaseData.py @@ -49,7 +49,7 @@ class webqtlCaseData(object): if self.variance != None: str += " variance=%2.3f" % self.variance if self.num_cases: - str += " ndata=%d" % self.num_cases + str += " ndata=%s" % self.num_cases if self.name: str += " name=%s" % self.name if self.name2: diff --git a/wqflask/wqflask/external_tools/send_to_geneweaver.py b/wqflask/wqflask/external_tools/send_to_geneweaver.py index 956286af..7a5dba73 100644 --- a/wqflask/wqflask/external_tools/send_to_geneweaver.py +++ b/wqflask/wqflask/external_tools/send_to_geneweaver.py @@ -18,4 +18,95 @@ # # This module is used by GeneNetwork project (www.genenetwork.org) -from __future__ import absolute_import, print_function, division \ No newline at end of file +from __future__ import absolute_import, print_function, division + +import string + +from flask import Flask, g + +from base.trait import GeneralTrait, retrieve_trait_info +from base.species import TheSpecies +from utility import helper_functions, corr_result_helpers + +import utility.logger +logger = utility.logger.getLogger(__name__ ) + +class SendToGeneWeaver(object): + def __init__(self, start_vars): + trait_db_list = [trait.strip() for trait in start_vars['trait_list'].split(',')] + helper_functions.get_trait_db_obs(self, trait_db_list) + + self.chip_name = test_chip(self.trait_list) + self.wrong_input = "False" + if self.chip_name == "mixed" or self.chip_name == "not_microarray" or '_NA' in self.chip_name: + self.wrong_input = "True" + else: + species = self.trait_list[0][1].group.species + if species == "rat": + species_name = "Rattus norvegicus" + elif species == "human": + species_name = "Homo sapiens" + elif species == "mouse": + species_name = "Mus musculus" + else: + species_name = "" + + trait_name_list = get_trait_name_list(self.trait_list) + + self.hidden_vars = { + 'client' : "genenetwork", + 'species' : species_name, + 'idtype' : self.chip_name, + 'list' : string.join(trait_name_list, ","), + } + +def get_trait_name_list(trait_list): + name_list = [] + for trait_db in trait_list: + name_list.append(trait_db[0].name) + + return name_list + +def test_chip(trait_list): + final_chip_name = "" + + for trait_db in trait_list: + dataset = trait_db[1] + result = g.db.execute("""SELECT GeneChip.GO_tree_value + FROM GeneChip, ProbeFreeze, ProbeSetFreeze + WHERE GeneChip.Id = ProbeFreeze.ChipId and + ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and + ProbeSetFreeze.Name = '%s'""" % dataset.name).fetchone() + + if result: + chip_name = result[0] + if chip_name: + if chip_name != final_chip_name: + if final_chip_name: + return "mixed" + else: + final_chip_name = chip_name + else: + pass + else: + result = g.db.execute("""SELECT GeneChip.Name + FROM GeneChip, ProbeFreeze, ProbeSetFreeze + WHERE GeneChip.Id = ProbeFreeze.ChipId and + ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and + ProbeSetFreeze.Name = '%s'""" % dataset.name).fetchone() + chip_name = '%s_NA' % result[0] + return chip_name + else: + query = """SELECT GeneChip.Name + FROM GeneChip, ProbeFreeze, ProbeSetFreeze + WHERE GeneChip.Id = ProbeFreeze.ChipId and + ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and + ProbeSetFreeze.Name = '%s'""" % dataset.name + result = g.db.execute(query).fetchone() + if result == None: + return "not_microarray" + else: + chip_name = '%s_NA' % result[0] + return chip_name + + return chip_name \ No newline at end of file diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py index f2259b55..50d7b6c0 100644 --- a/wqflask/wqflask/show_trait/SampleList.py +++ b/wqflask/wqflask/show_trait/SampleList.py @@ -75,7 +75,6 @@ class SampleList(object): logger.debug("self.attributes is", pf(self.attributes)) self.do_outliers() - #do_outliers(the_samples) logger.debug("*the_samples are [%i]: %s" % (len(self.sample_list), pf(self.sample_list))) def __repr__(self): diff --git a/wqflask/wqflask/static/new/javascript/search_results.js b/wqflask/wqflask/static/new/javascript/search_results.js index 2277a157..ebb1651d 100644 --- a/wqflask/wqflask/static/new/javascript/search_results.js +++ b/wqflask/wqflask/static/new/javascript/search_results.js @@ -272,7 +272,7 @@ $(function() { return submit_special(url) }); - $("#send_to_webgestalt, #send_to_bnw").on("click", function() { + $("#send_to_webgestalt, #send_to_bnw, #send_to_geneweaver").on("click", function() { traits = $("#trait_table input:checked").map(function() { return $(this).val(); }).get(); diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 717d98b9..2f846642 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -342,7 +342,7 @@ if (!__hasProp.call(_ref1, key)) continue; value = _ref1[key]; the_id = process_id(key, row.vn); - row_line += "foo"; + row_line += "N/A"; } row_line += ""; the_rows += row_line; @@ -619,7 +619,7 @@ }; sqrt_normalize_data = function() { - return $('.trait_value_input').each((function(_this) { + return $('.edit_sample_value').each((function(_this) { return function(_index, element) { current_value = parseFloat($(element).data("value")) + 1; if(isNaN(current_value)) { @@ -633,7 +633,7 @@ }; qnorm_data = function() { - return $('.trait_value_input').each((function(_this) { + return $('.edit_sample_value').each((function(_this) { return function(_index, element) { current_value = parseFloat($(element).data("value")) + 1; if(isNaN(current_value)) { @@ -1164,9 +1164,17 @@ return redraw_prob_plot(); }); + function isEmpty( el ){ + return !$.trim(el.html()) + } + $('.stats_panel').click(function() { - make_table(); - edit_data_change(); + if (isEmpty($('#stats_table'))){ + make_table(); + edit_data_change(); + } else { + edit_data_change(); + } }); $('#edit_sample_lists').change(edit_data_change); $('.edit_sample_value').change(edit_data_change); diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index 83e74613..5372fa46 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -8,15 +8,16 @@ {% endblock %} {% block content %} - {% if g.user_session.logged_in %} - {{ header("Collections owned by {{ g.user_session.user_name }}", - 'You have {}.'.format(numify(collections|count, "collection", "collections"))) }} - {% else %} - {{ header("Your Collections", - 'You have {}.'.format(numify(collections|count, "collection", "collections"))) }} - {% endif %} -
+ {% if g.user_session.logged_in %} +

Collections owned by {{ g.user_session.user_name }}

+ {% else %} +

Your Collections

+ {% endif %} +

You have {{ '{}'.format(numify(collections|count, "collection", "collections")) }}.

+ +
+
- {% if uc %} -

{{ uc.name }}

-

{{ 'This collection has {}.'.format(numify(trait_obs|count, "record", "records")) }}

- {% else %} -

{{ collection_name }}

-

{{ 'This collection has {}.'.format(numify(trait_obs|count, "record", "records")) }}

- {% endif %} -
+ {% if uc %} +

{{ uc.name }}

+ {% else %} +

{{ collection_name }}

+ {% endif %} +

This collection has {{ '{}'.format(numify(trait_obs|count, "record", "records")) }}

+ +
-
{% if uc %} @@ -63,6 +62,10 @@ WebGestalt + + diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index 4786e379..76aa8d2d 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -4,12 +4,12 @@ {% endblock %} {% block content %} - - {{ header("Correlation", 'Trait: {} Dataset: {}'.format(this_trait.name, dataset.name)) }} -

Values of record {{ this_trait.name }} in the {{ dataset.fullname }} @@ -59,6 +59,10 @@ WebGestalt + + diff --git a/wqflask/wqflask/templates/geneweaver_page.html b/wqflask/wqflask/templates/geneweaver_page.html new file mode 100644 index 00000000..91fca85b --- /dev/null +++ b/wqflask/wqflask/templates/geneweaver_page.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} +{% block title %}{% if wrong_input == "True" %}WebGestalt Error{% else %}Opening WebGestalt{% endif %}{% endblock %} +{% block content %} + {% if wrong_input == "True" %} + {{ header("Error") }} + +

+ {% if chip_name == "mixed" %} +

Sorry, the analysis was interrupted because your selections from GeneNetwork apparently include data from more than one array platform (i.e., Affymetrix U74A and M430 2.0). Most WebGestalt analyses assume that you are using a single array type and compute statistical values on the basis of that particular array. Please reselect traits from a signle platform and submit again.

+ {% elif chip_name == "not_microarray" %} +

You need to select at least one microarray trait to submit. + {% elif '_NA' in chip_name %} +

Sorry, the analysis was interrupted because your selections from GeneNetwork apparently include data from platform {{ chip_name }} which is unknown by GeneWeaver. Please reselect traits and submit again.

+ {% else %} +

Sorry, an error occurred while submitting your traits to GeneWeaver.

+ {% endif %} +
+ {% else %} +
+

Opening GeneWeaver...

+
+ + {% for key in hidden_vars %} + + {% endfor %} + + {% endif %} +{% endblock %} +{% block js %} +{% if wrong_input == "False" %} + +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 66073555..ebebd044 100644 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -62,6 +62,13 @@ } ); }; + $.fn.dataTable.ext.order['dom-inner-text'] = function ( settings, col ) + { + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $(td).text(); + } ); + } + $(document).ready( function () { $('#trait_table tr').click(function(event) { @@ -115,6 +122,7 @@ 'title': "Record", 'type': "natural", 'data': null, + 'orderDataType': "dom-inner-text", 'render': function(data, type, row, meta) { return '' + data.name + '' } diff --git a/wqflask/wqflask/templates/gsearch_pheno.html b/wqflask/wqflask/templates/gsearch_pheno.html index 168b2846..96a5d71a 100644 --- a/wqflask/wqflask/templates/gsearch_pheno.html +++ b/wqflask/wqflask/templates/gsearch_pheno.html @@ -62,6 +62,13 @@ } ); }; + $.fn.dataTable.ext.order['dom-inner-text'] = function ( settings, col ) + { + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $(td).text(); + } ); + } + $(document).ready( function () { $('#trait_table tr').click(function(event) { @@ -144,6 +151,7 @@ 'title': "Year", 'type': "natural", 'data': null, + 'orderDataType': "dom-inner-text", 'render': function(data, type, row, meta) { if (data.pubmed_id != "N/A"){ return '' + data.pubmed_text + '' diff --git a/wqflask/wqflask/templates/search_result_page.html b/wqflask/wqflask/templates/search_result_page.html index db6bc15d..36a25665 100644 --- a/wqflask/wqflask/templates/search_result_page.html +++ b/wqflask/wqflask/templates/search_result_page.html @@ -44,6 +44,9 @@

To study a record click on its ID below, and to view the whole description {% if dataset.type == "Publish" %}or list of authors {% endif %} hover over the table cell. Check records below and click Add button to add to selection.

+ +
+
@@ -86,6 +89,10 @@ WebGestalt + + @@ -149,6 +156,13 @@ } ); }; + $.fn.dataTable.ext.order['dom-inner-text'] = function ( settings, col ) + { + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $(td).text(); + } ); + } + $(document).ready( function () { $('#trait_table tr').click(function(event) { @@ -261,6 +275,7 @@ 'title': "Record", 'type': "natural", 'data': null, + 'orderDataType': "dom-inner-text", 'render': function(data, type, row, meta) { return '' + data.name + '' } @@ -316,6 +331,7 @@ { 'title': "Year", 'type': "natural", + 'orderDataType': "dom-inner-text", 'data': null, 'render': function(data, type, row, meta) { if (data.pubmed_id != "N/A"){ diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 7c2ed80d..cd2e047b 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -43,7 +43,7 @@ from base.data_set import DataSet # Used by YAML in marker_regression from wqflask.show_trait import show_trait from wqflask.show_trait import export_trait_data from wqflask.heatmap import heatmap -from wqflask.external_tools import send_to_bnw, send_to_webgestalt +from wqflask.external_tools import send_to_bnw, send_to_webgestalt, send_to_geneweaver from wqflask.comparison_bar_chart import comparison_bar_chart from wqflask.marker_regression import run_mapping from wqflask.marker_regression import display_mapping_results @@ -499,7 +499,25 @@ def webgestalt_page(): result = template_vars.__dict__ rendered_template = render_template("webgestalt_page.html", **result) else: - rendered_template = render_template("empty_collection.html", **{'tool':'BNW'}) + rendered_template = render_template("empty_collection.html", **{'tool':'WebGestalt'}) + + return rendered_template + +@app.route("/geneweaver_page", methods=('POST',)) +def geneweaver_page(): + logger.info("In run WebGestalt, request.form is:", pf(request.form)) + logger.info(request.url) + + start_vars = request.form + + traits = [trait.strip() for trait in start_vars['trait_list'].split(',')] + if traits[0] != "": + template_vars = send_to_geneweaver.SendToGeneWeaver(request.form) + + result = template_vars.__dict__ + rendered_template = render_template("geneweaver_page.html", **result) + else: + rendered_template = render_template("empty_collection.html", **{'tool':'GeneWeaver'}) return rendered_template -- cgit v1.2.3