From 97b83d20a5f6896614024a3cc40535bfb738ef51 Mon Sep 17 00:00:00 2001 From: zsloan Date: Sat, 12 Dec 2015 00:01:06 +0000 Subject: Changed loop drawing qtl curve to fix some issues; still need to make it draw to different chr areas though --- .gitignore | 1 + wqflask/base/webqtlConfig.py | 2 +- .../marker_regression/marker_regression_gn1.py | 65 ++++++++++++++-------- wqflask/wqflask/views.py | 8 +-- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 1ab1e727..f4693a9a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ web/new_genotypes/HSNIH.json wqflask/secure_server.py wqflask/base/webqtlConfig.py +wqflask/output/* diff --git a/wqflask/base/webqtlConfig.py b/wqflask/base/webqtlConfig.py index 330fec56..4f9b3af3 100755 --- a/wqflask/base/webqtlConfig.py +++ b/wqflask/base/webqtlConfig.py @@ -55,7 +55,7 @@ COMMON_LIB = GNROOT + 'support/admin' HTMLPATH = GNROOT + 'genotype_files/' PYLMM_PATH = '/home/zas1024/plink_gemma/' SNP_PATH = '/home/zas1024/snps/' -IMGDIR = GNROOT + '/wqflask/wqflask/images/' +IMGDIR = GNROOT + '/wqflask/output/' IMAGESPATH = HTMLPATH + 'images/' UPLOADPATH = IMAGESPATH + 'upload/' TMPDIR = '/home/zas1024/tmp/' # Will remove this and dependent items later diff --git a/wqflask/wqflask/marker_regression/marker_regression_gn1.py b/wqflask/wqflask/marker_regression/marker_regression_gn1.py index f2fc12a4..c2cd5e97 100644 --- a/wqflask/wqflask/marker_regression/marker_regression_gn1.py +++ b/wqflask/wqflask/marker_regression/marker_regression_gn1.py @@ -37,13 +37,14 @@ 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 utility import webqtlUtil +from utility import webqtlUtil #from utility.THCell import THCell #from utility.TDCell import TDCell #from dbFunction import webqtlDatabaseFunction @@ -507,19 +508,16 @@ class MarkerRegression(object): ################################################################ # Plots goes here ################################################################ - print("BEFORE GN1 PLOT") if self.plotScale != 'physic' or self.multipleInterval: showLocusForm = webqtlUtil.genRandStr("fm_") else: showLocusForm = "" - print("BEFORE PIL CANVAS") intCanvas = pid.PILCanvas(size=(self.graphWidth,self.graphHeight)) - print("BEFORE PLOTINTMAPPING") gifmap = self.plotIntMapping(intCanvas, startMb = self.startMb, endMb = self.endMb, showLocusForm= showLocusForm) print("AFTER PLOTINTMAPPING") filename= webqtlUtil.genRandStr("Itvl_") - intCanvas.save(os.path.join(webqtlConfig.IMGDIR, filename), format='png') + intCanvas.save(os.path.join(webqtlConfig.IMGDIR, filename), format='jpeg') intImg=HT.Image('/image/'+filename+'.png', border=0, usemap='#WebQTLImageMap') #Scales plot differently for high resolution @@ -743,7 +741,6 @@ class MarkerRegression(object): endPixelX = (xLeftOffset + plotWidth) #Drawing Area Height - print("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 @@ -769,7 +766,6 @@ class MarkerRegression(object): newoffset = (xLeftOffset, xRightOffset, yTopOffset, yBottomOffset) # Draw the alternating-color background first and get plotXScale - print("DRAW BACKGROUND") plotXScale = self.drawGraphBackground(canvas, gifmap, offset=newoffset, zoom= zoom, startMb=startMb, endMb = endMb) #draw bootstap @@ -778,7 +774,6 @@ class MarkerRegression(object): # Draw clickable region and gene band if selected if self.plotScale == 'physic' and self.selectedChr > -1: - print("DRAW CLICKABLE REGION") self.drawClickBand(canvas, gifmap, plotXScale, offset=newoffset, zoom = zoom, startMb=startMb, endMb = endMb) if self.geneChecked and self.geneCol: self.drawGeneBand(canvas, gifmap, plotXScale, offset=newoffset, zoom = zoom, startMb=startMb, endMb = endMb) @@ -786,18 +781,14 @@ class MarkerRegression(object): self.drawSNPTrackNew(canvas, offset=newoffset, zoom = 2*zoom, startMb=startMb, endMb = endMb) ## BEGIN HaplotypeAnalyst if self.haplotypeAnalystChecked: - print("DRAW HAPLOTYPE") self.drawHaplotypeBand(canvas, gifmap, plotXScale, offset=newoffset, zoom = zoom, startMb=startMb, endMb = endMb) ## END HaplotypeAnalyst # Draw X axis - print("DRAW X AXIS") self.drawXAxis(canvas, drawAreaHeight, gifmap, plotXScale, showLocusForm, offset=newoffset, zoom = zoom, startMb=startMb, endMb = endMb) # Draw QTL curve - print("DRAW QTL CURVE") self.drawQTL(canvas, drawAreaHeight, gifmap, plotXScale, offset=newoffset, zoom= zoom, startMb=startMb, endMb = endMb) #draw legend - print("DRAW LEGEND") if self.multipleInterval: self.drawMultiTraitName(fd, canvas, gifmap, showLocusForm, offset=newoffset) elif self.legendChecked: @@ -806,7 +797,6 @@ class MarkerRegression(object): pass #draw position, no need to use a separate function - print("DRAW PROBESET POSITION") if self.genotype.Mbmap: self.drawProbeSetPosition(canvas, plotXScale, offset=newoffset, zoom = zoom) @@ -1823,7 +1813,7 @@ class MarkerRegression(object): lodm = self.LODFACTOR else: lodm = 1.0 - + if self.lrsMax <= 0: #sliding scale if "lrs_value" in self.qtlresults[0]: LRSMax = max([result['lrs_value'] for result in self.qtlresults]) @@ -1874,6 +1864,7 @@ class MarkerRegression(object): #"Significant" and "Suggestive" Drawing Routine # ======= Draw the thick lines for "Significant" and "Suggestive" ===== (crowell: I tried to make the SNPs draw over these lines, but piddle wouldn't have it...) + print("DRAW SUGGESTIVE/SIGNFICANT LINES") if self.permChecked and not self.multipleInterval: significantY = yZero - self.significance*LRSHeightThresh/LRSMax suggestiveY = yZero - self.suggestive*LRSHeightThresh/LRSMax @@ -1912,23 +1903,37 @@ class MarkerRegression(object): if zoom == 2: lrsEdgeWidth = 2 * lrsEdgeWidth + print("DRAW QTL RESULT CURVE") + + LRSCoordXY = [] + AdditiveCoordXY = [] + DominanceCoordXY = [] + + previous_chr = 1 + previous_chr_as_int = 1 for i, qtlresult in enumerate(self.qtlresults): m = 0 startPosX = xLeftOffset thisLRSColor = self.colorCollection[0] - for j, _chr in enumerate(self.genotype): - LRSCoordXY = [] - AdditiveCoordXY = [] - DominanceCoordXY = [] - for k, _locus in enumerate(_chr): + #for j, _chr in enumerate(self.genotype): + if 1 == 1: + #LRSCoordXY = [] + #AdditiveCoordXY = [] + #DominanceCoordXY = [] + #for k, _locus in enumerate(_chr): + if 1 == 1: if self.plotScale == 'physic': - Xc = startPosX + (_locus.Mb-startMb)*plotXScale + #Xc = startPosX + (_locus.Mb-startMb)*plotXScale + Xc = startPosX + (qtlresult['Mb']-startMb)*plotXScale else: - Xc = startPosX + (_locus.cM-_chr[0].cM)*plotXScale + #Xc = startPosX + (_locus.cM-_chr[0].cM)*plotXScale + Xc = startPosX + (qtlresult['cM']-qtlresult[0]['cM'])*plotXScale + # updated by NL 06-18-2011: # fix the over limit LRS graph issue since genotype trait may give infinite LRS; # for any lrs is over than 460(LRS max in this system), it will be reset to 460 if qtlresult['lrs_value'] > 460 or qtlresult['lrs_value']=='inf': + #if self.qtlresults[j]['lrs_value'] > 460 or self.qtlresults[j]['lrs_value']=='inf': Yc = yZero - webqtlConfig.MAXLRS*LRSHeightThresh/LRSMax else: Yc = yZero - qtlresult['lrs_value']*LRSHeightThresh/LRSMax @@ -1943,7 +1948,7 @@ class MarkerRegression(object): # Yc = yZero - qtlresult[m].dominance*DominanceHeightThresh/dominanceMax # DominanceCoordXY.append((Xc, Yc)) m += 1 - canvas.drawPolygon(LRSCoordXY,edgeColor=thisLRSColor,closed=0, edgeWidth=lrsEdgeWidth, clipX=(xLeftOffset, xLeftOffset + plotWidth)) + #canvas.drawPolygon(LRSCoordXY,edgeColor=thisLRSColor,closed=0, edgeWidth=lrsEdgeWidth, clipX=(xLeftOffset, xLeftOffset + plotWidth)) lineWidth = 1 if not self.multipleInterval and self.additiveChecked: @@ -2004,7 +2009,21 @@ class MarkerRegression(object): canvas.drawLine(Xc0, Yc0, Xc, Yc, color=plusColor, width=lineWidth, clipX=(xLeftOffset, xLeftOffset + plotWidth)) else: canvas.drawLine(Xc0, yZero - (Yc0-yZero), Xc, yZero - (Yc-yZero), color=minusColor, width=lineWidth, clipX=(xLeftOffset, xLeftOffset + plotWidth)) - startPosX += (self.ChrLengthDistList[j]+self.GraphInterval)*plotXScale + + print("previous_chr:", previous_chr_as_int) + startPosX += (self.ChrLengthDistList[previous_chr_as_int-1]+self.GraphInterval)*plotXScale + #startPosX += (self.ChrLengthDistList[j]+self.GraphInterval)*plotXScale + + if qtlresult['chr'] != previous_chr: + previous_chr = qtlresult['chr'] + try: + previous_chr_as_int = int(previous_chr) + except: + previous_chr_as_int += 1 + + canvas.drawPolygon(LRSCoordXY,edgeColor=thisLRSColor,closed=0, edgeWidth=lrsEdgeWidth, clipX=(xLeftOffset, xLeftOffset + plotWidth)) + + print("AFTER QTL CURVE") ###draw additive scale if not self.multipleInterval and self.additiveChecked: diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 4446b431..c17d6274 100755 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -385,10 +385,10 @@ def marker_regression_page(): #causeerror - #print("TESTING GN1!!!") - #gn1_template_vars = marker_regression_gn1.MarkerRegression(result).__dict__ - #print("gn1_template_vars:", gn1_template_vars) - #causeerror + print("TESTING GN1!!!") + gn1_template_vars = marker_regression_gn1.MarkerRegression(result).__dict__ + print("gn1_template_vars:", gn1_template_vars) + causeerror #qtl_length = len(result['js_data']['qtl_results']) -- cgit v1.2.3