From b1e0067c95efa7d2fffa0dd1230b917121869709 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 6 Apr 2016 18:21:04 +0000 Subject: Permutations (suggestive/significant lines, legend, and histogram) should now work for both R/qtl and qtl reaper mapping. Changed the logic for receiving permutation/bootstrap info when loading mapping page in different ways (from show_trait, from remapping, from clicking single chromosome) Added text below figure when Allele Effects selected/relevant --- wqflask/utility/Plot.py | 352 ++++++++++++++++++++++++------------------------ 1 file changed, 175 insertions(+), 177 deletions(-) mode change 100755 => 100644 wqflask/utility/Plot.py (limited to 'wqflask/utility/Plot.py') diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py old mode 100755 new mode 100644 index 51a57a6d..ad11a81e --- a/wqflask/utility/Plot.py +++ b/wqflask/utility/Plot.py @@ -24,10 +24,9 @@ # # Last updated by GeneNetwork Core Team 2010/10/20 -#import piddle as pid - from __future__ import print_function +import piddle as pid from pprint import pformat as pf print("Lysol") @@ -478,181 +477,180 @@ def plotSecurity(canvas, text="12345"): # parameter: data is either object returned by reaper permutation function (called by MarkerRegressionPage.py) # or the first object returned by direct (pair-scan) permu function (called by DirectPlotPage.py) -#def plotBar(canvas, data, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, offset= (60, 20, 40, 40), zoom = 1): -# -# xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset -# -# plotWidth = canvas.size[0] - xLeftOffset - xRightOffset -# plotHeight = canvas.size[1] - yTopOffset - yBottomOffset -# if plotHeight<=0 or plotWidth<=0: -# return -# -# if len(data) < 2: -# return -# -# max_D = max(data) -# min_D = min(data) -# #add by NL 06-20-2011: fix the error: when max_D is infinite, log function in detScale will go wrong -# if max_D == float('inf') or max_D>webqtlConfig.MAXLRS: -# max_D=webqtlConfig.MAXLRS #maximum LRS value -# -# xLow, xTop, stepX = detScale(min_D, max_D) -# -# #reduce data -# step = ceil((xTop-xLow)/50.0) -# j = xLow -# dataXY = [] -# Count = [] -# while j <= xTop: -# dataXY.append(j) -# Count.append(0) -# j += step -# -# for i, item in enumerate(data): -# if item == float('inf') or item>webqtlConfig.MAXLRS: -# item = webqtlConfig.MAXLRS #maximum LRS value -# j = int((item-xLow)/step) -# Count[j] += 1 -# -# yLow, yTop, stepY=detScale(0,max(Count)) -# -# #draw data -# xScale = plotWidth/(xTop-xLow) -# yScale = plotHeight/(yTop-yLow) -# barWidth = xScale*step -# -# for i, count in enumerate(Count): -# if count: -# xc = (dataXY[i]-xLow)*xScale+xLeftOffset -# yc =-(count-yLow)*yScale+yTopOffset+plotHeight -# canvas.drawRect(xc+2,yc,xc+barWidth-2,yTopOffset+plotHeight,edgeColor=barColor,fillColor=barColor) -# -# #draw drawing region -# canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) -# -# #draw scale -# scaleFont=pid.Font(ttf="cour",size=11,bold=1) -# x=xLow -# for i in range(stepX+1): -# xc=xLeftOffset+(x-xLow)*xScale -# canvas.drawLine(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, color=axesColor) -# strX = cformat(d=x, rank=0) -# canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+14,font=scaleFont) -# x+= (xTop - xLow)/stepX -# -# y=yLow -# for i in range(stepY+1): -# yc=yTopOffset+plotHeight-(y-yLow)*yScale -# canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) -# strY = "%d" %y -# canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) -# y+= (yTop - yLow)/stepY -# -# #draw label -# labelFont=pid.Font(ttf="tahoma",size=17,bold=0) -# if XLabel: -# canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, -# yTopOffset+plotHeight+yBottomOffset-10,font=labelFont,color=labelColor) -# -# if YLabel: -# canvas.drawString(YLabel, 19, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, -# font=labelFont,color=labelColor,angle=90) -# -# labelFont=pid.Font(ttf="verdana",size=16,bold=0) -# if title: -# canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, -# 20,font=labelFont,color=labelColor) -# -#def plotBarText(canvas, data, label, variance=None, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, sLabel = None, offset= (80, 20, 40, 100), barSpace = 2, zoom = 1): -# xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset -# plotWidth = canvas.size[0] - xLeftOffset - xRightOffset -# plotHeight = canvas.size[1] - yTopOffset - yBottomOffset -# if plotHeight<=0 or plotWidth<=0: -# return -# -# NNN = len(data) -# if NNN < 2 or NNN != len(label): -# return -# if variance and len(variance)!=NNN: -# variance = [] -# -# Y2 = data[:] -# if variance: -# for i in range(NNN): -# if variance[i]: -# Y2 += [data[i]-variance[i]] -# -# #Y axis -# YLow, YTop, stepY = detScale(min(Y2), max(Y2)) -# YScale = plotHeight/(YTop - YLow) -# -# if YLow < 0 and YTop > 0: -# drawZero = 1 -# else: -# drawZero = 0 -# -# #X axis -# X = range(NNN) -# Xll= 0 -# Xur= NNN-1 -# -# -# if drawZero: -# YZero = yTopOffset+plotHeight-YScale*(0-YLow) -# canvas.drawLine(xLeftOffset, YZero, xLeftOffset+plotWidth, YZero) -# else: -# YZero = yTopOffset+plotHeight -# #draw data -# spaceWidth = barSpace -# if spaceWidth < 1: -# spaceWidth = 1 -# barWidth = int((plotWidth - (NNN-1.0)*spaceWidth)/NNN) -# -# xc= xLeftOffset -# scaleFont=pid.Font(ttf="verdana",size=11,bold=0) -# for i in range(NNN): -# yc = yTopOffset+plotHeight-(data[i]-YLow)*YScale -# canvas.drawRect(xc,YZero,xc+barWidth-1, yc, edgeColor=barColor,fillColor=barColor) -# if variance and variance[i]: -# varlen = variance[i]*YScale -# if yc-varlen < yTopOffset: -# topYd = yTopOffset -# else: -# topYd = yc-varlen -# canvas.drawLine(xc+barWidth/2-2,yc-varlen,xc+barWidth/2+2,yc-varlen,color=pid.red) -# canvas.drawLine(xc+barWidth/2,yc+varlen,xc+barWidth/2,topYd,color=pid.red) -# canvas.drawLine(xc+barWidth/2-2,yc+varlen,xc+barWidth/2+2,yc+varlen,color=pid.red) -# strX = label[i] -# canvas.drawString(strX,xc+barWidth/2.0+2,yTopOffset+plotHeight+2+canvas.stringWidth(strX,font=scaleFont),font=scaleFont,angle=90) -# xc += barWidth + spaceWidth -# -# #draw drawing region -# canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) -# -# #draw Y scale -# scaleFont=pid.Font(ttf="cour",size=16,bold=1) -# y=YLow -# for i in range(stepY+1): -# yc=yTopOffset+plotHeight-(y-YLow)*YScale -# canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) -# strY = cformat(d=y, rank=0) -# canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) -# y+= (YTop - YLow)/stepY -# -# #draw label -# labelFont=pid.Font(ttf="verdana",size=17,bold=0) -# if XLabel: -# canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0,yTopOffset+plotHeight+65,font=labelFont,color=labelColor) -# -# if YLabel: -# canvas.drawString(YLabel,xLeftOffset-50, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0,font=labelFont,color=labelColor,angle=90) -# -# labelFont=pid.Font(ttf="verdana",size=18,bold=0) -# if title: -# canvas.drawString(title,xLeftOffset,yTopOffset-15,font=labelFont,color=labelColor) -# -# return -# +def plotBar(canvas, data, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, offset= (60, 20, 40, 40), zoom = 1): + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + + if len(data) < 2: + return + + max_D = max(data) + min_D = min(data) + #add by NL 06-20-2011: fix the error: when max_D is infinite, log function in detScale will go wrong + if max_D == float('inf') or max_D>webqtlConfig.MAXLRS: + max_D=webqtlConfig.MAXLRS #maximum LRS value + + xLow, xTop, stepX = detScale(min_D, max_D) + + #reduce data + step = ceil((xTop-xLow)/50.0) + j = xLow + dataXY = [] + Count = [] + while j <= xTop: + dataXY.append(j) + Count.append(0) + j += step + + for i, item in enumerate(data): + if item == float('inf') or item>webqtlConfig.MAXLRS: + item = webqtlConfig.MAXLRS #maximum LRS value + j = int((item-xLow)/step) + Count[j] += 1 + + yLow, yTop, stepY=detScale(0,max(Count)) + + #draw data + xScale = plotWidth/(xTop-xLow) + yScale = plotHeight/(yTop-yLow) + barWidth = xScale*step + + for i, count in enumerate(Count): + if count: + xc = (dataXY[i]-xLow)*xScale+xLeftOffset + yc =-(count-yLow)*yScale+yTopOffset+plotHeight + canvas.drawRect(xc+2,yc,xc+barWidth-2,yTopOffset+plotHeight,edgeColor=barColor,fillColor=barColor) + + #draw drawing region + canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) + + #draw scale + scaleFont=pid.Font(ttf="cour",size=11,bold=1) + x=xLow + for i in range(int(stepX)+1): + xc=xLeftOffset+(x-xLow)*xScale + canvas.drawLine(xc,yTopOffset+plotHeight,xc,yTopOffset+plotHeight+5, color=axesColor) + strX = cformat(d=x, rank=0) + canvas.drawString(strX,xc-canvas.stringWidth(strX,font=scaleFont)/2,yTopOffset+plotHeight+14,font=scaleFont) + x+= (xTop - xLow)/stepX + + y=yLow + for i in range(int(stepY)+1): + yc=yTopOffset+plotHeight-(y-yLow)*yScale + canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) + strY = "%d" %y + canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) + y+= (yTop - yLow)/stepY + + #draw label + labelFont=pid.Font(ttf="tahoma",size=17,bold=0) + if XLabel: + canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0, + yTopOffset+plotHeight+yBottomOffset-10,font=labelFont,color=labelColor) + + if YLabel: + canvas.drawString(YLabel, 19, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0, + font=labelFont,color=labelColor,angle=90) + + labelFont=pid.Font(ttf="verdana",size=16,bold=0) + if title: + canvas.drawString(title,xLeftOffset+(plotWidth-canvas.stringWidth(title,font=labelFont))/2.0, + 20,font=labelFont,color=labelColor) + +def plotBarText(canvas, data, label, variance=None, barColor=pid.blue, axesColor=pid.black, labelColor=pid.black, XLabel=None, YLabel=None, title=None, sLabel = None, offset= (80, 20, 40, 100), barSpace = 2, zoom = 1): + xLeftOffset, xRightOffset, yTopOffset, yBottomOffset = offset + plotWidth = canvas.size[0] - xLeftOffset - xRightOffset + plotHeight = canvas.size[1] - yTopOffset - yBottomOffset + if plotHeight<=0 or plotWidth<=0: + return + + NNN = len(data) + if NNN < 2 or NNN != len(label): + return + if variance and len(variance)!=NNN: + variance = [] + + Y2 = data[:] + if variance: + for i in range(NNN): + if variance[i]: + Y2 += [data[i]-variance[i]] + + #Y axis + YLow, YTop, stepY = detScale(min(Y2), max(Y2)) + YScale = plotHeight/(YTop - YLow) + + if YLow < 0 and YTop > 0: + drawZero = 1 + else: + drawZero = 0 + + #X axis + X = range(NNN) + Xll= 0 + Xur= NNN-1 + + + if drawZero: + YZero = yTopOffset+plotHeight-YScale*(0-YLow) + canvas.drawLine(xLeftOffset, YZero, xLeftOffset+plotWidth, YZero) + else: + YZero = yTopOffset+plotHeight + #draw data + spaceWidth = barSpace + if spaceWidth < 1: + spaceWidth = 1 + barWidth = int((plotWidth - (NNN-1.0)*spaceWidth)/NNN) + + xc= xLeftOffset + scaleFont=pid.Font(ttf="verdana",size=11,bold=0) + for i in range(NNN): + yc = yTopOffset+plotHeight-(data[i]-YLow)*YScale + canvas.drawRect(xc,YZero,xc+barWidth-1, yc, edgeColor=barColor,fillColor=barColor) + if variance and variance[i]: + varlen = variance[i]*YScale + if yc-varlen < yTopOffset: + topYd = yTopOffset + else: + topYd = yc-varlen + canvas.drawLine(xc+barWidth/2-2,yc-varlen,xc+barWidth/2+2,yc-varlen,color=pid.red) + canvas.drawLine(xc+barWidth/2,yc+varlen,xc+barWidth/2,topYd,color=pid.red) + canvas.drawLine(xc+barWidth/2-2,yc+varlen,xc+barWidth/2+2,yc+varlen,color=pid.red) + strX = label[i] + canvas.drawString(strX,xc+barWidth/2.0+2,yTopOffset+plotHeight+2+canvas.stringWidth(strX,font=scaleFont),font=scaleFont,angle=90) + xc += barWidth + spaceWidth + + #draw drawing region + canvas.drawRect(xLeftOffset, yTopOffset, xLeftOffset+plotWidth, yTopOffset+plotHeight) + + #draw Y scale + scaleFont=pid.Font(ttf="cour",size=16,bold=1) + y=YLow + for i in range(stepY+1): + yc=yTopOffset+plotHeight-(y-YLow)*YScale + canvas.drawLine(xLeftOffset,yc,xLeftOffset-5,yc, color=axesColor) + strY = cformat(d=y, rank=0) + canvas.drawString(strY,xLeftOffset-canvas.stringWidth(strY,font=scaleFont)-6,yc+5,font=scaleFont) + y+= (YTop - YLow)/stepY + + #draw label + labelFont=pid.Font(ttf="verdana",size=17,bold=0) + if XLabel: + canvas.drawString(XLabel,xLeftOffset+(plotWidth-canvas.stringWidth(XLabel,font=labelFont))/2.0,yTopOffset+plotHeight+65,font=labelFont,color=labelColor) + + if YLabel: + canvas.drawString(YLabel,xLeftOffset-50, yTopOffset+plotHeight-(plotHeight-canvas.stringWidth(YLabel,font=labelFont))/2.0,font=labelFont,color=labelColor,angle=90) + + labelFont=pid.Font(ttf="verdana",size=18,bold=0) + if title: + canvas.drawString(title,xLeftOffset,yTopOffset-15,font=labelFont,color=labelColor) + + return + #def plotXY(canvas, dataX, dataY, rank=0, dataLabel=[], plotColor = pid.black, axesColor=pid.black, labelColor=pid.black, lineSize="thin", lineColor=pid.grey, idFont="arial", idColor=pid.blue, idSize="14", symbolColor=pid.black, symbolType="circle", filled="yes", symbolSize="tiny", XLabel=None, YLabel=None, title=None, fitcurve=None, connectdot=1, displayR=None, loadingPlot = 0, offset= (80, 20, 40, 60), zoom = 1, specialCases=[], showLabel = 1, bufferSpace = 15): # 'displayR : correlation scatter plot, loadings : loading plot' # -- cgit v1.2.3 From 8d7f923631cc3578aa9fb8116b31dbfd773e3b59 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 7 Apr 2016 17:58:49 +0000 Subject: SNP Track option should now work for GN1 mapping figure Fixed typo in show_trait html that caused the p-value slider to not work for correlations --- wqflask/utility/Plot.py | 1 + wqflask/wqflask/marker_regression/marker_regression.py | 8 +++++++- wqflask/wqflask/marker_regression/marker_regression_gn1.py | 13 ++++++++----- wqflask/wqflask/templates/marker_regression_gn1.html | 6 ++++++ wqflask/wqflask/templates/show_trait.html | 2 +- wqflask/wqflask/views.py | 1 + 6 files changed, 24 insertions(+), 7 deletions(-) (limited to 'wqflask/utility/Plot.py') diff --git a/wqflask/utility/Plot.py b/wqflask/utility/Plot.py index ad11a81e..444c71c9 100644 --- a/wqflask/utility/Plot.py +++ b/wqflask/utility/Plot.py @@ -497,6 +497,7 @@ def plotBar(canvas, data, barColor=pid.blue, axesColor=pid.black, labelColor=pid xLow, xTop, stepX = detScale(min_D, max_D) #reduce data + #ZS: Used to determine number of bins for permutation output step = ceil((xTop-xLow)/50.0) j = xLow dataXY = [] diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index 86fced39..26ba212d 100644 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -104,7 +104,12 @@ class MarkerRegression(object): self.num_perm = int(start_vars['num_perm']) self.LRSCheck = start_vars['LRSCheck'] - + + if "showSNP" in start_vars: + self.showSNP = start_vars['showSNP'] + else: + self.showSNP = False + if "showGenes" in start_vars: self.showGenes = start_vars['showGenes'] else: @@ -125,6 +130,7 @@ class MarkerRegression(object): self.LRSCheck = self.score_type self.permCheck = "ON" + self.showSNP = "ON" self.showGenes = "ON" self.viewLegend = "ON" diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py index 45d98554..3e08f7ae 100644 --- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py +++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py @@ -304,11 +304,14 @@ class MarkerRegression(object): self.legendChecked = start_vars['viewLegend'] else: self.legendChecked = False + if 'showSNP' in start_vars.keys(): + self.SNPChecked = start_vars['showSNP'] + else: + self.SNPChecked = 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 try: @@ -1047,14 +1050,14 @@ class MarkerRegression(object): SNPCounts = [] while startMb= %2.6f AND Mb < %2.6f AND StrainId1 = %d AND StrainId2 = %d - """ % (chrName, startMb, startMb+stepMb, strainId1, strainId2)) - SNPCounts.append(self.cursor.fetchone()[0]) + """ % (chrName, startMb, startMb+stepMb, strainId1, strainId2)).fetchone()[0] + SNPCounts.append(snp_count) startMb += stepMb if (len(SNPCounts) > 0): @@ -2538,7 +2541,7 @@ class MarkerRegression(object): heading2.append(HT.Strong("Trait Name: "), fd.identification) return HT.TD(intMapHeading, heading2, valign="top") - def drawPermutationHistogram(self): + def drawPermutationHistogram(self, x_label='LRS'): ######################################### # Permutation Graph ######################################### diff --git a/wqflask/wqflask/templates/marker_regression_gn1.html b/wqflask/wqflask/templates/marker_regression_gn1.html index 11c0f859..cc881011 100644 --- a/wqflask/wqflask/templates/marker_regression_gn1.html +++ b/wqflask/wqflask/templates/marker_regression_gn1.html @@ -104,6 +104,12 @@
{% endif %} + SNP Track + + ? + + * +
Gene Track *
Legend
{% if plotScale != "morgan" %} diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index 73bd8e4b..62a08d85 100755 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -151,7 +151,7 @@ -