diff options
26 files changed, 1035 insertions, 485 deletions
diff --git a/etc/default_settings.py b/etc/default_settings.py index da8cbb7c..3e54ad1f 100644 --- a/etc/default_settings.py +++ b/etc/default_settings.py @@ -77,7 +77,7 @@ USE_GN_SERVER = 'False' # Use GN_SERVER SQL calls HOME = os.environ['HOME'] # ---- Default locations -GENENETWORK_FILES = HOME+"/gn2_data" # base dir for all static data files +GENENETWORK_FILES = HOME+"/genotype_files" # base dir for all static data files # ---- Path overrides for Genenetwork - the defaults are normally # picked up from Guix or in the HOME directory diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index b71dacf6..3daf9ea9 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -18,7 +18,7 @@ import simplejson as json from MySQLdb import escape_string as escape from pprint import pformat as pf -from flask import Flask, g, request +from flask import Flask, g, request, url_for from utility.logger import getLogger logger = getLogger(__name__ ) @@ -176,13 +176,23 @@ def get_sample_data(): trait_ob = GeneralTrait(name=trait, dataset_name=dataset) - return json.dumps([trait, {key: value.value for key, value in trait_ob.data.iteritems() }]) - - #jsonable_sample_data = {} - #for sample in trait_ob.data.iteritems(): - # jsonable_sample_data[sample] = trait_ob.data[sample].value - # - #return jsonable_sample_data + trait_dict = {} + trait_dict['name'] = trait + trait_dict['db'] = dataset + trait_dict['type'] = trait_ob.dataset.type + trait_dict['group'] = trait_ob.dataset.group.name + trait_dict['tissue'] = trait_ob.dataset.tissue + trait_dict['species'] = trait_ob.dataset.group.species + trait_dict['url'] = url_for('show_trait_page', trait_id = trait, dataset = dataset) + trait_dict['description'] = trait_ob.description_display + if trait_ob.dataset.type == "ProbeSet": + trait_dict['symbol'] = trait_ob.symbol + trait_dict['location'] = trait_ob.location_repr + elif trait_ob.dataset.type == "Publish": + trait_dict['pubmed_link'] = trait_ob.pubmed_link + trait_dict['pubmed_text'] = trait_ob.pubmed_text + + return json.dumps([trait_dict, {key: value.value for key, value in trait_ob.data.iteritems() }]) def jsonable(trait): """Return a dict suitable for using as json diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py index ef644d85..b543c589 100644 --- a/wqflask/utility/corr_result_helpers.py +++ b/wqflask/utility/corr_result_helpers.py @@ -15,7 +15,7 @@ def normalize_values(a_values, b_values): a_new = [] b_new = [] for counter in range(min_length): - if a_values[counter] and b_values[counter]: + if (a_values[counter] or a_values[counter] == 0) and (b_values[counter] or b_values[counter] == 0): a_new.append(a_values[counter]) b_new.append(b_values[counter]) diff --git a/wqflask/wqflask/comparison_bar_chart/__init__.py b/wqflask/wqflask/comparison_bar_chart/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/wqflask/wqflask/comparison_bar_chart/__init__.py diff --git a/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py b/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py new file mode 100644 index 00000000..b9e6f450 --- /dev/null +++ b/wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py @@ -0,0 +1,118 @@ +## Copyright (C) University of Tennessee Health Science Center, Memphis, TN. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Affero General Public License for more details. +# +# This program is available from Source Forge: at GeneNetwork Project +# (sourceforge.net/projects/genenetwork/). +# +# Contact Dr. Robert W. Williams at rwilliams@uthsc.edu +# +# +# This module is used by GeneNetwork project (www.genenetwork.org) + +from __future__ import absolute_import, print_function, division + +import sys +# sys.path.append(".") Never do this in a webserver! + +import string +import cPickle +import os +import time +import pp +import math +import collections +import resource + + +from pprint import pformat as pf + +from htmlgen import HTMLgen2 as HT +import reaper + +from base.trait import GeneralTrait +from base import data_set +from utility import webqtlUtil, helper_functions, corr_result_helpers +from db import webqtlDatabaseFunction +import utility.webqtlUtil #this is for parallel computing only. +from wqflask.correlation import correlation_functions +from utility.benchmark import Bench + +from MySQLdb import escape_string as escape + +from pprint import pformat as pf + +from flask import Flask, g + + +class ComparisonBarChart(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.all_sample_list = [] + self.traits = [] + self.insufficient_shared_samples = False + this_group = self.trait_list[0][1].group.name #ZS: Getting initial group name before verifying all traits are in the same group in the following loop + for trait_db in self.trait_list: + + if trait_db[1].group.name != this_group: + self.insufficient_shared_samples = True + break + else: + this_group = trait_db[1].group.name + this_trait = trait_db[0] + self.traits.append(this_trait) + + this_sample_data = this_trait.data + + for sample in this_sample_data: + if sample not in self.all_sample_list: + self.all_sample_list.append(sample) + + if self.insufficient_shared_samples: + pass + else: + self.sample_data = [] + for trait_db in self.trait_list: + this_trait = trait_db[0] + this_sample_data = this_trait.data + + this_trait_vals = [] + for sample in self.all_sample_list: + if sample in this_sample_data: + this_trait_vals.append(this_sample_data[sample].value) + else: + this_trait_vals.append('') + self.sample_data.append(this_trait_vals) + + self.js_data = dict(traits = [trait.name for trait in self.traits], + samples = self.all_sample_list, + sample_data = self.sample_data,) + + def get_trait_db_obs(self, trait_db_list): + + self.trait_list = [] + for i, trait_db in enumerate(trait_db_list): + if i == (len(trait_db_list) - 1): + break + trait_name, dataset_name = trait_db.split(":") + #print("dataset_name:", dataset_name) + dataset_ob = data_set.create_dataset(dataset_name) + trait_ob = GeneralTrait(dataset=dataset_ob, + name=trait_name, + cellid=None) + self.trait_list.append((trait_ob, dataset_ob)) + + #print("trait_list:", self.trait_list) + diff --git a/wqflask/wqflask/gsearch.py b/wqflask/wqflask/gsearch.py index fe1e17d2..37eb46cb 100644 --- a/wqflask/wqflask/gsearch.py +++ b/wqflask/wqflask/gsearch.py @@ -5,6 +5,8 @@ from base.data_set import create_dataset from base.trait import GeneralTrait from db import webqtlDatabaseFunction +from base import webqtlConfig + from utility.type_checking import is_float, is_int, is_str, get_float, get_int, get_string from utility.benchmark import Bench @@ -57,10 +59,29 @@ class GSearch(object): self.trait_list = [] with Bench("Creating trait objects"): for line in re: - dataset = create_dataset(line[3], "ProbeSet", get_samplelist=False) - trait_id = line[4] + this_trait = {} + this_trait['name'] = line[4] + this_trait['dataset'] = line[3] + this_trait['species'] = line[0] + this_trait['group'] = line[1] + this_trait['tissue'] = line[2] + this_trait['symbol'] = line[5] + this_trait['description'] = line[6] + this_trait['location_repr'] = 'N/A' + if (line[7] != "NULL" and line[7] != "") and (line[8] != 0): + this_trait['location_repr'] = 'Chr%s: %.6f' % (line[7], float(line[8])) + this_trait['mean'] = line[9] + this_trait['LRS_score_repr'] = "N/A" + if line[10] != "" and line[10] != None: + this_trait['LRS_score_repr'] = '%3.1f' % line[10] + this_trait['additive'] = "N/A" + if line[13] != "": + this_trait['additive'] = line[13] + + #dataset = create_dataset(line[3], "ProbeSet", get_samplelist=False) + #trait_id = line[4] #with Bench("Building trait object"): - this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + #this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=False, get_sample_info=False) self.trait_list.append(this_trait) elif self.type == "phenotype": @@ -73,8 +94,8 @@ class GSearch(object): Phenotype.`Post_publication_description`, Publication.`Authors`, Publication.`Year`, + Publication.`PubMed_ID`, PublishXRef.`LRS`, - PublishXRef.`Locus`, PublishXRef.`additive` FROM Species,InbredSet,PublishFreeze,PublishXRef,Phenotype,Publication WHERE PublishXRef.`InbredSetId`=InbredSet.`Id` @@ -100,7 +121,30 @@ class GSearch(object): self.trait_list = [] with Bench("Creating trait objects"): for line in re: - dataset = create_dataset(line[2], "Publish") - trait_id = line[3] - this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) + this_trait = {} + this_trait['name'] = line[3] + this_trait['dataset'] = line[2] + this_trait['species'] = line[0] + this_trait['group'] = line[1] + this_trait['description'] = line[4] + this_trait['authors'] = line[5] + this_trait['year'] = line[6] + if this_trait['year'].isdigit(): + this_trait['pubmed_text'] = this_trait['year'] + else: + this_trait['pubmed_text'] = "N/A" + if line[7] != "" and line[7] != None: + this_trait['pubmed_link'] = webqtlConfig.PUBMEDLINK_URL % line[7] + else: + this_trait['pubmed_link'] = "N/A" + this_trait['LRS_score_repr'] = "N/A" + if line[8] != "" and line[8] != None: + this_trait['LRS_score_repr'] = '%3.1f' % line[8] + this_trait['additive'] = "N/A" + if line[9] != "": + this_trait['additive'] = line[9] + + #dataset = create_dataset(line[2], "Publish") + #trait_id = line[3] + #this_trait = GeneralTrait(dataset=dataset, name=trait_id, get_qtl_info=True, get_sample_info=False) self.trait_list.append(this_trait) diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py index 40402597..94145bb3 100644 --- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py +++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py @@ -68,12 +68,10 @@ class MarkerRegression(object): # ** GENES ********** BAND_SPACING = 4 - #ENSEMBL_BAND_Y = UCSC_BAND_Y + UCSC_BAND_HEIGHT + BAND_SPACING - UCSC_BAND_HEIGHT = 10 - ENSEMBL_BAND_HEIGHT = 10 - WEBQTL_BAND_HEIGHT = 10 + BAND_HEIGHT = 10 + BAND_HEIGHT = 10 + BAND_HEIGHT = 10 - #GENE_START_Y = ENSEMBL_BAND_Y + ENSEMBL_BAND_HEIGHT + BAND_SPACING NUM_GENE_ROWS = 10 EACH_GENE_HEIGHT = 6 # number of pixels tall, for each gene to display EACH_GENE_ARROW_WIDTH = 5 @@ -124,6 +122,10 @@ class MarkerRegression(object): CLICKABLE_WEBQTL_REGION_OUTLINE_COLOR = pid.HexColor(0xFCE9E9) CLICKABLE_WEBQTL_TEXT_COLOR = pid.HexColor(0x912828) + CLICKABLE_PHENOGEN_REGION_COLOR = pid.HexColor(0xA2FB94) + CLICKABLE_PHENOGEN_REGION_OUTLINE_COLOR = pid.HexColor(0xCEFEC7) + CLICKABLE_PHENOGEN_TEXT_COLOR = pid.HexColor(0x1FD504) + CLICKABLE_UCSC_REGION_COLOR = pid.HexColor(0xDDDDEE) CLICKABLE_UCSC_REGION_OUTLINE_COLOR = pid.HexColor(0xEDEDFF) CLICKABLE_UCSC_TEXT_COLOR = pid.HexColor(0x333366) @@ -498,7 +500,10 @@ class MarkerRegression(object): #Drawing Area Height drawAreaHeight = plotHeight if self.plotScale == 'physic' and self.selectedChr > -1: - drawAreaHeight -= self.ENSEMBL_BAND_HEIGHT + self.UCSC_BAND_HEIGHT+ self.WEBQTL_BAND_HEIGHT + 3*self.BAND_SPACING+ 10*zoom + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + drawAreaHeight -= 4*self.BAND_HEIGHT + 4*self.BAND_SPACING+ 10*zoom + else: + drawAreaHeight -= 3*self.BAND_HEIGHT + 3*self.BAND_SPACING+ 10*zoom if self.geneChecked: drawAreaHeight -= self.NUM_GENE_ROWS*self.EACH_GENE_HEIGHT + 3*self.BAND_SPACING + 10*zoom else: @@ -1023,7 +1028,10 @@ class MarkerRegression(object): #Draw Genes geneYLocation = yPaddingTop + (gIndex % self.NUM_GENE_ROWS) * self.EACH_GENE_HEIGHT*zoom - geneYLocation += self.UCSC_BAND_HEIGHT + self.BAND_SPACING + self.ENSEMBL_BAND_HEIGHT + self.BAND_SPACING + self.WEBQTL_BAND_HEIGHT + self.BAND_SPACING + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + geneYLocation += 4*self.BAND_HEIGHT + 4*self.BAND_SPACING + else: + geneYLocation += 3*self.BAND_HEIGHT + 3*self.BAND_SPACING #draw the detail view if self.endMb - self.startMb <= self.DRAW_DETAIL_MB and geneEndPix - geneStartPix > self.EACH_GENE_ARROW_SPACING * 3: @@ -1217,7 +1225,10 @@ class MarkerRegression(object): #Draw Genes geneYLocation = yPaddingTop + self.NUM_GENE_ROWS * (self.EACH_GENE_HEIGHT)*zoom - geneYLocation += self.UCSC_BAND_HEIGHT + self.BAND_SPACING + self.ENSEMBL_BAND_HEIGHT + self.BAND_SPACING + self.WEBQTL_BAND_HEIGHT + self.BAND_SPACING + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + geneYLocation += 4*self.BAND_HEIGHT + 4*self.BAND_SPACING + else: + geneYLocation += 3*self.BAND_HEIGHT + 3*self.BAND_SPACING if self.genotype[0][i].name != " - " : @@ -1335,49 +1346,70 @@ class MarkerRegression(object): i = 0 paddingTop = yTopOffset - ucscPaddingTop = paddingTop + self.WEBQTL_BAND_HEIGHT + self.BAND_SPACING - ensemblPaddingTop = ucscPaddingTop + self.UCSC_BAND_HEIGHT + self.BAND_SPACING + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + phenogenPaddingTop = paddingTop + (self.BAND_HEIGHT + self.BAND_SPACING) + ucscPaddingTop = paddingTop + 2*(self.BAND_HEIGHT + self.BAND_SPACING) + ensemblPaddingTop = paddingTop + 3*(self.BAND_HEIGHT + self.BAND_SPACING) + else: + ucscPaddingTop = paddingTop + (self.BAND_HEIGHT + self.BAND_SPACING) + ensemblPaddingTop = paddingTop + 2*(self.BAND_HEIGHT + self.BAND_SPACING) if zoom == 1: for pixel in range(xLeftOffset, xLeftOffset + plotWidth, pixelStep): calBase = self.kONE_MILLION*(startMb + (endMb-startMb)*(pixel-xLeftOffset-0.0)/plotWidth) + if pixel == (xLeftOffset + pixelStep*2): + logger.debug("CALBASE:", calBase) + logger.debug("FLANKING:", flankingWidthInBases) xBrowse1 = pixel xBrowse2 = min(xLeftOffset + plotWidth, (pixel + pixelStep - 1)) - WEBQTL_COORDS = "%d, %d, %d, %d" % (xBrowse1, paddingTop, xBrowse2, (paddingTop+self.WEBQTL_BAND_HEIGHT)) + WEBQTL_COORDS = "%d, %d, %d, %d" % (xBrowse1, paddingTop, xBrowse2, (paddingTop+self.BAND_HEIGHT)) WEBQTL_HREF = "javascript:rangeView('%s', %f, %f)" % (self.selectedChr - 1, max(0, (calBase-webqtlZoomWidth))/1000000.0, (calBase+webqtlZoomWidth)/1000000.0) WEBQTL_TITLE = "Click to view this section of the genome in WebQTL" gifmap.areas.append(HT.Area(shape='rect',coords=WEBQTL_COORDS,href=WEBQTL_HREF, title=WEBQTL_TITLE)) - canvas.drawRect(xBrowse1, paddingTop, xBrowse2, (paddingTop + self.WEBQTL_BAND_HEIGHT), edgeColor=self.CLICKABLE_WEBQTL_REGION_COLOR, fillColor=self.CLICKABLE_WEBQTL_REGION_COLOR) - canvas.drawLine(xBrowse1, paddingTop, xBrowse1, (paddingTop + self.WEBQTL_BAND_HEIGHT), color=self.CLICKABLE_WEBQTL_REGION_OUTLINE_COLOR) + canvas.drawRect(xBrowse1, paddingTop, xBrowse2, (paddingTop + self.BAND_HEIGHT), edgeColor=self.CLICKABLE_WEBQTL_REGION_COLOR, fillColor=self.CLICKABLE_WEBQTL_REGION_COLOR) + canvas.drawLine(xBrowse1, paddingTop, xBrowse1, (paddingTop + self.BAND_HEIGHT), color=self.CLICKABLE_WEBQTL_REGION_OUTLINE_COLOR) + + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + PHENOGEN_COORDS = "%d, %d, %d, %d" % (xBrowse1, phenogenPaddingTop, xBrowse2, (phenogenPaddingTop+self.BAND_HEIGHT)) + if self.dataset.group.species == "mouse": + PHENOGEN_HREF = "https://phenogen.ucdenver.edu/PhenoGen/gene.jsp?speciesCB=Mm&auto=Y&geneTxt=chr%s:%d-%d&genomeVer=mm10" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) + else: + PHENOGEN_HREF = "https://phenogen.ucdenver.edu/PhenoGen/gene.jsp?speciesCB=Mm&auto=Y&geneTxt=chr%s:%d-%d&genomeVer=mm10" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) + PHENOGEN_TITLE = "Click to view this section of the genome in PhenoGen" + gifmap.areas.append(HT.Area(shape='rect',coords=PHENOGEN_COORDS,href=PHENOGEN_HREF, title=PHENOGEN_TITLE)) + canvas.drawRect(xBrowse1, phenogenPaddingTop, xBrowse2, (phenogenPaddingTop+self.BAND_HEIGHT), edgeColor=self.CLICKABLE_PHENOGEN_REGION_COLOR, fillColor=self.CLICKABLE_PHENOGEN_REGION_COLOR) + canvas.drawLine(xBrowse1, phenogenPaddingTop, xBrowse1, (phenogenPaddingTop+self.BAND_HEIGHT), color=self.CLICKABLE_PHENOGEN_REGION_OUTLINE_COLOR) - UCSC_COORDS = "%d, %d, %d, %d" %(xBrowse1, ucscPaddingTop, xBrowse2, (ucscPaddingTop+self.UCSC_BAND_HEIGHT)) + UCSC_COORDS = "%d, %d, %d, %d" %(xBrowse1, ucscPaddingTop, xBrowse2, (ucscPaddingTop+self.BAND_HEIGHT)) if self.dataset.group.species == "mouse": UCSC_HREF = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=%s&position=chr%s:%d-%d&hgt.customText=%s/snp/chr%s" % (self._ucscDb, self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases, webqtlConfig.PORTADDR, self.selectedChr) else: UCSC_HREF = "http://genome.ucsc.edu/cgi-bin/hgTracks?db=%s&position=chr%s:%d-%d" % (self._ucscDb, self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) UCSC_TITLE = "Click to view this section of the genome in the UCSC Genome Browser" gifmap.areas.append(HT.Area(shape='rect',coords=UCSC_COORDS,href=UCSC_HREF, title=UCSC_TITLE)) - canvas.drawRect(xBrowse1, ucscPaddingTop, xBrowse2, (ucscPaddingTop+self.UCSC_BAND_HEIGHT), edgeColor=self.CLICKABLE_UCSC_REGION_COLOR, fillColor=self.CLICKABLE_UCSC_REGION_COLOR) - canvas.drawLine(xBrowse1, ucscPaddingTop, xBrowse1, (ucscPaddingTop+self.UCSC_BAND_HEIGHT), color=self.CLICKABLE_UCSC_REGION_OUTLINE_COLOR) + canvas.drawRect(xBrowse1, ucscPaddingTop, xBrowse2, (ucscPaddingTop+self.BAND_HEIGHT), edgeColor=self.CLICKABLE_UCSC_REGION_COLOR, fillColor=self.CLICKABLE_UCSC_REGION_COLOR) + canvas.drawLine(xBrowse1, ucscPaddingTop, xBrowse1, (ucscPaddingTop+self.BAND_HEIGHT), color=self.CLICKABLE_UCSC_REGION_OUTLINE_COLOR) - ENSEMBL_COORDS = "%d, %d, %d, %d" %(xBrowse1, ensemblPaddingTop, xBrowse2, (ensemblPaddingTop+self.ENSEMBL_BAND_HEIGHT)) + ENSEMBL_COORDS = "%d, %d, %d, %d" %(xBrowse1, ensemblPaddingTop, xBrowse2, (ensemblPaddingTop+self.BAND_HEIGHT)) if self.dataset.group.species == "mouse": ENSEMBL_HREF = "http://www.ensembl.org/Mus_musculus/contigview?highlight=&chr=%s&vc_start=%d&vc_end=%d&x=35&y=12" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) else: ENSEMBL_HREF = "http://www.ensembl.org/Rattus_norvegicus/contigview?chr=%s&start=%d&end=%d" % (self.selectedChr, max(0, calBase-flankingWidthInBases), calBase+flankingWidthInBases) ENSEMBL_TITLE = "Click to view this section of the genome in the Ensembl Genome Browser" gifmap.areas.append(HT.Area(shape='rect',coords=ENSEMBL_COORDS,href=ENSEMBL_HREF, title=ENSEMBL_TITLE)) - canvas.drawRect(xBrowse1, ensemblPaddingTop, xBrowse2, (ensemblPaddingTop+self.ENSEMBL_BAND_HEIGHT), edgeColor=self.CLICKABLE_ENSEMBL_REGION_COLOR, fillColor=self.CLICKABLE_ENSEMBL_REGION_COLOR) - canvas.drawLine(xBrowse1, ensemblPaddingTop, xBrowse1, (ensemblPaddingTop+self.ENSEMBL_BAND_HEIGHT), color=self.CLICKABLE_ENSEMBL_REGION_OUTLINE_COLOR) + canvas.drawRect(xBrowse1, ensemblPaddingTop, xBrowse2, (ensemblPaddingTop+self.BAND_HEIGHT), edgeColor=self.CLICKABLE_ENSEMBL_REGION_COLOR, fillColor=self.CLICKABLE_ENSEMBL_REGION_COLOR) + canvas.drawLine(xBrowse1, ensemblPaddingTop, xBrowse1, (ensemblPaddingTop+self.BAND_HEIGHT), color=self.CLICKABLE_ENSEMBL_REGION_OUTLINE_COLOR) # end for - canvas.drawString("Click to view the corresponding section of the genome in an 8x expanded WebQTL map", (xLeftOffset + 10), paddingTop + self.WEBQTL_BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_WEBQTL_TEXT_COLOR) - canvas.drawString("Click to view the corresponding section of the genome in the UCSC Genome Browser", (xLeftOffset + 10), ucscPaddingTop + self.UCSC_BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_UCSC_TEXT_COLOR) - canvas.drawString("Click to view the corresponding section of the genome in the Ensembl Genome Browser", (xLeftOffset+10), ensemblPaddingTop + self.ENSEMBL_BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_ENSEMBL_TEXT_COLOR) + canvas.drawString("Click to view the corresponding section of the genome in an 8x expanded WebQTL map", (xLeftOffset + 10), paddingTop + self.BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_WEBQTL_TEXT_COLOR) + if self.dataset.group.species == "mouse" or self.dataset.group.species == "rat": + canvas.drawString("Click to view the corresponding section of the genome in PhenoGen", (xLeftOffset + 10), phenogenPaddingTop + self.BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_PHENOGEN_TEXT_COLOR) + canvas.drawString("Click to view the corresponding section of the genome in the UCSC Genome Browser", (xLeftOffset + 10), ucscPaddingTop + self.BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_UCSC_TEXT_COLOR) + canvas.drawString("Click to view the corresponding section of the genome in the Ensembl Genome Browser", (xLeftOffset+10), ensemblPaddingTop + self.BAND_HEIGHT/2, font=clickableRegionLabelFont, color=self.CLICKABLE_ENSEMBL_TEXT_COLOR) #draw the gray text chrFont = pid.Font(ttf="verdana", size=26*zoom, bold=1) diff --git a/wqflask/wqflask/static/new/javascript/comparison_bar_chart.js b/wqflask/wqflask/static/new/javascript/comparison_bar_chart.js new file mode 100644 index 00000000..5e73807c --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/comparison_bar_chart.js @@ -0,0 +1,25 @@ +generate_traces = function() { + traces = []; + for (i = 0, _len = js_data.traits.length; i < _len; i++) { + this_trace = { + x: js_data.samples, + y: js_data.sample_data[i], + name: js_data.traits[i], + type: 'bar', + bargap: 20 + } + + traces.push(this_trace) + } + + return traces +} + +create_bar_chart = function() { + var data = generate_traces() + var layout = {barmode: 'group', bargap: 5}; + + Plotly.newPlot('comp_bar_chart', data, layout); +} + +create_bar_chart();
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json b/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json index c605329b..81185136 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json +++ b/wqflask/wqflask/static/new/javascript/dataset_menu_structure.json @@ -1751,7 +1751,7 @@ ], "Phenotypes": [ [ - "None", + "651", "B6D2RIPublish", "B6D2RI Published Phenotypes" ] @@ -2616,6 +2616,16 @@ "EPFL/LISP BXD CD+HFD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA Exon Level" ], [ + "849", + "EPFLMouseLiverCDEx0413", + "EPFL/LISP BXD CD Liver Affy Mouse Gene 1.0 ST (Apr13) RMA Exon Level" + ], + [ + "848", + "EPFLMouseLiverHFCEx0413", + "EPFL/LISP BXD HFC Liver Affy Mouse Gene 1.0 ST (Apr13) RMA Exon Level" + ], + [ "700", "UTHSC-VGX_MmBXDHepatocytesRMA1014", "UT-VGX Hepatocytes Affy Mouse Gene 1.0 ST Gene Level (Oct14) RMA" @@ -2783,7 +2793,7 @@ ], "Phenotypes": [ [ - "None", + "602", "BXDPublish", "BXD Published Phenotypes" ] @@ -3030,6 +3040,18 @@ "842", "UTHSC-BXD-Liv-0917", "UTHSC BXD Liver Affy Clariom S GeneLevel Main (Sep17) RMA **" + ], + [ + "850", + "UTHSC-BXD-Liv-0818", + "UTHSC BXD Liver Affy Clariom S GeneLevel Main (Aug18) RMA **" + ] + ], + "Phenotypes": [ + [ + "None", + "BXD-HarvestedPublish", + "BXD-Harvested Published Phenotypes" ] ] }, @@ -3638,7 +3660,7 @@ "HSNIH-Palmer": { "Phenotypes": [ [ - "None", + "652", "HSNIH-PalmerPublish", "HSNIH-Palmer Published Phenotypes" ] @@ -3892,11 +3914,11 @@ ], [ "AKXD", - "AKXD" + "AKXD RI Family" ], [ "AXBXA", - "AXB/BXA" + "AXB/BXA RI Family" ], [ "B6BTBRF2", @@ -3931,10 +3953,6 @@ "BHF2 (Apoe Null) UCLA" ], [ - "BXD", - "BXD" - ], - [ "B6D2RI", "BXD Aged" ], @@ -3947,12 +3965,16 @@ "BXD NIA Longevity Study" ], [ + "BXD", + "BXD RI Family" + ], + [ "BXD300", "BXD300" ], [ "BXH", - "BXH" + "BXH RI Family" ], [ "CTB6F2", @@ -3976,7 +3998,7 @@ ], [ "CXB", - "CXB" + "CXB RI Family (strain means)" ], [ "D2GM", @@ -4000,11 +4022,11 @@ ], [ "LXS", - "LXS" + "ILSXISS (LXS) RI Family (strain means)" ], [ "MDP", - "Mouse Diversity Panel" + "Mouse Diversity Panel (strain means)" ], [ "NZBXFVB-N2", @@ -5114,6 +5136,10 @@ ], "BXD-Harvested": [ [ + "Phenotypes", + "Phenotypes" + ], + [ "Liver mRNA", "Liver mRNA" ] diff --git a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js index c290cdfe..57dae378 100644 --- a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js +++ b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js @@ -1,75 +1,80 @@ -// http://gn2-lei.genenetwork.org/corr_scatter_plot2?dataset_1=HC_M2_0606_P&dataset_2=HC_M2_0606_P&dataset_3=HC_M2_0606_P&trait_1=1427571_at&trait_2=1457022_at&trait_3=1427571_at - var chart; var srchart; +var layout = { + height: 700, + width: 800, + margin: { + l: 60, + r: 30, + t: 80, + b: 50 + }, + xaxis: { + title: js_data.trait_1, + zeroline: false, + visible: true, + linecolor: 'black', + linewidth: 1, + }, + yaxis: { + title: js_data.trait_2, + zeroline: false, + visible: true, + linecolor: 'black', + linewidth: 1, + } +} + +cofactor1_dict = {} +ranked_cofactor1_dict = {} +cofactor1_values = [] +ranked_cofactor1_values = [] +cofactor2_dict = {} +ranked_cofactor2_dict = {} + function drawg() { - // - chart = nv.models.scatterChart(); - // - chart.showLegend(false); - chart.duration(300); - //chart.color(d3.scale.category10().range()); - chart.pointRange([0, 400]); - chart.pointDomain([0, 10]); - // - chart.xAxis.axisLabel(js_data.trait_1); - chart.xAxis.axisLabelDistance(11); - chart.yAxis.axisLabel(js_data.trait_2); - chart.yAxis.axisLabelDistance(11); - // - xmin = d3.min(js_data.data[0]); - xmax = d3.max(js_data.data[0]); - xrange = xmax - xmin; - ymin = d3.min(js_data.data[1]); - ymax = d3.max(js_data.data[1]); - yrange = ymax - ymin; - chart.xDomain([xmin - xrange/10, xmax + xrange/10]); - chart.yDomain([ymin - yrange/10, ymax + yrange/10]); - chart.xAxis.tickFormat(d3.format(checkformat(xrange))); - chart.yAxis.tickFormat(d3.format(checkformat(yrange))); - // - chart.tooltip.contentGenerator(function (obj) { - return tiptext(obj); - }); + x_values = [] + y_values = [] + sample_names = [] + for (j = 0; j < js_data.data[0].length; j++) { + x_values.push(js_data.data[0][j]) + y_values.push(js_data.data[1][j]) + sample_names.push(js_data.indIDs[j]) + } + + var trace = { + x: x_values, + y: y_values, + mode: 'markers', + text: sample_names + } + + Plotly.newPlot('scatterplot2', [trace], layout) + } function srdrawg() { - // - srchart = nv.models.scatterChart(); - // - srchart.showLegend(false); - srchart.duration(300); - srchart.color(d3.scale.category10().range()); - srchart.pointRange([0, 400]); - srchart.pointDomain([0, 10]); - // - srchart.xAxis.axisLabel(js_data.trait_1); - srchart.xAxis.axisLabelDistance(11); - srchart.yAxis.axisLabel(js_data.trait_2); - srchart.yAxis.axisLabelDistance(11); - // - xmin = d3.min(js_data.rdata[0]); - xmax = d3.max(js_data.rdata[0]); - xrange = xmax - xmin; - ymin = d3.min(js_data.rdata[1]); - ymax = d3.max(js_data.rdata[1]); - yrange = ymax - ymin; - srchart.xDomain([0, xmax + xrange/10]); - srchart.yDomain([0, ymax + yrange/10]); - srchart.xAxis.tickFormat(d3.format(checkformat(xrange))); - srchart.yAxis.tickFormat(d3.format(checkformat(yrange))); - // - srchart.tooltip.contentGenerator(function (obj) { - return tiptext(obj); - }); -} + x_values = [] + y_values = [] + sample_names = [] + for (j = 0; j < js_data.rdata[0].length; j++) { + x_values.push(js_data.rdata[0][j]) + y_values.push(js_data.rdata[1][j]) + sample_names.push(js_data.indIDs[j]) + } -function tiptext(obj) { - return '<b style="font-size: 18px">' + obj.point.name + " (" + obj.point.x + ', ' + obj.point.y + ')</b>'; + var trace = { + x: x_values, + y: y_values, + mode: 'markers', + text: sample_names + } + + Plotly.newPlot('srscatterplot2', [trace], layout) } -function getdata(size, shape) { +function getdata() { var data = []; data.push({ values: [], @@ -79,37 +84,91 @@ function getdata(size, shape) { sizemin = 1; sizemax = 50; - if ('vals_3' in js_data) { - datamin = d3.min(js_data.vals_3); - datamax = d3.max(js_data.vals_3); - colormin = $("#cocolorfrom").val(); - colormax = $("#cocolorto").val(); - compute = d3.interpolate(colormin, colormax); - linear = d3.scale.linear().domain([datamin, datamax]).range([0,1]); + + if ($('input[name=cofactor1_vals]').val()){ + just_vals = [] + val_sample_dict = {} + val_sample_pairs = $('input[name=cofactor1_vals]').val().split(",") + for (i=0; i < val_sample_pairs.length; i++) { + just_vals.push(parseFloat(val_sample_pairs[i].split(":")[1])) + val_sample_dict[val_sample_pairs[i].split(":")[0]] = parseFloat(val_sample_pairs[i].split(":")[1]) + } + + cofactor1_dict = val_sample_dict + cofactor1_values = just_vals + } + + if ($('input[name=cofactor2_vals]').val()){ + vals_3 = []; + samples_3 = []; + val_sample_dict = {} + val_sample_pairs = $('input[name=cofactor2_vals]').val().split(",") + for (i=0; i < val_sample_pairs.length; i++) { + samples_3.push(val_sample_pairs[i].split(":")[0]) + vals_3.push(parseFloat(val_sample_pairs[i].split(":")[1])) + val_sample_dict[val_sample_pairs[i].split(":")[0]] = val_sample_pairs[i].split(":")[1] + } + datamin = d3.min(vals_3); + datamax = d3.max(vals_3); + + cofactor2_dict = val_sample_dict } + x_values = [] + y_values = [] + sample_names = [] + sizes = [] + for (j = 0; j < js_data.data[0].length; j++) { - if ('trait3' in js_data) { - if (js_data.indIDs[j] in js_data.trait3) { - datav = js_data.trait3[js_data.indIDs[j]].value; - // size = (sizemax - sizemin) * (datav - datamin) / (datamax - datamin) + sizemin; + if ($('input[name=cofactor2_vals]').val()){ + if (samples_3.indexOf(js_data.indIDs[j])) { + datav = vals_3[j] sizev = map1to2(datamin, datamax, sizemin, sizemax, datav); } } else { datav = 0; - sizev = sizemin; + sizev = 10; } + + x_values.push(js_data.data[0][j]) + y_values.push(js_data.data[1][j]) + sample_names.push(js_data.indIDs[j]) + sizes.push(sizev) + data[0].values.push({ + type: "normal", x: js_data.data[0][j], y: js_data.data[1][j], name: js_data.indIDs[j], size: sizev, - shape: shape, v3: datav }); } - console.log(data); - return data; + + point_text = [] + for (j = 0; j < sample_names.length; j++) { + this_text = "" + this_text += sample_names[j] + if (sample_names[j] in cofactor1_dict){ + this_text += "<br>Cofactor 1: " + cofactor1_dict[sample_names[j]] + } + if (sample_names[j] in cofactor2_dict){ + this_text += "<br>Cofactor 2: " + cofactor2_dict[sample_names[j]] + } + point_text.push(this_text) + } + + var trace = { + x: x_values, + y: y_values, + mode: 'markers', + text: point_text, + marker: { + size: sizes + } + } + + return [trace]; } function map1to2 (min1, max1, min2, max2, v1) { @@ -117,167 +176,223 @@ function map1to2 (min1, max1, min2, max2, v1) { return v2; } -function srgetdata(size, shape) { +function srgetdata() { var data = []; data.push({ values: [], slope: js_data.srslope, intercept: js_data.srintercept }); + + sizemin = 1; + sizemax = 50; + + x_values = [] + y_values = [] + sample_names = [] + sizes = [] + + if ($('input[name=ranked_cofactor1_vals]').val()){ + just_vals = [] + val_sample_dict = {} + val_sample_pairs = $('input[name=ranked_cofactor1_vals]').val().split(",") + for (i=0; i < val_sample_pairs.length; i++) { + just_vals.push(parseFloat(val_sample_pairs[i].split(":")[1])) + val_sample_dict[val_sample_pairs[i].split(":")[0]] = parseFloat(val_sample_pairs[i].split(":")[1]) + } + + ranked_cofactor1_dict = val_sample_dict + ranked_cofactor1_values = just_vals + } + + if ($('input[name=ranked_cofactor2_vals]').val()){ + vals_3 = [] + samples_3 = []; + val_sample_dict = {} + val_sample_pairs = $('input[name=ranked_cofactor2_vals]').val().split(",") + for (i=0; i<val_sample_pairs.length; i++){ + samples_3.push(val_sample_pairs[i].split(":")[0]) + vals_3.push(val_sample_pairs[i].split(":")[1]) + val_sample_dict[val_sample_pairs[i].split(":")[0]] = val_sample_pairs[i].split(":")[1] + } + datamin = d3.min(vals_3); + datamax = d3.max(vals_3); + + ranked_cofactor2_dict = val_sample_dict + } + for (j = 0; j < js_data.rdata[0].length; j++) { - if (js_data.indIDs[j] in js_data.trait3) { - size = js_data.trait3[js_data.indIDs[j]].value; - //console.log("yes "+js_data.indIDs[j]+", "+size); + if ($('input[name=ranked_cofactor2_vals]').val()){ + if (samples_3.indexOf(js_data.indIDs[j])) { + datav = vals_3[j] + sizev = map1to2(datamin, datamax, sizemin, sizemax, datav); + } } else { - //console.log("no "+js_data.indIDs[j]); + sizev = 10; } + + x_values.push(js_data.rdata[0][j]) + y_values.push(js_data.rdata[1][j]) + sample_names.push(js_data.indIDs[j]) + sizes.push(sizev) + data[0].values.push({ + type: "ranked", x: js_data.rdata[0][j], y: js_data.rdata[1][j], name: js_data.indIDs[j], - size: size, - shape: shape + size: sizev, }); } - return data; -} - -function checkformat(range) { - cell = range / 10.0; - if (cell >= 1) { - return ",r"; - } else { - cell = -Math.log(cell); - n = cell.toString().split(".")[0].length; - return ",.0" + n + "f"; + + point_text = [] + for (j = 0; j < sample_names.length; j++) { + this_text = "" + this_text += sample_names[j] + if (sample_names[j] in ranked_cofactor1_dict){ + this_text += "<br>Cofactor 1: " + ranked_cofactor1_dict[sample_names[j]] + } + if (sample_names[j] in ranked_cofactor2_dict){ + this_text += "<br>Cofactor 2: " + ranked_cofactor2_dict[sample_names[j]] + } + point_text.push(this_text) + } + + var trace = { + x: x_values, + y: y_values, + mode: 'markers', + text: point_text, + marker: { + size: sizes + } } -} -function chartupdate() { - // - var labelcolor = $("#labelcolor").val(); - $(".nvd3 .nv-axis.nv-x text").css("fill", labelcolor); - $(".nvd3 .nv-axis.nv-y text").css("fill", labelcolor); - // - var labelfont = $("#labelfont").val(); - $(".nvd3 .nv-axis.nv-x text").css("font-size", labelfont); - $(".nvd3 .nv-axis.nv-y text").css("font-size", labelfont); - // - var numbercolor = $("#numbercolor").val(); - $("g.tick text").css("fill", numbercolor); - // - var numberfont = $("#numberfont").val(); - $("g.tick text").css("font-size", numberfont); - // - var axiscolor = $("#axiscolor").val(); - $(".nv-x .nv-axis g path.domain").css("stroke", axiscolor); - $(".nv-y .nv-axis g path.domain").css("stroke", axiscolor); - // - var axiswidth = $("#axiswidth").val(); - $(".nv-x .nv-axis g path.domain").css("stroke-width", axiswidth); - $(".nv-y .nv-axis g path.domain").css("stroke-width", axiswidth); - // - var linecolor = $("#linecolor").val(); - $("line.nv-regLine").css("stroke", linecolor); - // - var linewidth = $("#linewidth").val(); - $("line.nv-regLine").css("stroke-width", linewidth); - // - var markcolor = $("#markcolor").val(); - $(".nvd3 g path").css("fill", markcolor); + return [trace]; } function chartupdatewh() { - // var width = $("#width").val(); - $("#scatterplot2 svg").css("width", width); - $("#srscatterplot2 svg").css("width", width); - // var height = $("#height").val(); - $("#scatterplot2 svg").css("height", height); - $("#srscatterplot2 svg").css("height", height); - // - window.dispatchEvent(new Event('resize')); + + width_height_update = { + height: height, + width: width + } + + Plotly.newPlot('scatterplot2', getdata(), layout) + Plotly.relayout('scatterplot2', width_height_update) + Plotly.newPlot('srscatterplot2', srgetdata(), layout) + Plotly.relayout('srscatterplot2', width_height_update) } - function colorer(d) { - datamin = d3.min(js_data.vals_3); - datamax = d3.max(js_data.vals_3); - //colormin = d3.rgb(255,0,0); - //colormax = d3.rgb(0,255,0); +function colorer(d) { + datamin = d3.min(cofactor1_values); + datamax = d3.max(cofactor1_values); colormin = $("#cocolorfrom").val(); colormax = $("#cocolorto").val(); - console.log("colormin: "+colormin); - console.log("colormax: "+colormax); + compute = d3.interpolate(colormin, colormax); + linear = d3.scale.linear().domain([datamin, datamax]).range([0,1]); + + this_sample = d.tx.split("<br>")[0] + + c = compute(linear(cofactor1_dict[this_sample])); + + return c; +} + +function ranked_colorer(d) { + datamin = d3.min(ranked_cofactor1_values); + datamax = d3.max(ranked_cofactor1_values); + colormin = $("#cocolorfrom").val(); + colormax = $("#cocolorto").val(); compute = d3.interpolate(colormin, colormax); linear = d3.scale.linear().domain([datamin, datamax]).range([0,1]); - //console.log(d[0].x); - c= compute(linear(d[0].x)); - //console.log(c); - return c; - } + + this_sample = d.tx.split("<br>")[0] + + c= compute(linear(ranked_cofactor1_dict[this_sample])); + + return c; +} function chartupdatedata() { - // var size = $("#marksize").val(); var shape = $("#markshape").val(); - // - d3.select('#scatterplot2 svg').datum(getdata(size, shape)).call(chart); - d3.select('#srscatterplot2 svg').datum(nv.log(srgetdata(size, shape))).call(srchart); - // - d3.selectAll('.nv-point') - .attr({ - 'stroke': colorer, - 'fill': colorer - }); - // - nv.utils.windowResize(chart.update); - nv.utils.windowResize(srchart.update); -} -function savesvg(svgEl, name) { - svgEl.setAttribute("xmlns", "http://www.w3.org/2000/svg"); - var svgData = svgEl.outerHTML; - var preface = '<?xml version="1.0" standalone="no"?>\r\n'; - preface += '<?xml-stylesheet type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.min.css"?>\r\n'; - var svgBlob = new Blob([preface, svgData], {type:"image/svg+xml;charset=utf-8"}); - var svgUrl = URL.createObjectURL(svgBlob); - var downloadLink = document.createElement("a"); - downloadLink.href = svgUrl; - downloadLink.download = name; - document.body.appendChild(downloadLink); - downloadLink.click(); - document.body.removeChild(downloadLink); -} + var pearson_title_update = { + title: "Pearson Correlation Scatterplot" + } + var spearman_title_update = { + title: "Spearman Rank Correlation Scatterplot" + } -function saveassvg_pcs() { - savesvg($("#svg_pcs")[0], "Pearson Correlation Scatterplot.svg"); -} + Plotly.newPlot('scatterplot2', getdata(), layout) + Plotly.relayout('scatterplot2', pearson_title_update) + Plotly.newPlot('srscatterplot2', srgetdata(), layout) + Plotly.relayout('srscatterplot2', spearman_title_update) -function saveassvg_srcs() { - savesvg($("#svg_srcs")[0], "Spearman Rank Correlation Scatterplot.svg"); + if ($('input[name=cofactor1_vals]').val()){ + d3.select('#scatterplot2 svg').selectAll('.point') + .style({ + 'stroke': colorer, + 'fill': colorer + }); + d3.select('#srscatterplot2 svg').selectAll('.point') + .style({ + 'stroke': ranked_colorer, + 'fill': ranked_colorer + }); + } } drawg(); srdrawg(); -$(".chartupdate").change(function () { - chartupdate(); -}); - $(".chartupdatewh").change(function () { chartupdatewh(); - chartupdate(); }); $(".chartupdatedata").change(function () { chartupdatedata(); - chartupdate(); }); +$(".cofactor1_type").change(function () { + console.log("cofactor1 type:", $(".cofactor1_type").val()) + if ($(".cofactor1_type").val() == "color"){ + $(".cofactor2_type").val("size") + } else { + $(".cofactor2_type").val("color") + } +}); + +open_covariate_selection = function() { + return $('#collections_holder').load('/collections/list #collections_list', (function(_this) { + return function() { + $.colorbox({ + inline: true, + href: "#collections_holder", + onComplete: function(){ + $.getScript("/static/new/javascript/get_traits_from_collection.js"); + } + }); + return $('a.collection_name').attr('onClick', 'return false'); + }; + })(this)); +}; + $(document).ready(function(){ chartupdatedata(); - chartupdate(); + + $('#select_cofactor1').click(function () { + $('input[name=selecting_which_cofactor]').val("1"); + open_covariate_selection(); + }); + + $('#select_cofactor2').click(function () { + $('input[name=selecting_which_cofactor]').val("2"); + open_covariate_selection(); + }); }); diff --git a/wqflask/wqflask/static/new/javascript/draw_probability_plot.js b/wqflask/wqflask/static/new/javascript/draw_probability_plot.js index f23dad0c..3d756303 100644 --- a/wqflask/wqflask/static/new/javascript/draw_probability_plot.js +++ b/wqflask/wqflask/static/new/javascript/draw_probability_plot.js @@ -26,7 +26,7 @@ redraw_prob_plot = function(samples, sample_group) { var container, h, margin, totalh, totalw, w; h = 600; - w = 600; + w = 500; margin = { left: 60, top: 40, diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js index 4abb0735..8a79627a 100644 --- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js +++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js @@ -4,7 +4,7 @@ var add_trait_data, assemble_into_json, back_to_collections, collection_click, c console.log("before get_traits_from_collection"); -collection_list = null; +//collection_list = null; this_trait_data = null; @@ -15,7 +15,6 @@ collection_click = function() { console.log("Clicking on:", $(this)); this_collection_url = $(this).find('.collection_name').prop("href"); this_collection_url += "&json"; - console.log("this_collection_url", this_collection_url); collection_list = $("#collections_holder").html(); return $.ajax({ dataType: "json", @@ -42,7 +41,6 @@ submit_click = function() { success: add_trait_data }); }); - console.log("SELECTED_TRAITS IS:", selected_traits); trait_names = []; samples = $('input[name=allsamples]').val().split(" "); all_vals = []; @@ -117,7 +115,6 @@ trait_click = function() { trait = $(this).parent().find('.trait').text(); dataset = $(this).parent().find('.dataset').text(); this_trait_url = "/trait/get_sample_data?trait=" + trait + "&dataset=" + dataset; - console.log("this_trait_url", this_trait_url); $.ajax({ dataType: "json", url: this_trait_url, @@ -134,28 +131,84 @@ add_trait_data = function(trait_data, textStatus, jqXHR) { return console.log("selected_traits:", selected_traits); }; +populate_cofactor_info = function(trait_info) { + if ($('input[name=selecting_which_cofactor]').val() == "1"){ + $('#cofactor1_trait_link').attr("href", trait_info['url']) + if (trait_info['type'] == "ProbeSet"){ + $('#cofactor1_trait_link').text(trait_info['species'] + " " + trait_info['group'] + " " + trait_info['tissue'] + " " + trait_info['db'] + ": " + trait_info['name']) + $('#cofactor1_description').text("[" + trait_info['symbol'] + " on " + trait_info['location'] + " Mb]\n" + trait_info['description']) + } else { + $('#cofactor1_trait_link').text(trait_info['species'] + " " + trait_info['group'] + " " + trait_info['db'] + ": " + trait_info['name']) + $('#cofactor1_description').html('<a href=\"' + trait_info['pubmed_link'] + '\">PubMed: ' + trait_info['pubmed_text'] + '</a><br>' + trait_info['description']) + } + $('#select_cofactor1').text("Change Cofactor 1"); + $('#cofactor1_info_container').css("display", "inline"); + $('#cofactor2_button').css("display", "inline"); + } else { + $('#cofactor2_trait_link').attr("href", trait_info['url']) + if (trait_info['type'] == "ProbeSet"){ + $('#cofactor2_trait_link').text(trait_info['species'] + " " + trait_info['group'] + " " + trait_info['tissue'] + " " + trait_info['db'] + ": " + trait_info['name']) + $('#cofactor2_description').text("[" + trait_info['symbol'] + " on " + trait_info['location'] + " Mb]\n" + trait_info['description']) + } else { + $('#cofactor2_trait_link').text(trait_info['species'] + " " + trait_info['group'] + " " + trait_info['db'] + ": " + trait_info['name']) + $('#cofactor2_description').html('<a href=\"' + trait_info['pubmed_link'] + '\">PubMed: ' + trait_info['pubmed_text'] + '</a><br>' + trait_info['description']) + } + $('#select_cofactor2').text("Change Cofactor 2"); + $('#cofactor2_info_container').css("display", "inline"); + } +} + get_trait_data = function(trait_data, textStatus, jqXHR) { var sample, samples, this_trait_vals, trait_sample_data, vals, _i, _len; - console.log("trait:", trait_data[0]); trait_sample_data = trait_data[1]; - console.log("trait_sample_data:", trait_sample_data); - samples = $('input[name=allsamples]').val().split(" "); + if ( $('input[name=allsamples]').length ) { + samples = $('input[name=allsamples]').val().split(" "); + } else { + samples = js_data.indIDs + } + sample_vals = []; vals = []; for (_i = 0, _len = samples.length; _i < _len; _i++) { sample = samples[_i]; - if (__indexOf.call(Object.keys(trait_sample_data), sample) >= 0) { - vals.push(parseFloat(trait_sample_data[sample])); + if (sample in trait_sample_data) { + sample_vals.push(sample + ":" + parseFloat(trait_sample_data[sample])) + vals.push(parseFloat(trait_sample_data[sample])) } else { - vals.push(null); + sample_vals.push(null) + vals.push(null) } } - if ($('input[name=samples]').length < 1) { - $('#hidden_inputs').append('<input type="hidden" name="samples" value="[' + samples.toString() + ']" />'); + if ( $('input[name=allsamples]').length ) { + if ($('input[name=samples]').length < 1) { + $('#hidden_inputs').append('<input type="hidden" name="samples" value="[' + samples.toString() + ']" />'); + } + $('#hidden_inputs').append('<input type="hidden" name="vals" value="[' + vals.toString() + ']" />'); + this_trait_vals = get_this_trait_vals(samples); + return color_by_trait(trait_sample_data); + } else{ + populate_cofactor_info(trait_data[0]) + sorted = vals.slice().sort(function(a,b){return a-b}) + ranks = vals.slice().map(function(v){ return sorted.indexOf(v)+1 }); + sample_ranks = [] + for (_i = 0; _i < samples.length; _i++){ + if (samples[_i] in trait_sample_data){ + sample_ranks.push(samples[_i] + ":" + ranks[_i]) + } else { + sample_ranks.push(null) + } + } + + if ($('input[name=selecting_which_cofactor]').val() == "1"){ + $('input[name=cofactor1_vals]').val(sample_vals) + $('input[name=ranked_cofactor1_vals]').val(sample_ranks) + } else { + $('input[name=cofactor2_vals]').val(sample_vals) + $('input[name=ranked_cofactor2_vals]').val(sample_ranks) + } + chartupdatedata(); + chartupdate(); + return false } - $('#hidden_inputs').append('<input type="hidden" name="vals" value="[' + vals.toString() + ']" />'); - this_trait_vals = get_this_trait_vals(samples); - console.log("THE LENGTH IS:", $('input[name=vals]').length); - return color_by_trait(trait_sample_data); }; get_this_trait_vals = function(samples) { @@ -215,14 +268,17 @@ process_traits = function(trait_data, textStatus, jqXHR) { } the_html += "</tbody>"; the_html += "</table>"; + the_html += "<div id=\"collection_list_html\" style=\"display: none;\">" + the_html += collection_list + the_html += "</div>" the_html += "<script type='text/javascript' src='/static/new/javascript/get_traits_from_collection.js'></script>" $("#collections_holder").html(the_html); return $('#collections_holder').colorbox.resize(); }; back_to_collections = function() { - console.log("collection_list:", collection_list); - $("#collections_holder").html(collection_list); + collection_list_html = $('#collection_list_html').html() + $("#collections_holder").html(collection_list_html); $(document).on("click", ".collection_line", collection_click); return $('#collections_holder').colorbox.resize(); }; diff --git a/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js b/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js index 49fd53b1..97d768c8 100644 --- a/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js +++ b/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js @@ -25,7 +25,7 @@ redraw_prob_plot = function(samples, sample_group) { var container, h, margin, totalh, totalw, w; - h = 600; + h = 370; w = 600; margin = { left: 60, @@ -71,11 +71,11 @@ })(); //ZS: 0.1 indicates buffer, increase to increase buffer y_domain = [sorted_values[0] - (sorted_values.slice(-1)[0] - sorted_values[0])*0.1, sorted_values.slice(-1)[0] + (sorted_values.slice(-1)[0] - sorted_values[0])*0.1] - sw_result = ShapiroWilkW(sorted_values); - W = sw_result.w.toFixed(3); - pvalue = sw_result.p.toFixed(3); - pvalue_str = pvalue > 0.05 ? pvalue.toString() : "<span style='color:red'>" + pvalue + "</span>"; - test_str = "Shapiro-Wilk test statistic is " + W + " (p = " + pvalue_str + ")"; + //sw_result = ShapiroWilkW(sorted_values); + //W = sw_result.w.toFixed(3); + //pvalue = sw_result.p.toFixed(3); + //pvalue_str = pvalue > 0.05 ? pvalue.toString() : "<span style='color:red'>" + pvalue + "</span>"; + //test_str = "Shapiro-Wilk test statistic is " + W + " (p = " + pvalue_str + ")"; z_scores = get_z_scores(sorted_values.length); //ZS: 0.1 indicates buffer, increase to increase buffer x_domain = [z_scores[0] - (z_scores.slice(-1)[0] - z_scores[0])*0.1, z_scores.slice(-1)[0] + (z_scores.slice(-1)[0] - z_scores[0])*0.1] @@ -106,7 +106,6 @@ }; }; data = [make_data('samples_primary'), make_data('samples_other'), make_data('samples_all')]; - console.log("THE DATA IS:", data); x_values = {} y_values = {} point_names = {} diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 5e2ecc33..e9dd3c9d 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -247,6 +247,9 @@ } root.bar_data[0]['x'] = trait_samples Plotly.newPlot('bar_chart', root.bar_data, root.bar_layout); + Plotly.relayout('bar_chart', { + 'yaxis.autorange': true + }); }; redraw_box_plot = function() { @@ -564,7 +567,7 @@ log_normalize_data = function() { return $('.trait_value_input').each((function(_this) { return function(_index, element) { - current_value = $(element).data("value"); + current_value = parseFloat($(element).data("value")) + 1; if(isNaN(current_value)) { return current_value } else { @@ -575,6 +578,20 @@ })(this)); }; + sqrt_normalize_data = function() { + return $('.trait_value_input').each((function(_this) { + return function(_index, element) { + current_value = parseFloat($(element).data("value")) + 1; + if(isNaN(current_value)) { + return current_value + } else { + $(element).val(Math.sqrt(current_value).toFixed(3)); + return Math.sqrt(current_value).toFixed(3) + } + }; + })(this)); + }; + qnorm_data = function() { return $('.trait_value_input').each((function(_this) { return function(_index, element) { @@ -596,6 +613,12 @@ $('input[name="transform"]').val("log2") } } + else if ($('#norm_method option:selected').val() == 'sqrt'){ + if ($('input[name="transform"]').val() != "sqrt") { + sqrt_normalize_data() + $('input[name="transform"]').val("sqrt") + } + } else if ($('#norm_method option:selected').val() == 'qnorm'){ if ($('input[name="transform"]').val() != "qnorm") { qnorm_data() @@ -866,6 +889,7 @@ max_y_val = Math.max(...positive_error_vals) if (min_y_val == 0) { + range_top = max_y_val + Math.abs(max_y_val)*0.1 range_bottom = 0; } else { range_top = max_y_val + Math.abs(max_y_val)*0.1 diff --git a/wqflask/wqflask/templates/collections/add.html b/wqflask/wqflask/templates/collections/add.html index d45aa015..603947f4 100644 --- a/wqflask/wqflask/templates/collections/add.html +++ b/wqflask/wqflask/templates/collections/add.html @@ -1,36 +1,38 @@ <div id="myModal"> <div class="modal-header"> - <h3>Add to collection</h3> - <p>You have two choices: Create and name a collection, - or add the traits to an existing collection.</p> + <h2>Define or Add to Collection</h2> + <p>You have two choices: Name a new collection + or add to an existing collection.</p> </div> - <div class="modal-body"> + <div class="modal-body" style="margin-left: 20px;"> <form action="/collections/new" data-validate="parsley" id="add_form"> <input type="hidden" name="traits" value="{{ traits }}" /> <fieldset> - <legend>Create a new named collection</legend> - <label>New collection name</label> - <input type="text" name="new_collection" placeholder="Name of new collection..." - data-trigger="change" data-minlength="5" data-maxlength="50"> - <span class="help-block">Type the name of the new collection.</span> + <legend>1. Create a new collection</legend> + <div style="margin-left: 20px;"> + <!--<label>Collection name:</label>--> + <input type="text" name="new_collection" placeholder=" Name of new collection..." + data-trigger="change" data-minlength="5" data-maxlength="50" style="width: 100%"> + <button type="submit" name="create_new" class="btn btn-primary" style="margin-top: 20px;">Create collection</button> {% if uc is not defined %} <span class="help-block" style="color:red;">This collection will be saved to this computer for 5 days.</span> {% endif %} - <button type="submit" name="create_new" class="btn">Create and add traits</button> + </div> </fieldset> <hr /> <fieldset> - <legend>Or add to an existing collection</legend> - <label>Existing collection name</label> - + <legend>2. Add to an existing collection</legend> + <div style="margin-left: 20px;"> + <!--<label>Existing collection name:</label>--> <select name="existing_collection" class="form-control"> + <option selected disabled>Select Collection</option> {% for col in collections %} <option value="{{ col.id }}:{{ col.name }}">{{ col.name }}</option> {% endfor %} </select> <br /> - - <button type="submit" name="add_to_existing" class="btn">Add to existing collection</button> + <button type="submit" name="add_to_existing" class="btn btn-primary">Add to existing collection</button> + </div> </fieldset> </form> </div> diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index 11c33673..64d5a676 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -3,7 +3,6 @@ {% block css %} <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" /> - <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" /> <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" /> {% endblock %} {% block content %} diff --git a/wqflask/wqflask/templates/collections/view.html b/wqflask/wqflask/templates/collections/view.html index cae03b4a..864299a2 100644 --- a/wqflask/wqflask/templates/collections/view.html +++ b/wqflask/wqflask/templates/collections/view.html @@ -29,10 +29,6 @@ {{ this_trait.name }}:{{ this_trait.dataset.name }}, {% endfor %}" > - <button id="delete" class="btn btn-danger submit_special" data-url="/collections/delete" title="Delete this collection" > - Delete this collection - </button> - <button id="corr_matrix" class="btn btn-primary submit_special" data-url="/corr_matrix" title="Correlation Matrix" > Correlation Matrix @@ -58,6 +54,15 @@ Heatmap </button> + <button id="comp_bar_chart" class="btn btn-primary submit_special" data-url="/comparison_bar_chart" title="Comparison Bar Chart" > + Comparison Bar Chart + </button> + + + <button id="delete" class="btn btn-danger submit_special" style="margin-left: 15px;" data-url="/collections/delete" title="Delete this collection" > + Delete Collection + </button> + </form> </div> @@ -66,8 +71,8 @@ <button class="btn btn-default" id="select_all"><span class="glyphicon glyphicon-ok"></span> Select All</button> <button class="btn btn-default" id="deselect_all"><span class="glyphicon glyphicon-remove"></span> Deselect All</button> <button class="btn btn-default" id="invert"><span class="glyphicon glyphicon-resize-vertical"></span> Invert</button> - <button class="btn" id="add" disabled="disabled"><i class="icon-plus-sign"></i> Add Record to Other Collection</button> - <button class="btn" id="remove" disabled="disabled"><i class="icon-minus-sign"></i> Remove Record</button> + <button class="btn btn-danger" id="remove" disabled="disabled"><i class="icon-minus-sign"></i> Delete From Collection</button> + <button class="btn" id="add" disabled="disabled"><i class="icon-plus-sign"></i> Copy Record to Other Collection</button> <br /> <br /> <form id="export_form" method="POST" action="/export_traits_csv"> @@ -246,6 +251,14 @@ url = $(this).data("url") return submit_special(url) }); + $("#comp_bar_chart").on("click", function() { + traits = $("#trait_table input:checked").map(function() { + return $(this).val(); + }).get(); + $("#trait_list").val(traits) + url = $(this).data("url") + return submit_special(url) + }); }); </script> diff --git a/wqflask/wqflask/templates/comparison_bar_chart.html b/wqflask/wqflask/templates/comparison_bar_chart.html new file mode 100644 index 00000000..033ff0a4 --- /dev/null +++ b/wqflask/wqflask/templates/comparison_bar_chart.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} +{% block title %}Comparison Bar Chart{% endblock %} +{% block css %} + <link rel="stylesheet" type="text/css" href="/static/new/css/d3-tip.min.css" /> + <link rel="stylesheet" type="text/css" href="/static/new/css/panelutil.css" /> +{% endblock %} +{% block content %} <!-- Start of body --> + + {{ header("Comparison Bar Chart") }} + + <div class="container"> + <div> + <h3> + The following is a grouped bar chart with the sample values for each selected trait. + </h3> + </div> + <div id="chart_container"> + <div id="comp_bar_chart"></div> + </div> + + </div> + + <!-- End of body --> + +{% endblock %} + +{% block js %} + <script> + js_data = {{ js_data | safe }} + </script> + + <script language="javascript" type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/js_external/d3-tip.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/panelutil.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> + <script type="text/javascript" src="/static/new/js_external/plotly-latest.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/comparison_bar_chart.js"></script> + +{% endblock %}
\ No newline at end of file diff --git a/wqflask/wqflask/templates/corr_scatterplot.html b/wqflask/wqflask/templates/corr_scatterplot.html index e0f017c2..6451fda5 100644 --- a/wqflask/wqflask/templates/corr_scatterplot.html +++ b/wqflask/wqflask/templates/corr_scatterplot.html @@ -12,124 +12,74 @@ <div class="container-fluid"> - <h2>Correlation Scatterplot</h2> + <input type="hidden" name="cofactor1_vals"></input> + <input type="hidden" name="ranked_cofactor1_vals"></input> + <input type="hidden" name="cofactor2_vals"></input> + <input type="hidden" name="ranked_cofactor2_vals"></input> + <input type="hidden" name="selecting_which_cofactor"></input> - <div style="margin-left: 0px;"> - {% if trait_1.dataset.type == "ProbeSet" %} - <div> - X axis: - <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> - {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.tissue + " " + trait_1.dataset.name + ": " + trait_1.name|string}} - </a> - </div> - <div> - [{{trait_1.symbol}} on {{trait_1.location_repr}} Mb] - {{trait_1.description_display}} - </div> - {% elif trait_1.dataset.type == "Publish" %} - <div> - X axis: - <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> - {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.name + ": " + trait_1.name|string}} - </a> - </div> - <div> - <a href="{{trait_1.pubmed_link}}">PubMed: {{trait_1.pubmed_text}}</a> - {{trait_1.description_display}} - </div> - {% endif %} + <h2>Correlation Scatterplot</h2> - <br/> + <table class="table"> + <tr> + <td style="vertical-align: middle;">Width <input class="chartupdatewh" id="width" type="text" value="800" style="width: 44px; height: 22px;"> px</td> + <td style="vertical-align: middle;">Height <input class="chartupdatewh" id="height" type="text" value="700" style="width: 44px; height: 22px;"> px</td> + </tr> + </table> - {% if trait_2.dataset.type == "ProbeSet" %} - <div> - Y axis: - <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> - {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.tissue + " " + trait_2.dataset.name + ": " + trait_2.name|string}} - </a> - </div> - <div> - [{{trait_2.symbol}} on {{trait_2.location_repr}} Mb] - {{trait_2.description_display}} - </div> - {% elif trait_2.dataset.type == "Publish" %} - <div> - Y axis: - <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> - {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.name + ": " + trait_2.name|string}} - </a> - </div> - <div> - <a href="{{trait_2.pubmed_link}}">PubMed: {{trait_2.pubmed_text}}</a> - {{trait_2.description_display}} + <div> + <button type="button" class="btn btn-default" id="select_cofactor1"> + Select Cofactor 1 + </button> +<!-- + <select class="cofactor1_type"> + <option value="color">Color</option> + <option value="size">Size</option> + </select> +--> + <div id="cofactor2_button" style="margin-left: 10px; display: none;"> + <button type="button" class="btn btn-default" id="select_cofactor2"> + Add a Second Cofactor? + </button> +<!-- + <select class="cofactor2_type"> + <option value="color">Color</option> + <option value="size" selected="selected">Size</option> + </select> +--> </div> - {% endif %} - - <br/> + </div> + <div id="collections_holder_wrapper" style="display:none;"> + <div id="collections_holder"></div> + </div> + <br/> - {% if trait_3 %} - {% if trait_3.dataset.type == "ProbeSet" %} + <div id="cofactor1_info_container" style="margin-left: 0px; display: none;"> <div> - Cofactor: - <a href="{{url_for('show_trait_page', trait_id = trait_3.name, dataset = trait_3.dataset.name)}}"> - {{trait_3.dataset.group.species + " " + trait_3.dataset.group.name + " " + trait_3.dataset.tissue + " " + trait_3.dataset.name + ": " + trait_3.name|string}} - </a> + <b>Cofactor 1</b>: <a id="cofactor1_trait_link" href="#"></a> </div> - <div> - [{{trait_3.symbol}} on {{trait_3.location_repr}} Mb] - {{trait_3.description_display}} + <div id="cofactor1_description"></div> + <br> + <div style="margin-bottom: 10px;"> + <b>Cofactor 1 Color Range:</b> + <input class="chartupdatedata" id="cocolorfrom" type="color" value="#D9D9D9"> + <input class="chartupdatedata" id="cocolorto" type="color" value="#000000"> </div> - {% elif trait_3.dataset.type == "Publish" %} + </div> + + <div id="cofactor2_info_container" style="margin-left: 0px; display: none;"> + <hr> <div> - Cofactor: - <a href="{{url_for('show_trait_page', trait_id = trait_3.name, dataset = trait_3.dataset.name)}}"> - {{trait_3.dataset.group.species + " " + trait_3.dataset.group.name + " " + trait_3.dataset.name + ": " + trait_3.name|string}} - </a> + <b>Cofactor 2</b>: <a id="cofactor2_trait_link" href="#"></a> </div> - <div> - <a href="{{trait_3.pubmed_link}}">PubMed: {{trait_3.pubmed_text}}</a> - {{trait_3.description_display}} + <div id="cofactor2_description"></div> + <br> + <div style="margin-bottom: 20px;"> + <b>Cofactor 2 corresponds to point radius</b> </div> - {% endif %} - {% endif %} - - <input class="chartupdatedata" id="cocolorfrom" type="color" value="#000000"> - <input class="chartupdatedata" id="cocolorto" type="color" value="#000000"> - + <br> </div> - <br> - - <table class="table"> - <tr> - <td style="vertical-align: middle;">Width <input class="chartupdatewh" id="width" type="text" value="1000" style="width: 44px; height: 22px;"> px</td> - <td style="vertical-align: middle;">Height <input class="chartupdatewh" id="height" type="text" value="800" style="width: 44px; height: 22px;"> px</td> - </tr> - </table> - - <table class="table"> - <tr> - <td style="vertical-align: middle;">Label - <input class="chartupdate" id="labelcolor" type="color" value="#000000"> - <input class="chartupdate" id="labelfont" type="text" value="16" style="width: 44px; height: 22px;"> px - </td> - <td style="vertical-align: middle;">Number - <input class="chartupdate" id="numbercolor" type="color" value="#000000"> - <input class="chartupdate" id="numberfont" type="text" value="16" style="width: 44px; height: 22px;"> px - </td> - <td style="vertical-align: middle;">Axis - <input class="chartupdate" id="axiscolor" type="color" value="#000000"> - <input class="chartupdate" id="axiswidth" type="text" value="2" style="width: 44px; height: 22px;"> px - </td> - <td style="vertical-align: middle;">Line - <input class="chartupdate" id="linecolor" type="color" value="#8fbbda"> - <input class="chartupdate" id="linewidth" type="text" value="1" style="width: 44px; height: 22px;"> px - </td> - </tr> - </table> - - <br> - <ul class="nav nav-tabs"> <li class="active"> <a href="#tp1" data-toggle="tab">Pearson</a> @@ -143,17 +93,11 @@ <div class="tab-pane active" id="tp1"> <br> - <div> - <a id="a_svg_pcs" href="#" onclick="javascript:saveassvg_pcs();" class="btn btn-primary">Save as SVG</a> - </div> - <div style="width: 1000px; text-align: center;"> - <h2>Pearson Correlation Scatterplot</h2> - </div> - <div id="scatterplot2"> - <svg id="svg_pcs" style="width: 1000px; height: 800px; margin-left: 10px;"></svg> - </div> + <div id="scatterplot2"></div> <br> - <table class="table table-hover table-striped table-bordered" style="width: 200px; margin-left: 80px; text-align: right;"> + <div class="row" style="width: 70%;"> + <div class="col-xs-3"> + <table class="table table-hover table-striped table-bordered" style="width: 80%; margin-left: 60px; text-align: right;"> <thead> <tr><th style="text-align: right;">Statistic</th><th style="text-align: right;">Value</th></tr> </thead> @@ -187,53 +131,147 @@ </tr> </tbody> </table> - </div> - - <div class="tab-pane" id="tp2"> + </div> + <div class="col-xs-9"> + {% if trait_1.dataset.type == "ProbeSet" %} + <div> + X axis: + <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> + {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.tissue + " " + trait_1.dataset.name + ": " + trait_1.name|string}} + </a> + </div> + <div> + [{{trait_1.symbol}} on {{trait_1.location_repr}} Mb] + {{trait_1.description_display}} + </div> + {% elif trait_1.dataset.type == "Publish" %} + <div> + X axis: + <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> + {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.name + ": " + trait_1.name|string}} + </a> + </div> + <div> + <a href="{{trait_1.pubmed_link}}">PubMed: {{trait_1.pubmed_text}}</a> + {{trait_1.description_display}} + </div> + {% endif %} - <br> + <br/> - <div> - <a id="a_svg_srcs" href="#" onclick="javascript:saveassvg_srcs();" class="btn btn-primary">Save as SVG</a> - </div> - <div style="width: 1000px; text-align: center;"> - <h2>Spearman Rank Correlation Scatterplot</h2> + {% if trait_2.dataset.type == "ProbeSet" %} + <div> + Y axis: + <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> + {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.tissue + " " + trait_2.dataset.name + ": " + trait_2.name|string}} + </a> + </div> + <div> + [{{trait_2.symbol}} on {{trait_2.location_repr}} Mb] + {{trait_2.description_display}} + </div> + {% elif trait_2.dataset.type == "Publish" %} + <div> + Y axis: + <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> + {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.name + ": " + trait_2.name|string}} + </a> + </div> + <div> + <a href="{{trait_2.pubmed_link}}">PubMed: {{trait_2.pubmed_text}}</a> + {{trait_2.description_display}} + </div> + {% endif %} </div> - <div id="srscatterplot2"> - <svg id="svg_srcs" style="width: 1000px; height: 800px; margin-left: 10px;"></svg> </div> + </div> + <div class="tab-pane" id="tp2"> + <br> + <div id="srscatterplot2"></div> <br> + <div class="row" style="width: 70%;"> + <div class="col-xs-3"> + <table class="table table-hover table-striped table-bordered" style="width: 80%; margin-left: 60px; text-align: right;"> + <thead> + <tr><th style="text-align: right;">Statistic</th><th style="text-align: right;">Value</th></tr> + </thead> + <tbody> + <tr> + <td>Number</td> + <td>{{jsdata.num_overlap}}</td> + </tr> + <tr> + <td>Slope</td> + <td>{{'%0.3f' % jsdata.srslope}}</td> + </tr> + <tr> + <td>Intercept</td> + <td>{{'%0.3f' % jsdata.srintercept}}</td> + </tr> + <tr> + <td>r value</td> + <td>{{'%0.3f' % jsdata.srr_value}}</td> + </tr> + <tr> + <td>P value</td> + <td>{% if jsdata.srp_value < 0.001 %}{{'%0.3e' % jsdata.srp_value}}{% else %}{{'%0.3f' % jsdata.srp_value}}{% endif %}</td> + </tr> + </tbody> + </table> + </div> + <div class="col-xs-9"> + {% if trait_1.dataset.type == "ProbeSet" %} + <div> + X axis: + <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> + {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.tissue + " " + trait_1.dataset.name + ": " + trait_1.name|string}} + </a> + </div> + <div> + [{{trait_1.symbol}} on {{trait_1.location_repr}} Mb] + {{trait_1.description_display}} + </div> + {% elif trait_1.dataset.type == "Publish" %} + <div> + X axis: + <a href="{{url_for('show_trait_page', trait_id = trait_1.name, dataset = trait_1.dataset.name)}}"> + {{trait_1.dataset.group.species + " " + trait_1.dataset.group.name + " " + trait_1.dataset.name + ": " + trait_1.name|string}} + </a> + </div> + <div> + <a href="{{trait_1.pubmed_link}}">PubMed: {{trait_1.pubmed_text}}</a> + {{trait_1.description_display}} + </div> + {% endif %} - <table class="table table-hover table-striped table-bordered" style="width: 200px; margin-left: 80px; text-align: right;"> - <thead> - <tr><th style="text-align: right;">Statistic</th><th style="text-align: right;">Value</th></tr> - </thead> - <tbody> - <tr> - <td>Number</td> - <td>{{jsdata.num_overlap}}</td> - </tr> - <tr> - <td>Slope</td> - <td>{{'%0.3f' % jsdata.srslope}}</td> - </tr> - <tr> - <td>Intercept</td> - <td>{{'%0.3f' % jsdata.srintercept}}</td> - </tr> - <tr> - <td>r value</td> - <td>{{'%0.3f' % jsdata.srr_value}}</td> - </tr> - <tr> - <td>P value</td> - <td>{% if jsdata.srp_value < 0.001 %}{{'%0.3e' % jsdata.srp_value}}{% else %}{{'%0.3f' % jsdata.srp_value}}{% endif %}</td> - </tr> - </tbody> - </table> - </div> + <br/> + {% if trait_2.dataset.type == "ProbeSet" %} + <div> + Y axis: + <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> + {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.tissue + " " + trait_2.dataset.name + ": " + trait_2.name|string}} + </a> + </div> + <div> + [{{trait_2.symbol}} on {{trait_2.location_repr}} Mb] + {{trait_2.description_display}} + </div> + {% elif trait_2.dataset.type == "Publish" %} + <div> + Y axis: + <a href="{{url_for('show_trait_page', trait_id = trait_2.name, dataset = trait_2.dataset.name)}}"> + {{trait_2.dataset.group.species + " " + trait_2.dataset.group.name + " " + trait_2.dataset.name + ": " + trait_2.name|string}} + </a> + </div> + <div> + <a href="{{trait_2.pubmed_link}}">PubMed: {{trait_2.pubmed_text}}</a> + {{trait_2.description_display}} + </div> + {% endif %} + </div> + </div> </div> </div> @@ -250,5 +288,7 @@ <script language="javascript" type="text/javascript" src="/static/new/js_external/d3-tip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/colorbrewer.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/panelutil.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/javascript/get_traits_from_collection.js"></script> + <script type="text/javascript" src="/static/new/js_external/plotly-latest.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/javascript/draw_corr_scatterplot.js"></script> {% endblock %} diff --git a/wqflask/wqflask/templates/correlation_matrix.html b/wqflask/wqflask/templates/correlation_matrix.html index c4668e05..e4fd3136 100644 --- a/wqflask/wqflask/templates/correlation_matrix.html +++ b/wqflask/wqflask/templates/correlation_matrix.html @@ -1,8 +1,6 @@ {% extends "base.html" %} {% block css %} <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" /> - <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" /> - <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" /> <link rel="stylesheet" type="text/css" href="/static/new/css/corr_matrix.css" /> <link rel="stylesheet" type="text/css" href="/static/new/css/panelutil.css" /> <link rel="stylesheet" type="text/css" href="/static/new/css/d3-tip.min.css" /> @@ -107,8 +105,6 @@ <script type="text/javascript" src="/static/new/js_external/d3-tip.min.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script> <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.min.js"></script> - <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script> - <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> <script type="text/javascript" src="/static/new/javascript/panelutil.js"></script> <script language="javascript" type="text/javascript" src="/static/new/js_external/chroma.js"></script> diff --git a/wqflask/wqflask/templates/gsearch_gene.html b/wqflask/wqflask/templates/gsearch_gene.html index 6f2ad0b8..0612bfcc 100644 --- a/wqflask/wqflask/templates/gsearch_gene.html +++ b/wqflask/wqflask/templates/gsearch_gene.html @@ -43,26 +43,24 @@ <th data-export="Location">Location</th> <th data-export="Mean">Mean</th> <th data-export="Max LRS">Max LRS <a href="http://genenetwork.org//glossary.html#LRS" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> - <th data-export="Max LRS Location">Max LRS Location</th> <th data-export="Additive Effect">Additive Effect <a href="http://genenetwork.org//glossary.html#A" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> </tr> </thead> <tbody> {% for this_trait in trait_list %} - <tr id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <td align="center" style="padding-right: 0px; padding-left: 5px;"><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></td> + <tr id="trait:{{ this_trait.name }}:{{ this_trait.dataset }}"> + <td align="center" style="padding-right: 0px; padding-left: 5px;"><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset)) }}"></td> <td align="right" data-export="{{ loop.index }}">{{ loop.index }}</td> - <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> - <td data-export="{{ this_trait.dataset.group.species }}">{{ this_trait.dataset.group.species }}</td> - <td data-export="{{ this_trait.dataset.group.name }}">{{ this_trait.dataset.group.name }}</td> - <td data-export="{{ this_trait.dataset.tissue }}">{{ this_trait.dataset.tissue }}</td> - <td data-export="{{ this_trait.dataset.name }}">{{ this_trait.dataset.name }}</td> + <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset)}}">{{ this_trait.name }}</a></td> + <td data-export="{{ this_trait.species }}">{{ this_trait.species }}</td> + <td data-export="{{ this_trait.group }}">{{ this_trait.group }}</td> + <td data-export="{{ this_trait.tissue }}">{{ this_trait.tissue }}</td> + <td data-export="{{ this_trait.dataset }}">{{ this_trait.dataset }}</td> <td data-export="{{ this_trait.symbol }}">{{ this_trait.symbol }}</td> - <td data-export="{{ this_trait.description_display }}">{{ this_trait.description_display }}</td> + <td data-export="{{ this_trait.description }}">{{ this_trait.description }}</td> <td data-export="{{ this_trait.location_repr }}" align="right">{{ this_trait.location_repr }}</td> <td data-export="{{ '%0.3f' % this_trait.mean|float }}" align="right">{{ '%0.3f' % this_trait.mean|float }}</td> <td data-export="{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> - <td data-export="{{ this_trait.LRS_location_repr }}" align="right">{{ this_trait.LRS_location_repr }}</td> <td data-export="{% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %}</td> </tr> {% endfor %} @@ -81,7 +79,6 @@ <th>Location</th> <th>Mean</th> <th data-export="Max LRS">Max LRS <a href="http://genenetwork.org//glossary.html#LRS" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> - <th data-export="LRS Location">Max LRS Location</th> <th data-export="Additive Effect">Additive Effect <a href="http://genenetwork.org//glossary.html#A" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> </tr> </tfoot> @@ -142,7 +139,6 @@ { "type": "natural", "width": "7%" }, { "type": "natural", "width": "4%" }, { "type": "natural", "width": "5%" }, - { "type": "natural", "width": "7%" }, { "type": "natural", "width": "5%" } ], "columnDefs": [ diff --git a/wqflask/wqflask/templates/gsearch_pheno.html b/wqflask/wqflask/templates/gsearch_pheno.html index 7a8ca07b..c2cbdadd 100644 --- a/wqflask/wqflask/templates/gsearch_pheno.html +++ b/wqflask/wqflask/templates/gsearch_pheno.html @@ -40,23 +40,21 @@ <th data-export="Authors">Authors</th> <th data-export="Year">Year</th> <th data-export="Max LRS">Max LRS <a href="http://genenetwork.org//glossary.html#LRS" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> - <th data-export="LRS Location">Max LRS Location</th> <th data-export="Additive Effect">Additive Effect <a href="http://genenetwork.org//glossary.html#A" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> </tr> </thead> <tbody> {% for this_trait in trait_list %} - <tr id="trait:{{ this_trait.name }}:{{ this_trait.dataset.name }}"> - <td align="center" style="padding-right: 0px; padding-left: 5px;"><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset.name)) }}"></td> + <tr id="trait:{{ this_trait.name }}:{{ this_trait.dataset }}"> + <td align="center" style="padding-right: 0px; padding-left: 5px;"><input type="checkbox" name="searchResult" class="checkbox trait_checkbox" value="{{ data_hmac('{}:{}'.format(this_trait.name, this_trait.dataset)) }}"></td> <td align="right" data-export="{{ loop.index }}">{{ loop.index }}</td> - <td data-export="{{ this_trait.dataset.group.species }}">{{ this_trait.dataset.group.species }}</td> - <td data-export="{{ this_trait.dataset.group.name }}">{{ this_trait.dataset.group.name }}</td> - <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset.name)}}">{{ this_trait.name }}</a></td> - <td data-export="{{ this_trait.description_display }}">{{ this_trait.description_display }}</td> + <td data-export="{{ this_trait.species }}">{{ this_trait.species }}</td> + <td data-export="{{ this_trait.group }}">{{ this_trait.group }}</td> + <td data-export="{{ this_trait.name }}"><a href="{{ url_for('show_trait_page', trait_id = this_trait.name, dataset = this_trait.dataset)}}">{{ this_trait.name }}</a></td> + <td data-export="{{ this_trait.description }}">{{ this_trait.description }}</td> <td data-export="{{ this_trait.authors }}">{{ this_trait.authors }}</td> <td data-export="{{ this_trait.pubmed_text }}" data-order="{{ this_trait.pubmed_text }}"><a href="{{ this_trait.pubmed_link }}">{{ this_trait.pubmed_text }}</a></td> <td data-export="{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}" align="right">{% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td> - <td data-export="{{ this_trait.LRS_location_repr }}" align="right">{{ this_trait.LRS_location_repr }}</td> <td data-export="{% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %}" align="right">{% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %}</td> </tr> {% endfor %} @@ -72,7 +70,6 @@ <th>Authors</th> <th>Year</th> <th data-export="Max LRS">Max LRS <a href="http://genenetwork.org//glossary.html#LRS" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> - <th data-export="LRS Location">Max LRS Location</th> <th data-export="Additive Effect">Additive Effect <a href="http://genenetwork.org//glossary.html#A" target="_blank"><img style="width: 15px; height: 15px;" src="/static/new/images/question_mark.jpg"></a></th> </tr> </tfoot> @@ -135,7 +132,6 @@ { "type": "natural", "width": "25%"}, { "type": "natural" }, { "type": "natural", "width": "8%"}, - { "type": "natural", "width": "12%"}, { "type": "natural" } ], "columnDefs": [ diff --git a/wqflask/wqflask/templates/show_trait_edit_data.html b/wqflask/wqflask/templates/show_trait_edit_data.html index 482d1d88..ac2f1078 100644 --- a/wqflask/wqflask/templates/show_trait_edit_data.html +++ b/wqflask/wqflask/templates/show_trait_edit_data.html @@ -56,6 +56,7 @@ <select id="norm_method" class="select optional span2"> <option value="log2">Log2</option> <option value="qnorm">Quantile</option> + <option value="sqrt">Square Root</option> </select> </div> <!-- diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html index a54b595b..495a266e 100644 --- a/wqflask/wqflask/templates/show_trait_mapping_tools.html +++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html @@ -14,9 +14,11 @@ <li> <a href="#rqtl_geno" data-toggle="tab">R/qtl</a> </li> +<!-- <li> <a href="#pylmm" data-toggle="tab">pyLMM</a> </li> +--> {% endif %} {% for mapping_method in dataset.group.mapping_names %} {% if mapping_method == "GEMMA" %} @@ -74,6 +76,12 @@ {% if g.user_session.logged_in %} {% if g.user_session.num_collections < 1 %} No collections available. Please add traits to a collection to use them as covariates. + {% else %} + <div style="margin-bottom: 10px;" class="btn-group" role="group"> + <button type="button" id="select_covariates" class="btn btn-default">Select</button> + <button type="button" id="remove_covariates" class="btn btn-default">Remove</button> + </div> + <textarea rows="3" cols="20" readonly placeholder="No covariates selected" style="overflow-y: scroll; resize: none;" class="selected_covariates"></textarea> {% endif %} {% elif g.cookie_session.display_num_collections() == "" %} No collections available. Please add traits to a collection to use them as covariates. @@ -330,8 +338,10 @@ <dd>Interval mapping is a process in which the statistical significance of a hypothetical QTL is evaluated at regular points across a chromosome, even in the absence of explicit genotype data at those points.</dd> <dt>R/qtl</dt> <dd>R/qtl is an extensible, interactive environment for mapping quantitative trait loci (QTL) in experimental crosses.</dd> +<!-- <dt>pyLMM</dt> <dd>pyLMM is a fast and lightweight linear mixed-model (LMM) solver for use in genome-wide association studies (GWAS).</dd> +--> {% endif %} </dl> </div> diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index 830c7864..d6f39e83 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -49,7 +49,7 @@ def timestamp(): class AnonUser(object): """Anonymous user handling""" - cookie_name = 'anon_user_v8' + cookie_name = 'anon_user_v1' def __init__(self): self.cookie = request.cookies.get(self.cookie_name) @@ -60,23 +60,10 @@ class AnonUser(object): else: logger.debug("CREATING NEW ANON COOKIE") self.anon_id, self.cookie = create_signed_cookie() + res = flask.make_response() + res.set_cookie(self.cookie_name, self.cookie) self.key = "anon_collection:v1:{}".format(self.anon_id) - #ZS: This was originally the commented out function below - # For some reason I don't yet understand the commented out code works on production, - # but wouldn't set cookies for staging and my branch. The new code (using @app.after_request) seems to work. - @app.after_request - def set_cookie(response): - if self.cookie: - pass - else: - response.set_cookie(self.cookie_name, self.cookie) - return response - - #@after.after_this_request - #def set_cookie(response): - # response.set_cookie(self.cookie_name, self.cookie) - def add_collection(self, new_collection): collection_dict = dict(name = new_collection.name, created_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p'), diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 2089f9de..ae333e73 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -43,6 +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.comparison_bar_chart import comparison_bar_chart from wqflask.marker_regression import marker_regression from wqflask.marker_regression import marker_regression_gn1 from wqflask.network_graph import network_graph @@ -464,6 +465,27 @@ def heatmap_page(): return rendered_template +@app.route("/comparison_bar_chart", methods=('POST',)) +def comp_bar_chart_page(): + logger.info("In comp bar chart, 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 = comparison_bar_chart.ComparisonBarChart(request.form) + template_vars.js_data = json.dumps(template_vars.js_data, + default=json_default_handler, + indent=" ") + + result = template_vars.__dict__ + rendered_template = render_template("comparison_bar_chart.html", **result) + else: + rendered_template = render_template("empty_collection.html", **{'tool':'Comparison Bar Chart'}) + + return rendered_template + @app.route("/mapping_results_container") def mapping_results_container_page(): return render_template("mapping_results_container.html") |