From 18ef3e74e7e898cbec200b7ed18b83db26741b62 Mon Sep 17 00:00:00 2001 From: zsloan Date: Tue, 14 Aug 2018 17:19:46 +0000 Subject: Added cofactors to correlation scatterplot and changed it to use Plotly Added Phenogen track to mapping results Added comparison bar chart figure Simplified global search to not build trait/dataset objects, which speeds thing up considerably Fixed correlation matrix to correctly deal with 0 values Fixed issue where anonymous collections couldn't be created if none already existed --- wqflask/base/trait.py | 26 +- wqflask/utility/corr_result_helpers.py | 2 +- wqflask/wqflask/comparison_bar_chart/__init__.py | 0 .../comparison_bar_chart/comparison_bar_chart.py | 118 +++++ wqflask/wqflask/gsearch.py | 58 ++- .../marker_regression/marker_regression_gn1.py | 76 +++- .../static/new/javascript/comparison_bar_chart.js | 25 ++ .../new/javascript/dataset_menu_structure.json | 52 ++- .../static/new/javascript/draw_corr_scatterplot.js | 491 +++++++++++++-------- .../new/javascript/get_traits_from_collection.js | 92 +++- .../new/javascript/plotly_probability_plot.js | 11 +- .../wqflask/static/new/javascript/show_trait.js | 1 + wqflask/wqflask/templates/collections/add.html | 32 +- wqflask/wqflask/templates/collections/list.html | 1 - wqflask/wqflask/templates/collections/view.html | 25 +- .../wqflask/templates/comparison_bar_chart.html | 39 ++ wqflask/wqflask/templates/corr_scatterplot.html | 348 ++++++++------- wqflask/wqflask/templates/correlation_matrix.html | 4 - wqflask/wqflask/templates/gsearch_gene.html | 20 +- wqflask/wqflask/templates/gsearch_pheno.html | 16 +- .../templates/show_trait_mapping_tools.html | 6 + wqflask/wqflask/user_manager.py | 19 +- wqflask/wqflask/views.py | 22 + 23 files changed, 1003 insertions(+), 481 deletions(-) create mode 100644 wqflask/wqflask/comparison_bar_chart/__init__.py create mode 100644 wqflask/wqflask/comparison_bar_chart/comparison_bar_chart.py create mode 100644 wqflask/wqflask/static/new/javascript/comparison_bar_chart.js create mode 100644 wqflask/wqflask/templates/comparison_bar_chart.html (limited to 'wqflask') 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 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" ] @@ -2615,6 +2615,16 @@ "EPFLMouseLiverBothExRMA0413", "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", @@ -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", @@ -3930,10 +3952,6 @@ "BHF2", "BHF2 (Apoe Null) UCLA" ], - [ - "BXD", - "BXD" - ], [ "B6D2RI", "BXD Aged" @@ -3946,13 +3964,17 @@ "BXD-Harvested", "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", @@ -5113,6 +5135,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 '' + obj.point.name + " (" + obj.point.x + ', ' + obj.point.y + ')'; + 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 += "
Cofactor 1: " + cofactor1_dict[sample_names[j]] + } + if (sample_names[j] in cofactor2_dict){ + this_text += "
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= 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 += "
Cofactor 1: " + ranked_cofactor1_dict[sample_names[j]] + } + if (sample_names[j] in ranked_cofactor2_dict){ + this_text += "
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("
")[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("
")[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 = '\r\n'; - preface += '\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/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('PubMed: ' + trait_info['pubmed_text'] + '
' + 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('PubMed: ' + trait_info['pubmed_text'] + '
' + 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(''); + if ( $('input[name=allsamples]').length ) { + if ($('input[name=samples]').length < 1) { + $('#hidden_inputs').append(''); + } + $('#hidden_inputs').append(''); + 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(''); - 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 += ""; the_html += ""; + the_html += "
" + the_html += collection_list + the_html += "
" the_html += "" $("#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 185de8a9..97d768c8 100644 --- a/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js +++ b/wqflask/wqflask/static/new/javascript/plotly_probability_plot.js @@ -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() : "" + pvalue + ""; - 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() : "" + pvalue + ""; + //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 d641dc67..e9dd3c9d 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -889,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 @@
- @@ -66,8 +71,8 @@ - - + +

@@ -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) + }); }); 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 %} + + +{% endblock %} +{% block content %} + + {{ header("Comparison Bar Chart") }} + +
+
+

+ The following is a grouped bar chart with the sample values for each selected trait. +

+
+
+
+
+ +
+ + + +{% endblock %} + +{% block js %} + + + + + + + + + +{% 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 @@
-

Correlation Scatterplot

+ + + + + -
- {% if trait_1.dataset.type == "ProbeSet" %} - -
- [{{trait_1.symbol}} on {{trait_1.location_repr}} Mb] - {{trait_1.description_display}} -
- {% elif trait_1.dataset.type == "Publish" %} - -
- PubMed: {{trait_1.pubmed_text}} - {{trait_1.description_display}} -
- {% endif %} +

Correlation Scatterplot

-
+ + + + + +
Width pxHeight px
- {% if trait_2.dataset.type == "ProbeSet" %} - -
- [{{trait_2.symbol}} on {{trait_2.location_repr}} Mb] - {{trait_2.description_display}} -
- {% elif trait_2.dataset.type == "Publish" %} - -
- PubMed: {{trait_2.pubmed_text}} - {{trait_2.description_display}} +
+ + + - {% endif %} - -
+
+ +
- {% if trait_3 %} - {% if trait_3.dataset.type == "ProbeSet" %} + @@ -250,5 +288,7 @@ + + {% 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 %} - - @@ -107,8 +105,6 @@ - - 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 @@ Location Mean Max LRS - Max LRS Location Additive Effect {% for this_trait in trait_list %} - - + + {{ loop.index }} - {{ this_trait.name }} - {{ this_trait.dataset.group.species }} - {{ this_trait.dataset.group.name }} - {{ this_trait.dataset.tissue }} - {{ this_trait.dataset.name }} + {{ this_trait.name }} + {{ this_trait.species }} + {{ this_trait.group }} + {{ this_trait.tissue }} + {{ this_trait.dataset }} {{ this_trait.symbol }} - {{ this_trait.description_display }} + {{ this_trait.description }} {{ this_trait.location_repr }} {{ '%0.3f' % this_trait.mean|float }} {% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %} - {{ this_trait.LRS_location_repr }} {% if this_trait.additive != "" %}{{ '%0.3f' % this_trait.additive|float }}{% else %}N/A{% endif %} {% endfor %} @@ -81,7 +79,6 @@ Location Mean Max LRS - Max LRS Location Additive Effect @@ -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 @@ Authors Year Max LRS - Max LRS Location Additive Effect {% for this_trait in trait_list %} - - + + {{ loop.index }} - {{ this_trait.dataset.group.species }} - {{ this_trait.dataset.group.name }} - {{ this_trait.name }} - {{ this_trait.description_display }} + {{ this_trait.species }} + {{ this_trait.group }} + {{ this_trait.name }} + {{ this_trait.description }} {{ this_trait.authors }} {{ this_trait.pubmed_text }} {% if this_trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % this_trait.LRS_score_repr|float }}{% else %}N/A{% endif %} - {{ this_trait.LRS_location_repr }} {% if this_trait.additive != "" %}{{ this_trait.additive }}{% else %}N/A{% endif %} {% endfor %} @@ -72,7 +70,6 @@ Authors Year Max LRS - Max LRS Location Additive Effect @@ -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_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html index 53b6646c..495a266e 100644 --- a/wqflask/wqflask/templates/show_trait_mapping_tools.html +++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html @@ -76,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 %} +
+ + +
+ {% endif %} {% elif g.cookie_session.display_num_collections() == "" %} No collections available. Please add traits to a collection to use them as covariates. 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") -- cgit v1.2.3