aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorzsloan2016-03-24 19:49:08 +0000
committerzsloan2016-03-24 19:49:08 +0000
commitb216de9759c9413071fedb9cf5cd1aa63dd054c9 (patch)
tree9fde4845c3a0abacda608177d3be9ef744afa6b5 /wqflask
parent6eff6c4cc097feba53022898ddfe96f26386e258 (diff)
downloadgenenetwork2-b216de9759c9413071fedb9cf5cd1aa63dd054c9.tar.gz
Add the Gene Track option to display the Gene Band for single chromosome view
Fixed an issue where width wasn't being set correctly, so chromosome view is correct width now (was too short before)
Diffstat (limited to 'wqflask')
-rw-r--r--[-rwxr-xr-x]wqflask/wqflask/interval_analyst/GeneUtil.py98
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression.py22
-rw-r--r--wqflask/wqflask/marker_regression/marker_regression_gn1.py83
-rw-r--r--wqflask/wqflask/templates/marker_regression_gn1.html7
-rw-r--r--wqflask/wqflask/views.py1
5 files changed, 93 insertions, 118 deletions
diff --git a/wqflask/wqflask/interval_analyst/GeneUtil.py b/wqflask/wqflask/interval_analyst/GeneUtil.py
index 43008ecf..a8a48786 100755..100644
--- a/wqflask/wqflask/interval_analyst/GeneUtil.py
+++ b/wqflask/wqflask/interval_analyst/GeneUtil.py
@@ -1,46 +1,24 @@
-# 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 Drs. Robert W. Williams and Xiaodong Zhou (2010)
-# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
-#
-#
-#
-# This module is used by GeneNetwork project (www.genenetwork.org)
-#
-# Created by GeneNetwork Core Team 2010/08/10
-#
-# Last updated by GeneNetwork Core Team 2010/10/20
+from __future__ import absolute_import, print_function, division
import string
+from flask import Flask, g
+
#Just return a list of dictionaries
#each dictionary contains sub-dictionary
-def loadGenes(cursor, chrName, diffCol, startMb, endMb, webqtlDb =None, species='mouse'):
- #cursor.execute("desc GeneList")
- #results = cursor.fetchall()
- #fetchFields = map(lambda X:X[0], results)
+def loadGenes(chrName, diffCol, startMb, endMb, webqtlDb =None, species='mouse'):
fetchFields = ['SpeciesId', 'Id', 'GeneSymbol', 'GeneDescription', 'Chromosome', 'TxStart', 'TxEnd',
'Strand', 'GeneID', 'NM_ID', 'kgID', 'GenBankID', 'UnigenID', 'ProteinID', 'AlignID',
'exonCount', 'exonStarts', 'exonEnds', 'cdsStart', 'cdsEnd']
##List All Species in the Gene Table
speciesDict = {}
- cursor.execute("select Species.Name, GeneList.SpeciesId from Species, GeneList where \
- GeneList.SpeciesId = Species.Id group by GeneList.SpeciesId")
- results = cursor.fetchall()
+ results = g.db.execute("""
+ SELECT Species.Name, GeneList.SpeciesId
+ FROM Species, GeneList
+ WHERE GeneList.SpeciesId = Species.Id
+ GROUP BY GeneList.SpeciesId""").fetchall()
+
for item in results:
speciesDict[item[0]] = item[1]
@@ -49,14 +27,17 @@ def loadGenes(cursor, chrName, diffCol, startMb, endMb, webqtlDb =None, species=
otherSpecies = map(lambda X: [X, speciesDict[X]], speciesDict.keys())
otherSpecies.remove([species, speciesId])
- cursor.execute("""SELECT %s from GeneList
- where
- SpeciesId = %d AND Chromosome = '%s' AND
- ((TxStart > %f and TxStart <= %f) OR (TxEnd > %f and TxEnd <= %f))
- order by txStart
- """
- % (string.join(fetchFields, ", "), speciesId, chrName, startMb, endMb, startMb, endMb))
- results = cursor.fetchall()
+ results = g.db.execute("""
+ SELECT %s FROM GeneList
+ WHERE SpeciesId = %d AND
+ Chromosome = '%s' AND
+ ((TxStart > %f and TxStart <= %f) OR (TxEnd > %f and TxEnd <= %f))
+ ORDER BY txStart
+ """ % (string.join(fetchFields, ", "),
+ speciesId, chrName,
+ startMb, endMb,
+ startMb, endMb)).fetchall()
+
GeneList = []
if results:
@@ -66,14 +47,13 @@ def loadGenes(cursor, chrName, diffCol, startMb, endMb, webqtlDb =None, species=
newdict[item] = result[j]
#count SNPs if possible
if diffCol and species=='mouse':
- cursor.execute("""
- select
- count(*) from BXDSnpPosition
- where
- Chr = '%s' AND Mb >= %2.6f AND Mb < %2.6f AND
- StrainId1 = %d AND StrainId2 = %d
- """ % (chrName, newdict["TxStart"], newdict["TxEnd"], diffCol[0], diffCol[1]))
- newdict["snpCount"] = cursor.fetchone()[0]
+ newdict["snpCount"] = g.db.execute("""
+ SELECT count(*)
+ FROM BXDSnpPosition
+ WHERE Chr = '%s' AND
+ Mb >= %2.6f AND Mb < %2.6f AND
+ StrainId1 = %d AND StrainId2 = %d
+ """ % (chrName, newdict["TxStart"], newdict["TxEnd"], diffCol[0], diffCol[1])).fetchone()[0]
newdict["snpDensity"] = newdict["snpCount"]/(newdict["TxEnd"]-newdict["TxStart"])/1000.0
else:
newdict["snpDensity"] = newdict["snpCount"] = 0
@@ -88,24 +68,24 @@ def loadGenes(cursor, chrName, diffCol, startMb, endMb, webqtlDb =None, species=
othSpec, othSpecId = item
newdict2 = {}
- cursor.execute("SELECT %s from GeneList where SpeciesId = %d and geneSymbol= '%s' limit 1" %
- (string.join(fetchFields, ", "), othSpecId, newdict["GeneSymbol"]))
- resultsOther = cursor.fetchone()
+ resultsOther = g.db.execute("SELECT %s FROM GeneList WHERE SpeciesId = %d AND geneSymbol= '%s' LIMIT 1" % (string.join(fetchFields, ", "),
+ othSpecId,
+ newdict["GeneSymbol"])).fetchone()
+
if resultsOther:
for j, item in enumerate(fetchFields):
newdict2[item] = resultsOther[j]
#count SNPs if possible, could be a separate function
if diffCol and othSpec == 'mouse':
- cursor.execute("""
- select
- count(*) from BXDSnpPosition
- where
- Chr = '%s' AND Mb >= %2.6f AND Mb < %2.6f AND
- StrainId1 = %d AND StrainId2 = %d
- """ % (chrName, newdict["TxStart"], newdict["TxEnd"], diffCol[0], diffCol[1]))
+ newdict2["snpCount"] = g.db.execute("""
+ SELECT count(*)
+ FROM BXDSnpPosition
+ WHERE Chr = '%s' AND
+ Mb >= %2.6f AND Mb < %2.6f AND
+ StrainId1 = %d AND StrainId2 = %d
+ """ % (chrName, newdict["TxStart"], newdict["TxEnd"], diffCol[0], diffCol[1])).fetchone()[0]
- newdict2["snpCount"] = cursor.fetchone()[0]
newdict2["snpDensity"] = newdict2["snpCount"]/(newdict2["TxEnd"]-newdict2["TxStart"])/1000.0
else:
newdict2["snpDensity"] = newdict2["snpCount"] = 0
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py
index 6d996bd3..fb7efd0f 100644
--- a/wqflask/wqflask/marker_regression/marker_regression.py
+++ b/wqflask/wqflask/marker_regression/marker_regression.py
@@ -32,15 +32,15 @@ from base import data_set
from base import species
from base import webqtlConfig
from utility import webqtlUtil
-#from wqflask.marker_regression import qtl_reaper_mapping
-#from wqflask.marker_regression import plink_mapping
-from wqflask.marker_regression import gemma_mapping
-#from wqflask.marker_regression import rqtl_mapping
from utility import helper_functions
from utility import Plot, Bunch
from utility import temp_data
from utility.benchmark import Bench
from utility.tools import pylmm_command, plink_command, gemma_command
+from wqflask.marker_regression import gemma_mapping
+#from wqflask.marker_regression import qtl_reaper_mapping
+#from wqflask.marker_regression import plink_mapping
+#from wqflask.marker_regression import rqtl_mapping
PYLMM_PATH,PYLMM_COMMAND = pylmm_command()
PLINK_PATH,PLINK_COMMAND = plink_command()
@@ -83,14 +83,22 @@ class MarkerRegression(object):
#ZS: This is passed to GN1 code for single chr mapping
self.selected_chr = -1
- #if "chromosomes" in start_vars:
- # self.selected_chr = int(start_vars['chromosomes']) + 1
if "selected_chr" in start_vars:
- self.selected_chr = int(start_vars['selected_chr']) + 1
+ if int(start_vars['selected_chr']) != -1: #ZS: Needs to be -1 if showing full map; there's probably a better way to fix this
+ self.selected_chr = int(start_vars['selected_chr']) + 1
+ else:
+ self.selected_chr = int(start_vars['selected_chr'])
if "startMb" in start_vars:
self.startMb = start_vars['startMb']
if "endMb" in start_vars:
self.endMb = start_vars['endMb']
+ if "startMb" in start_vars: #ZS: This is to ensure showGenes is checked the first time you open the mapping page, since startMb will only not be set during the first load
+ if "showGenes" in start_vars:
+ self.showGenes = start_vars['showGenes']
+ else:
+ self.showGenes = False
+ else:
+ self.showGenes = "ON"
self.dataset.group.get_markers()
if self.mapping_method == "gemma":
diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
index bb8f7b11..83b33353 100644
--- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py
+++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py
@@ -36,18 +36,18 @@ from flask import Flask, g
from htmlgen import HTMLgen2 as HT
-
-from utility import helper_functions
-from utility import Plot
from base import webqtlConfig
-#from intervalAnalyst import GeneUtil
#from base.webqtlTrait import webqtlTrait
#from base.templatePage import templatePage
+#from base.GeneralObject import GeneralObject
from utility import webqtlUtil
+from utility import helper_functions
+from utility import Plot
#from utility.THCell import THCell
#from utility.TDCell import TDCell
+from wqflask.interval_analyst import GeneUtil
+
#from dbFunction import webqtlDatabaseFunction
-#from base.GeneralObject import GeneralObject
#import logging
#logging.basicConfig(filename="/tmp/gn_leiyan.log", level=logging.INFO)
@@ -228,8 +228,9 @@ class MarkerRegression(object):
else:
self.permChecked = True
#self.permChecked = fd.formdata.getvalue('permCheck', True)
- self.bootChecked = False #ZS: For now setting to False, I'll add this option later once rest of figure works
#self.bootChecked = fd.formdata.getvalue('bootCheck', '')
+ self.bootChecked = False #ZS: For now setting to False, I'll add this option later once rest of figure works
+
if 'do_control' in start_vars.keys():
self.doControl = start_vars['do_control']
else:
@@ -258,26 +259,15 @@ class MarkerRegression(object):
#Darwing Options
try:
- if self.selectedChr > -1:
- self.graphWidth = min(self.GRAPH_MAX_WIDTH, self.GRAPH_MIN_WIDTH)
- else:
- self.graphWidth = min(self.GRAPH_MAX_WIDTH, self.MULT_GRAPH_MIN_WIDTH)
+ if self.selectedChr > -1:
+ self.graphWidth = min(self.GRAPH_MAX_WIDTH, max(self.GRAPH_MIN_WIDTH, int(fd.formdata.getvalue('graphWidth'))))
+ else:
+ self.graphWidth = min(self.GRAPH_MAX_WIDTH, max(self.MULT_GRAPH_MIN_WIDTH, int(fd.formdata.getvalue('graphWidth'))))
except:
- if self.selectedChr > -1:
- self.graphWidth = self.GRAPH_DEFAULT_WIDTH
- else:
- self.graphWidth = self.MULT_GRAPH_DEFAULT_WIDTH
-
- #try:
- # if self.selectedChr > -1:
- # self.graphWidth = min(self.GRAPH_MAX_WIDTH, max(self.GRAPH_MIN_WIDTH, int(fd.formdata.getvalue('graphWidth'))))
- # else:
- # self.graphWidth = min(self.GRAPH_MAX_WIDTH, max(self.MULT_GRAPH_MIN_WIDTH, int(fd.formdata.getvalue('graphWidth'))))
- #except:
- # if self.selectedChr > -1:
- # self.graphWidth = self.GRAPH_DEFAULT_WIDTH
- # else:
- # self.graphWidth = self.MULT_GRAPH_DEFAULT_WIDTH
+ if self.selectedChr > -1:
+ self.graphWidth = self.GRAPH_DEFAULT_WIDTH
+ else:
+ self.graphWidth = self.MULT_GRAPH_DEFAULT_WIDTH
## BEGIN HaplotypeAnalyst
#self.haplotypeAnalystChecked = fd.formdata.getvalue('haplotypeAnalystCheck')
@@ -293,7 +283,10 @@ class MarkerRegression(object):
self.cutoff = start_vars['cutoff']
self.intervalAnalystChecked = False
self.legendChecked = False
- self.geneChecked = False
+ if 'showGenes' in start_vars.keys():
+ self.geneChecked = start_vars['showGenes']
+ else:
+ self.geneChecked = False
self.SNPChecked = False
self.draw2X = False
self.lrsMax = 0
@@ -491,23 +484,17 @@ class MarkerRegression(object):
geneTable = ""
- #if self.plotScale == 'physic' and self.selectedChr > -1 and (self.intervalAnalystChecked or self.geneChecked):
- # chrName = self.genotype[0].name
- # # Draw the genes for this chromosome / region of this chromosome
- # if self.traitList and self.traitList[0] and len(self.traitList) == 1 and self.dataset.name:
- # webqtldatabase = self.dataset.name
- # #webqtldatabase = self.traitList[0].db.name
- # else:
- # webqtldatabase = None
- #
- # self.geneCol = None
- #
- # if self.species == "mouse":
- # self.geneCol = GeneUtil.loadGenes(self.cursor, chrName, self.diffCol, self.startMb, self.endMb, webqtldatabase, "mouse")
- # elif self.species == "rat":
- # self.geneCol = GeneUtil.loadGenes(self.cursor, chrName, self.diffCol, self.startMb, self.endMb, webqtldatabase, "rat")
- # else:
- # self.geneCol = None
+ self.geneCol = None
+ if self.plotScale == 'physic' and self.selectedChr > -1 and (self.intervalAnalystChecked or self.geneChecked):
+ chrName = self.selectedChr
+ # Draw the genes for this chromosome / region of this chromosome
+ webqtldatabase = self.dataset.name
+
+ if self.dataset.group.species == "mouse":
+ self.geneCol = GeneUtil.loadGenes(chrName, self.diffCol, self.startMb, self.endMb, webqtldatabase, "mouse")
+ elif self.dataset.group.species == "rat":
+ self.geneCol = GeneUtil.loadGenes(chrName, self.diffCol, self.startMb, self.endMb, webqtldatabase, "rat")
+
#
# if self.geneCol and self.intervalAnalystChecked:
# #######################################################################
@@ -527,9 +514,7 @@ class MarkerRegression(object):
# tableForm = HT.Form(cgi=os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name=mainfmName, submit=HT.Input(type='hidden'))
# tableForm.append(HT.Input(name='FormID', value='', type='hidden'))
# tableForm.append(geneTableContainer)
- #
- #else:
- self.geneCol = None
+
################################################################
# Plots goes here
@@ -1168,7 +1153,7 @@ class MarkerRegression(object):
for gIndex, theGO in enumerate(self.geneCol):
geneNCBILink = 'http://www.ncbi.nlm.nih.gov/gene?term=%s'
- if self.species == "mouse":
+ if self.dataset.group.species == "mouse":
txStart = theGO["TxStart"]
txEnd = theGO["TxEnd"]
geneLength = (txEnd - txStart)*1000.0
@@ -1227,7 +1212,7 @@ class MarkerRegression(object):
# NL: 06-02-2011 Rob required to change this link for gene related
HREF=geneNCBILink %geneSymbol
- elif self.species == "rat":
+ elif self.dataset.group.species == "rat":
exonStarts = []
exonEnds = []
txStart = theGO["TxStart"]
@@ -1641,7 +1626,7 @@ class MarkerRegression(object):
chrFont = pid.Font(ttf="verdana", size=26*zoom, bold=1)
traitFont = pid.Font(ttf="verdana", size=14, bold=0)
chrX = xLeftOffset + plotWidth - 2 - canvas.stringWidth("Chr %s" % self.selectedChr, font=chrFont)
- canvas.drawString("Chr %s" % currentChromosome, chrX, ensemblPaddingTop-5, font=chrFont, color=pid.gray)
+ canvas.drawString("Chr %s" % self.selectedChr, chrX, ensemblPaddingTop-5, font=chrFont, color=pid.gray)
traitX = chrX - 28 - canvas.stringWidth("database", font=traitFont)
# end of drawBrowserClickableRegions
else:
diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html
index 767befd8..33335615 100644
--- a/wqflask/wqflask/templates/marker_regression_gn1.html
+++ b/wqflask/wqflask/templates/marker_regression_gn1.html
@@ -40,7 +40,7 @@
{% endif %}
</div>
<div id="gn1_map_options" class="col-xs-5" style="border:2px solid black; padding: 10px; margin: 10px;">
- <div class="col-xs-9" style="padding-left: 0px;">
+ <div class="col-xs-8" style="padding-left: 0px;">
<table>
<tr>
<td><b>Chr:&nbsp;</b></td>
@@ -62,12 +62,13 @@
<tr>
<td><b>Width:&nbsp;</b></td>
<td>
- <input type="text" name="graphWidth" value="1600" size="5">
+ <input type="text" name="graphWidth" value="1600" size="5"><span style="font-size: 11px;"> pixels (minimum=900)</span>
</td>
</tr>
</table>
</div>
- <div class="col-xs-3">
+ <div class="col-xs-4">
+ <input type="checkbox" name="showGenes" class="checkbox" style="display: inline;" {% if geneChecked|upper == "ON" %}value="ON" checked{% endif %}> <span>Gene Track </span> <span style="color:red;">*</span>
</div>
</div>
</div>
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index b5b6fa82..23073f88 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -356,6 +356,7 @@ def marker_regression_page():
'pair_scan',
'startMb',
'endMb',
+ 'showGenes',
'mapmethod_rqtl_geno',
'mapmodel_rqtl_geno'
)