def plotNormalProbability(vals=None, RISet='', title=None, showstrains=0, specialStrains=[None], size=(750,500)): dataXZ = vals[:] dataXZ.sort(webqtlUtil.cmpOrder) dataLabel = [] dataX = map(lambda X: X[1], dataXZ) showLabel = showstrains if len(dataXZ) > 50: showLabel = 0 for item in dataXZ: strainName = webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=item[0]) dataLabel.append(strainName) dataY=Plot.U(len(dataX)) dataZ=map(Plot.inverseCumul,dataY) c = pid.PILCanvas(size=(750,500)) Plot.plotXY(c, dataZ, dataX, dataLabel = dataLabel, XLabel='Expected Z score', connectdot=0, YLabel='Trait value', title=title, specialCases=specialStrains, showLabel = showLabel) filename= webqtlUtil.genRandStr("nP_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img=HT.Image('/image/'+filename+'.gif',border=0) return img
def plotBarGraph(identification='', RISet='', vals=None, type="name"): this_identification = "unnamed trait" if identification: this_identification = identification if type=="rank": dataXZ = vals[:] dataXZ.sort(webqtlUtil.cmpOrder) title='%s' % this_identification else: dataXZ = vals[:] title='%s' % this_identification tvals = [] tnames = [] tvars = [] for i in range(len(dataXZ)): tvals.append(dataXZ[i][1]) tnames.append(webqtlUtil.genShortStrainName(RISet=RISet, input_strainName=dataXZ[i][0])) tvars.append(dataXZ[i][2]) nnStrain = len(tnames) sLabel = 1 ###determine bar width and space width if nnStrain < 20: sw = 4 elif nnStrain < 40: sw = 3 else: sw = 2 ### 700 is the default plot width minus Xoffsets for 40 strains defaultWidth = 650 if nnStrain > 40: defaultWidth += (nnStrain-40)*10 defaultOffset = 100 bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) if bw < 10: bw = 10 plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset plotHeight = 500 #print [plotWidth, plotHeight, bw, sw, nnStrain] c = pid.PILCanvas(size=(plotWidth,plotHeight)) Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title=title, sLabel = sLabel, barSpace = sw) filename= webqtlUtil.genRandStr("Bar_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img=HT.Image('/image/'+filename+'.gif',border=0) return img
def __init__(self, fd): templatePage.__init__(self, fd) self.initializeDisplayParameters(fd) if not fd.genotype: fd.readGenotype() if fd.allstrainlist: mdpchoice = fd.formdata.getvalue('MDPChoice') if mdpchoice == "1": strainlist = fd.f1list + fd.strainlist elif mdpchoice == "2": strainlist = [] strainlist2 = fd.f1list + fd.strainlist for strain in fd.allstrainlist: if strain not in strainlist2: strainlist.append(strain) #So called MDP Panel if strainlist: strainlist = fd.f1list+fd.parlist+strainlist else: strainlist = fd.allstrainlist fd.readData(fd.allstrainlist) else: mdpchoice = None strainlist = fd.strainlist fd.readData() #if fd.allstrainlist: # fd.readData(fd.allstrainlist) # strainlist = fd.allstrainlist #else: # fd.readData() # strainlist = fd.strainlist if not self.openMysql(): return isSampleCorr = 0 #XZ: initial value is false isTissueCorr = 0 #XZ: initial value is false #Javascript functions (showCorrelationPlot2, showTissueCorrPlot) have made sure the correlation type is either sample correlation or tissue correlation. if (self.database and (self.ProbeSetID != 'none')): isSampleCorr = 1 elif (self.X_geneSymbol and self.Y_geneSymbol): isTissueCorr = 1 else: heading = "Correlation Type Error" detail = ["For the input parameters, GN can not recognize the correlation type is sample correlation or tissue correlation."] self.error(heading=heading,detail=detail) return TD_LR = HT.TD(colspan=2,height=200,width="100%",bgColor='#eeeeee', align="left", wrap="off") dataX=[] dataY=[] dataZ=[] # shortname fullTissueName=[] if isTissueCorr: dataX, dataY, xlabel, ylabel, dataZ, fullTissueName = self.getTissueLabelsValues(X_geneSymbol=self.X_geneSymbol, Y_geneSymbol=self.Y_geneSymbol, TissueProbeSetFreezeId=self.TissueProbeSetFreezeId) plotHeading = HT.Paragraph('Tissue Correlation Scatterplot') plotHeading.__setattr__("class","title") if self.xAxisLabel == '': self.xAxisLabel = xlabel if self.yAxisLabel == '': self.yAxisLabel = ylabel if isSampleCorr: plotHeading = HT.Paragraph('Sample Correlation Scatterplot') plotHeading.__setattr__("class","title") #XZ: retrieve trait 1 info, Y axis trait1_data = [] #trait 1 data trait1Url = '' try: Trait1 = webqtlTrait(db=self.database, name=self.ProbeSetID, cellid=self.CellID, cursor=self.cursor) Trait1.retrieveInfo() Trait1.retrieveData() except: heading = "Retrieve Data" detail = ["The database you just requested has not been established yet."] self.error(heading=heading,detail=detail) return trait1_data = Trait1.exportData(strainlist) if Trait1.db.type == 'Publish' and Trait1.confidential: trait1Url = Trait1.genHTML(dispFromDatabase=1, privilege=self.privilege, userName=self.userName, authorized_users=Trait1.authorized_users) else: trait1Url = Trait1.genHTML(dispFromDatabase=1) if self.yAxisLabel == '': self.yAxisLabel= '%s : %s' % (Trait1.db.shortname, Trait1.name) if Trait1.cellid: self.yAxisLabel += ' : ' + Trait1.cellid #XZ, retrieve trait 2 info, X axis traitdata2 = [] #trait 2 data _vals = [] #trait 2 data trait2Url = '' if ( self.database2 and (self.ProbeSetID2 != 'none') ): try: Trait2 = webqtlTrait(db=self.database2, name=self.ProbeSetID2, cellid=self.CellID2, cursor=self.cursor) Trait2.retrieveInfo() Trait2.retrieveData() except: heading = "Retrieve Data" detail = ["The database you just requested has not been established yet."] self.error(heading=heading,detail=detail) return if Trait2.db.type == 'Publish' and Trait2.confidential: trait2Url = Trait2.genHTML(dispFromDatabase=1, privilege=self.privilege, userName=self.userName, authorized_users=Trait2.authorized_users) else: trait2Url = Trait2.genHTML(dispFromDatabase=1) traitdata2 = Trait2.exportData(strainlist) _vals = traitdata2[:] if self.xAxisLabel == '': self.xAxisLabel = '%s : %s' % (Trait2.db.shortname, Trait2.name) if Trait2.cellid: self.xAxisLabel += ' : ' + Trait2.cellid else: for item in strainlist: if fd.allTraitData.has_key(item): _vals.append(fd.allTraitData[item].val) else: _vals.append(None) if self.xAxisLabel == '': if fd.identification: self.xAxisLabel = fd.identification else: self.xAxisLabel = "User Input Data" try: Trait2 = webqtlTrait(fullname=fd.formdata.getvalue('fullname'), cursor=self.cursor) trait2Url = Trait2.genHTML(dispFromDatabase=1) except: trait2Url = self.xAxisLabel if (_vals and trait1_data): if len(_vals) != len(trait1_data): errors = HT.Blockquote(HT.Font('Error: ',color='red'),HT.Font('The number of traits are inconsistent, Program quit',color='black')) errors.__setattr__("class","subtitle") TD_LR.append(errors) self.dict['body'] = str(TD_LR) return for i in range(len(_vals)): if _vals[i]!= None and trait1_data[i]!= None: dataX.append(_vals[i]) dataY.append(trait1_data[i]) strainName = strainlist[i] if self.showstrains: dataZ.append(webqtlUtil.genShortStrainName(RISet=fd.RISet, input_strainName=strainName)) else: heading = "Correlation Plot" detail = ['Empty Dataset for sample correlation, please check your data.'] self.error(heading=heading,detail=detail) return #XZ: We have gotten all data for both traits. if len(dataX) >= self.corrMinInformative: if self.rankOrder == 0: rankPrimary = 0 rankSecondary = 1 else: rankPrimary = 1 rankSecondary = 0 lineColor = self.setLineColor(); symbolColor = self.setSymbolColor(); idColor = self.setIdColor(); c = pid.PILCanvas(size=(self.plotSize, self.plotSize*0.90)) data_coordinate = Plot.plotXY(canvas=c, dataX=dataX, dataY=dataY, rank=rankPrimary, dataLabel = dataZ, labelColor=pid.black, lineSize=self.lineSize, lineColor=lineColor, idColor=idColor, idFont=self.idFont, idSize=self.idSize, symbolColor=symbolColor, symbolType=self.symbol, filled=self.filled, symbolSize=self.symbolSize, XLabel=self.xAxisLabel, connectdot=0, YLabel=self.yAxisLabel, title='', fitcurve=self.showline, displayR =1, offset= (90, self.plotSize/20, self.plotSize/10, 90), showLabel = self.showIdentifiers) if rankPrimary == 1: dataXlabel, dataYlabel = webqtlUtil.calRank(xVals=dataX, yVals=dataY, N=len(dataX)) else: dataXlabel, dataYlabel = dataX, dataY gifmap1 = HT.Map(name='CorrelationPlotImageMap1') for i, item in enumerate(data_coordinate): one_rect_coordinate = "%d, %d, %d, %d" % (item[0] - 5, item[1] - 5, item[0] + 5, item[1] + 5) if isTissueCorr: one_rect_title = "%s (%s, %s)" % (fullTissueName[i], dataXlabel[i], dataYlabel[i]) else: one_rect_title = "%s (%s, %s)" % (dataZ[i], dataXlabel[i], dataYlabel[i]) gifmap1.areas.append(HT.Area(shape='rect',coords=one_rect_coordinate, title=one_rect_title) ) filename= webqtlUtil.genRandStr("XY_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img1=HT.Image('/image/'+filename+'.gif',border=0, usemap='#CorrelationPlotImageMap1') mainForm_1 = HT.Form( cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name='showDatabase', submit=HT.Input(type='hidden')) hddn = {'FormID':'showDatabase','ProbeSetID':'_','database':'_','CellID':'_','RISet':fd.RISet, 'ProbeSetID2':'_', 'database2':'_', 'CellID2':'_', 'allstrainlist':string.join(fd.strainlist, " "), 'traitList': fd.formdata.getvalue("traitList")} if fd.incparentsf1: hddn['incparentsf1'] = 'ON' for key in hddn.keys(): mainForm_1.append(HT.Input(name=key, value=hddn[key], type='hidden')) if isSampleCorr: mainForm_1.append(HT.P(), HT.Blockquote(HT.Strong('X axis:'),HT.Blockquote(trait2Url),HT.Strong('Y axis:'),HT.Blockquote(trait1Url), style='width: %spx;' % self.plotSize, wrap="hard")) graphForm = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='MDP_Form',submit=HT.Input(type='hidden')) graph_hddn = self.setHiddenParameters(fd, rankPrimary) webqtlUtil.exportData(graph_hddn, fd.allTraitData) #XZ: This is necessary to replot with different groups of strains for key in graph_hddn.keys(): graphForm.append(HT.Input(name=key, value=graph_hddn[key], type='hidden')) options = self.createOptionsMenu(fd, mdpchoice) if (self.showOptions == '0'): showOptionsButton = HT.Input(type='button' ,name='optionsButton',value='Hide Options', onClick="showHideOptions();", Class="button") else: showOptionsButton = HT.Input(type='button' ,name='optionsButton',value='Show Options', onClick="showHideOptions();", Class="button") # updated by NL: 12-07-2011 add variables for tissue abbreviation page if isTissueCorr: graphForm.append(HT.Input(name='shortTissueName', value='', type='hidden')) graphForm.append(HT.Input(name='fullTissueName', value='', type='hidden')) shortTissueNameStr=string.join(dataZ, ",") fullTissueNameStr=string.join(fullTissueName, ",") tissueAbbrButton=HT.Input(type='button' ,name='tissueAbbrButton',value='Show Abbreviations', onClick="showTissueAbbr('MDP_Form','%s','%s')" % (shortTissueNameStr,fullTissueNameStr), Class="button") graphForm.append(showOptionsButton,' ',tissueAbbrButton, HT.BR(), HT.BR()) else: graphForm.append(showOptionsButton, HT.BR(), HT.BR()) graphForm.append(options, HT.BR()) graphForm.append(HT.HR(), HT.BR(), HT.P()) TD_LR.append(plotHeading, HT.BR(),graphForm, HT.BR(), gifmap1, HT.P(), img1, HT.P(), mainForm_1) TD_LR.append(HT.BR(), HT.HR(color="grey", size=5, width="100%")) c = pid.PILCanvas(size=(self.plotSize, self.plotSize*0.90)) data_coordinate = Plot.plotXY(canvas=c, dataX=dataX, dataY=dataY, rank=rankSecondary, dataLabel = dataZ, labelColor=pid.black,lineColor=lineColor, lineSize=self.lineSize, idColor=idColor, idFont=self.idFont, idSize=self.idSize, symbolColor=symbolColor, symbolType=self.symbol, filled=self.filled, symbolSize=self.symbolSize, XLabel=self.xAxisLabel, connectdot=0, YLabel=self.yAxisLabel,title='', fitcurve=self.showline, displayR =1, offset= (90, self.plotSize/20, self.plotSize/10, 90), showLabel = self.showIdentifiers) if rankSecondary == 1: dataXlabel, dataYlabel = webqtlUtil.calRank(xVals=dataX, yVals=dataY, N=len(dataX)) else: dataXlabel, dataYlabel = dataX, dataY gifmap2 = HT.Map(name='CorrelationPlotImageMap2') for i, item in enumerate(data_coordinate): one_rect_coordinate = "%d, %d, %d, %d" % (item[0] - 6, item[1] - 6, item[0] + 6, item[1] + 6) if isTissueCorr: one_rect_title = "%s (%s, %s)" % (fullTissueName[i], dataXlabel[i], dataYlabel[i]) else: one_rect_title = "%s (%s, %s)" % (dataZ[i], dataXlabel[i], dataYlabel[i]) gifmap2.areas.append(HT.Area(shape='rect',coords=one_rect_coordinate, title=one_rect_title) ) filename= webqtlUtil.genRandStr("XY_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img2=HT.Image('/image/'+filename+'.gif',border=0, usemap='#CorrelationPlotImageMap2') mainForm_2 = HT.Form( cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype='multipart/form-data', name='showDatabase2', submit=HT.Input(type='hidden')) hddn = {'FormID':'showDatabase2','ProbeSetID':'_','database':'_','CellID':'_','RISet':fd.RISet, 'ProbeSetID2':'_', 'database2':'_', 'CellID2':'_', 'allstrainlist':string.join(fd.strainlist, " "), 'traitList': fd.formdata.getvalue("traitList")} if fd.incparentsf1: hddn['incparentsf1'] = 'ON' for key in hddn.keys(): mainForm_2.append(HT.Input(name=key, value=hddn[key], type='hidden')) if isSampleCorr: mainForm_2.append(HT.P(), HT.Blockquote(HT.Strong('X axis:'),HT.Blockquote(trait2Url),HT.Strong('Y axis:'),HT.Blockquote(trait1Url), style='width:%spx;' % self.plotSize)) TD_LR.append(HT.BR(), HT.P()) TD_LR.append('\n', gifmap2, HT.P(), HT.P(), img2, HT.P(), mainForm_2) self.dict['body'] = str(TD_LR) else: heading = "Correlation Plot" detail = ['Fewer than %d strain data were entered for %s data set. No statitical analysis has been attempted.' % (self.corrMinInformative, fd.RISet)] self.error(heading=heading,detail=detail) return
def __init__(self, fd): templatePage.__init__(self, fd) self.initializeDisplayParameters(fd) if not fd.genotype: fd.readGenotype() mdpchoice = None strainlist = fd.strainlist fd.readData() if not self.openMysql(): return isSampleCorr = 1 isTissueCorr = 0 TD_LR = HT.TD(colspan=2, height=200, width="100%", bgColor="#eeeeee", align="left", wrap="off") dataX = [] dataY = [] dataZ = [] # shortname fullTissueName = [] xlabel = "" ylabel = "" if isSampleCorr: plotHeading = HT.Paragraph("Sample Correlation Scatterplot") plotHeading.__setattr__("class", "title") # XZ: retrieve trait 1 info, Y axis trait1_data = [] # trait 1 data trait1Url = "" try: Trait1 = webqtlTrait(db=self.database, name=self.ProbeSetID, cellid=self.CellID, cursor=self.cursor) Trait1.retrieveInfo() Trait1.retrieveData() except: heading = "Retrieve Data" detail = ["The database you just requested has not been established yet."] self.error(heading=heading, detail=detail) return trait1_data = Trait1.exportData(strainlist) trait1Url = Trait1.genHTML(dispFromDatabase=1) ylabel = "%s : %s" % (Trait1.db.shortname, Trait1.name) if Trait1.cellid: ylabel += " : " + Trait1.cellid # XZ, retrieve trait 2 info, X axis trait2_data = [] # trait 2 data trait2Url = "" try: Trait2 = webqtlTrait(db=self.database2, name=self.ProbeSetID2, cellid=self.CellID2, cursor=self.cursor) Trait2.retrieveInfo() Trait2.retrieveData() except: heading = "Retrieve Data" detail = ["The database you just requested has not been established yet."] self.error(heading=heading, detail=detail) return trait2_data = Trait2.exportData(strainlist) trait2Url = Trait2.genHTML(dispFromDatabase=1) xlabel = "%s : %s" % (Trait2.db.shortname, Trait2.name) if Trait2.cellid: xlabel += " : " + Trait2.cellid for strain in Trait1.data.keys(): if Trait2.data.has_key(strain): dataX.append(Trait2.data[strain].val) dataY.append(Trait1.data[strain].val) if self.showstrains: dataZ.append(webqtlUtil.genShortStrainName(RISet=fd.RISet, input_strainName=strain)) # XZ: We have gotten all data for both traits. if len(dataX) >= self.corrMinInformative: if self.rankOrder == 0: rankPrimary = 0 rankSecondary = 1 else: rankPrimary = 1 rankSecondary = 0 lineColor = self.setLineColor() symbolColor = self.setSymbolColor() idColor = self.setIdColor() c = pid.PILCanvas(size=(self.plotSize, self.plotSize * 0.90)) data_coordinate = Plot.plotXY( canvas=c, dataX=dataX, dataY=dataY, rank=rankPrimary, dataLabel=dataZ, labelColor=pid.black, lineSize=self.lineSize, lineColor=lineColor, idColor=idColor, idFont=self.idFont, idSize=self.idSize, symbolColor=symbolColor, symbolType=self.symbol, filled=self.filled, symbolSize=self.symbolSize, XLabel=xlabel, connectdot=0, YLabel=ylabel, title="", fitcurve=self.showline, displayR=1, offset=(90, self.plotSize / 20, self.plotSize / 10, 90), showLabel=self.showIdentifiers, ) if rankPrimary == 1: dataXlabel, dataYlabel = webqtlUtil.calRank(xVals=dataX, yVals=dataY, N=len(dataX)) else: dataXlabel, dataYlabel = dataX, dataY gifmap1 = HT.Map(name="CorrelationPlotImageMap1") for i, item in enumerate(data_coordinate): one_rect_coordinate = "%d, %d, %d, %d" % (item[0] - 5, item[1] - 5, item[0] + 5, item[1] + 5) if isTissueCorr: one_rect_title = "%s (%s, %s)" % (fullTissueName[i], dataXlabel[i], dataYlabel[i]) else: one_rect_title = "%s (%s, %s)" % (dataZ[i], dataXlabel[i], dataYlabel[i]) gifmap1.areas.append(HT.Area(shape="rect", coords=one_rect_coordinate, title=one_rect_title)) filename = webqtlUtil.genRandStr("XY_") c.save(webqtlConfig.IMGDIR + filename, format="gif") img1 = HT.Image("/image/" + filename + ".gif", border=0, usemap="#CorrelationPlotImageMap1") mainForm_1 = HT.Form( cgi=os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype="multipart/form-data", name="showDatabase", submit=HT.Input(type="hidden"), ) hddn = { "FormID": "showDatabase", "ProbeSetID": "_", "database": "_", "CellID": "_", "RISet": fd.RISet, "ProbeSetID2": "_", "database2": "_", "CellID2": "_", "allstrainlist": string.join(fd.strainlist, " "), "traitList": fd.formdata.getvalue("traitList"), } if fd.incparentsf1: hddn["incparentsf1"] = "ON" for key in hddn.keys(): mainForm_1.append(HT.Input(name=key, value=hddn[key], type="hidden")) if isSampleCorr: mainForm_1.append( HT.P(), HT.Blockquote( HT.Strong("X axis:"), HT.Blockquote(trait2Url), HT.Strong("Y axis:"), HT.Blockquote(trait1Url), style="width: %spx;" % self.plotSize, wrap="hard", ), ) graphForm = HT.Form( cgi=os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name="MDP_Form", submit=HT.Input(type="hidden"), ) graph_hddn = self.setHiddenParameters(fd, rankPrimary) webqtlUtil.exportData( graph_hddn, fd.allTraitData ) # XZ: This is necessary to replot with different groups of strains for key in graph_hddn.keys(): graphForm.append(HT.Input(name=key, value=graph_hddn[key], type="hidden")) options = self.createOptionsMenu(fd, mdpchoice) if self.showOptions == "0": showOptionsButton = HT.Input( type="button", name="optionsButton", value="Hide Options", onClick="showHideOptions();", Class="button", ) else: showOptionsButton = HT.Input( type="button", name="optionsButton", value="Show Options", onClick="showHideOptions();", Class="button", ) # updated by NL: 12-07-2011 add variables for tissue abbreviation page if isTissueCorr: graphForm.append(HT.Input(name="shortTissueName", value="", type="hidden")) graphForm.append(HT.Input(name="fullTissueName", value="", type="hidden")) shortTissueNameStr = string.join(dataZ, ",") fullTissueNameStr = string.join(fullTissueName, ",") tissueAbbrButton = HT.Input( type="button", name="tissueAbbrButton", value="Show Abbreviations", onClick="showTissueAbbr('MDP_Form','%s','%s')" % (shortTissueNameStr, fullTissueNameStr), Class="button", ) graphForm.append(showOptionsButton, " ", tissueAbbrButton, HT.BR(), HT.BR()) else: graphForm.append(showOptionsButton, HT.BR(), HT.BR()) graphForm.append(options, HT.BR()) graphForm.append(HT.HR(), HT.BR(), HT.P()) TD_LR.append(plotHeading, HT.BR(), graphForm, HT.BR(), gifmap1, HT.P(), img1, HT.P(), mainForm_1) TD_LR.append(HT.BR(), HT.HR(color="grey", size=5, width="100%")) c = pid.PILCanvas(size=(self.plotSize, self.plotSize * 0.90)) data_coordinate = Plot.plotXY( canvas=c, dataX=dataX, dataY=dataY, rank=rankSecondary, dataLabel=dataZ, labelColor=pid.black, lineColor=lineColor, lineSize=self.lineSize, idColor=idColor, idFont=self.idFont, idSize=self.idSize, symbolColor=symbolColor, symbolType=self.symbol, filled=self.filled, symbolSize=self.symbolSize, XLabel=xlabel, connectdot=0, YLabel=ylabel, title="", fitcurve=self.showline, displayR=1, offset=(90, self.plotSize / 20, self.plotSize / 10, 90), showLabel=self.showIdentifiers, ) if rankSecondary == 1: dataXlabel, dataYlabel = webqtlUtil.calRank(xVals=dataX, yVals=dataY, N=len(dataX)) else: dataXlabel, dataYlabel = dataX, dataY gifmap2 = HT.Map(name="CorrelationPlotImageMap2") for i, item in enumerate(data_coordinate): one_rect_coordinate = "%d, %d, %d, %d" % (item[0] - 6, item[1] - 6, item[0] + 6, item[1] + 6) if isTissueCorr: one_rect_title = "%s (%s, %s)" % (fullTissueName[i], dataXlabel[i], dataYlabel[i]) else: one_rect_title = "%s (%s, %s)" % (dataZ[i], dataXlabel[i], dataYlabel[i]) gifmap2.areas.append(HT.Area(shape="rect", coords=one_rect_coordinate, title=one_rect_title)) filename = webqtlUtil.genRandStr("XY_") c.save(webqtlConfig.IMGDIR + filename, format="gif") img2 = HT.Image("/image/" + filename + ".gif", border=0, usemap="#CorrelationPlotImageMap2") mainForm_2 = HT.Form( cgi=os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), enctype="multipart/form-data", name="showDatabase2", submit=HT.Input(type="hidden"), ) hddn = { "FormID": "showDatabase2", "ProbeSetID": "_", "database": "_", "CellID": "_", "RISet": fd.RISet, "ProbeSetID2": "_", "database2": "_", "CellID2": "_", "allstrainlist": string.join(fd.strainlist, " "), "traitList": fd.formdata.getvalue("traitList"), } if fd.incparentsf1: hddn["incparentsf1"] = "ON" for key in hddn.keys(): mainForm_2.append(HT.Input(name=key, value=hddn[key], type="hidden")) if isSampleCorr: mainForm_2.append( HT.P(), HT.Blockquote( HT.Strong("X axis:"), HT.Blockquote(trait2Url), HT.Strong("Y axis:"), HT.Blockquote(trait1Url), style="width:%spx;" % self.plotSize, ), ) TD_LR.append(HT.BR(), HT.P()) TD_LR.append("\n", gifmap2, HT.P(), HT.P(), img2, HT.P(), mainForm_2) self.dict["body"] = str(TD_LR) else: heading = "Correlation Plot" detail = [ "Fewer than %d strain data were entered for %s data set. No statitical analysis has been attempted." % (self.corrMinInformative, fd.RISet) ] self.error(heading=heading, detail=detail) return
def __init__(self, fd): templatePage.__init__(self, fd) if not fd.genotype: fd.readGenotype() strainlist2 = fd.strainlist if fd.allstrainlist: strainlist2 = fd.allstrainlist fd.readData(strainlist2) specialStrains = [] setStrains = [] for item in strainlist2: if item not in fd.strainlist and item.find('F1') < 0: specialStrains.append(item) else: setStrains.append(item) specialStrains.sort() #So called MDP Panel if specialStrains: specialStrains = fd.f1list+fd.parlist+specialStrains self.plotType = fd.formdata.getvalue('ptype', '0') plotStrains = strainlist2 if specialStrains: if self.plotType == '1': plotStrains = setStrains if self.plotType == '2': plotStrains = specialStrains self.dict['title'] = 'Basic Statistics' if not self.openMysql(): return self.showstrains = 1 self.identification = "unnamed trait" self.fullname = fd.formdata.getvalue('fullname', '') if self.fullname: self.Trait = webqtlTrait(fullname=self.fullname, cursor=self.cursor) self.Trait.retrieveInfo() else: self.Trait = None if fd.identification: self.identification = fd.identification self.dict['title'] = self.identification + ' / '+self.dict['title'] TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') ##should not display Variance, but cannot convert Variance to SE #print plotStrains, fd.allTraitData.keys() if len(fd.allTraitData) > 0: vals=[] InformData = [] for _strain in plotStrains: if fd.allTraitData.has_key(_strain): _val, _var = fd.allTraitData[_strain].val, fd.allTraitData[_strain].var if _val != None: vals.append([_strain, _val, _var]) InformData.append(_val) if len(vals) >= self.plotMinInformative: supertable2 = HT.TableLite(border=0, cellspacing=0, cellpadding=5,width="800") staIntro1 = HT.Paragraph("The table and plots below list the basic statistical analysis result of trait",HT.Strong(" %s" % self.identification)) ##### #anova ##### traitmean, traitmedian, traitvar, traitstdev, traitsem, N = reaper.anova(InformData) TDStatis = HT.TD(width="360", valign="top") tbl2 = HT.TableLite(cellpadding=5, cellspacing=0, Class="collap") dataXZ = vals[:] dataXZ.sort(self.cmpValue) tbl2.append(HT.TR(HT.TD("Statistic",align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 200), HT.TD("Value", align="center", Class="fs14 fwb ffl b1 cw cbrb", width = 140))) tbl2.append(HT.TR(HT.TD("N of Cases",align="center", Class="fs13 b1 cbw c222"), HT.TD(N,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("Mean",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.3f" % traitmean,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("Median",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.3f" % traitmedian,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) #tbl2.append(HT.TR(HT.TD("Variance",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), # HT.TD("%2.3f" % traitvar,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("SEM",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.3f" % traitsem,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("SD",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.3f" % traitstdev,nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("Minimum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%s" % dataXZ[0][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD("Maximum",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%s" % dataXZ[-1][1],nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) if self.Trait and self.Trait.db.type == 'ProbeSet': #IRQuest = HT.Href(text="Interquartile Range", url=webqtlConfig.glossaryfile +"#Interquartile",target="_blank", Class="fs14") #IRQuest.append(HT.BR()) #IRQuest.append(" (fold difference)") tbl2.append(HT.TR(HT.TD("Range (log2)",align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.3f" % (dataXZ[-1][1]-dataXZ[0][1]),nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD(HT.Span("Range (fold)"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.2f" % pow(2.0,(dataXZ[-1][1]-dataXZ[0][1])), nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) tbl2.append(HT.TR(HT.TD(HT.Span("Quartile Range",HT.BR()," (fold difference)"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"), HT.TD("%2.2f" % pow(2.0,(dataXZ[int((N-1)*3.0/4.0)][1]-dataXZ[int((N-1)/4.0)][1])), nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) # (Lei Yan) # 2008/12/19 self.Trait.retrieveData() #XZ, 04/01/2009: don't try to get H2 value for probe. if self.Trait.cellid: pass else: self.cursor.execute("SELECT DataId, h2 from ProbeSetXRef WHERE DataId = %d" % self.Trait.mysqlid) dataid, heritability = self.cursor.fetchone() if heritability: tbl2.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("%s" % heritability, nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) else: tbl2.append(HT.TR(HT.TD(HT.Span("Heritability"),align="center", Class="fs13 b1 cbw c222",nowrap="yes"),HT.TD("NaN", nowrap="yes",align="center", Class="fs13 b1 cbw c222"))) # Lei Yan # 2008/12/19 TDStatis.append(tbl2) plotHeight = 220 plotWidth = 120 xLeftOffset = 60 xRightOffset = 25 yTopOffset = 20 yBottomOffset = 53 canvasHeight = plotHeight + yTopOffset + yBottomOffset canvasWidth = plotWidth + xLeftOffset + xRightOffset canvas = pid.PILCanvas(size=(canvasWidth,canvasHeight)) XXX = [('', InformData[:])] Plot.plotBoxPlot(canvas, XXX, offset=(xLeftOffset, xRightOffset, yTopOffset, yBottomOffset), XLabel= "Trait") filename= webqtlUtil.genRandStr("Box_") canvas.save(webqtlConfig.IMGDIR+filename, format='gif') img=HT.Image('/image/'+filename+'.gif',border=0) #supertable2.append(HT.TR(HT.TD(staIntro1, colspan=3 ))) tb = HT.TableLite(border=0, cellspacing=0, cellpadding=0) tb.append(HT.TR(HT.TD(img, align="left", style="border: 1px solid #999999; padding:0px;"))) supertable2.append(HT.TR(TDStatis, HT.TD(tb))) dataXZ = vals[:] tvals = [] tnames = [] tvars = [] for i in range(len(dataXZ)): tvals.append(dataXZ[i][1]) tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) tvars.append(dataXZ[i][2]) nnStrain = len(tnames) sLabel = 1 ###determine bar width and space width if nnStrain < 20: sw = 4 elif nnStrain < 40: sw = 3 else: sw = 2 ### 700 is the default plot width minus Xoffsets for 40 strains defaultWidth = 650 if nnStrain > 40: defaultWidth += (nnStrain-40)*10 defaultOffset = 100 bw = int(0.5+(defaultWidth - (nnStrain-1.0)*sw)/nnStrain) if bw < 10: bw = 10 plotWidth = (nnStrain-1)*sw + nnStrain*bw + defaultOffset plotHeight = 500 #print [plotWidth, plotHeight, bw, sw, nnStrain] c = pid.PILCanvas(size=(plotWidth,plotHeight)) Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (sorted by name)' % self.identification, sLabel = sLabel, barSpace = sw) filename= webqtlUtil.genRandStr("Bar_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img0=HT.Image('/image/'+filename+'.gif',border=0) dataXZ = vals[:] dataXZ.sort(self.cmpValue) tvals = [] tnames = [] tvars = [] for i in range(len(dataXZ)): tvals.append(dataXZ[i][1]) tnames.append(webqtlUtil.genShortStrainName(fd, dataXZ[i][0])) tvars.append(dataXZ[i][2]) c = pid.PILCanvas(size=(plotWidth,plotHeight)) Plot.plotBarText(c, tvals, tnames, variance=tvars, YLabel='Value', title='%s by Case (ranked)' % self.identification, sLabel = sLabel, barSpace = sw) filename= webqtlUtil.genRandStr("Bar_") c.save(webqtlConfig.IMGDIR+filename, format='gif') img1=HT.Image('/image/'+filename+'.gif',border=0) # Lei Yan # 05/18/2009 # report title = HT.Paragraph('REPORT on the variation of Shh (or PCA Composite Trait XXXX) (sonic hedgehog) in the (insert Data set name) of (insert Species informal name, e.g., Mouse, Rat, Human, Barley, Arabidopsis)', Class="title") header = HT.Paragraph('''This report was generated by GeneNetwork on May 11, 2009, at 11.20 AM using the Basic Statistics module (v 1.0) and data from the Hippocampus Consortium M430v2 (Jun06) PDNN data set. For more details and updates on this data set please link to URL:get Basic Statistics''') hr = HT.HR() p1 = HT.Paragraph('''Trait values for Shh were taken from the (insert Database name, Hippocampus Consortium M430v2 (Jun06) PDNN). GeneNetwork contains data for NN (e.g., 99) cases. In general, data are averages for each case. A summary of mean, median, and the range of these data are provided in Table 1 and in the box plot (Figure 1). Data for individual cases are provided in Figure 2A and 2B, often with error bars (SEM). ''') p2 = HT.Paragraph('''Trait values for Shh range 5.1-fold: from a low of 8.2 (please round value) in 129S1/SvImJ to a high of 10.6 (please round value) in BXD9. The interquartile range (the difference between values closest to the 25% and 75% levels) is a more modest 1.8-fold. The mean value is XX. ''') t1 = HT.Paragraph('''Table 1. Summary of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''') f1 = HT.Paragraph('''Figure 1. ''') f1.append(HT.Href(text="Box plot", url="http://davidmlane.com/hyperstat/A37797.html", target="_blank", Class="fs14")) f1.append(HT.Text(''' of Shh data from the Hippocampus Consortium M430v2 (june06) PDNN data set''')) f2A = HT.Paragraph('''Figure 2A: Bar chart of Shh data ordered by case from the Hippocampus Consortium M430v2 (june06) PDNN data set''') f2B = HT.Paragraph('''Figure 2B: Bar chart of Shh values ordered by from the Hippocampus Consortium M430v2 (june06) PDNN data set''') TD_LR.append(HT.Blockquote(title, HT.P(), header, hr, p1, HT.P(), p2, HT.P(), supertable2, t1, f1, HT.P(), img0, f2A, HT.P(), img1, f2B)) self.dict['body'] = str(TD_LR) else: heading = "Basic Statistics" detail = ['Fewer than %d case data were entered for %s data set. No statitical analysis has been attempted.' % (self.plotMinInformative, fd.RISet)] self.error(heading=heading,detail=detail) return else: heading = "Basic Statistics" detail = ['Empty data set, please check your data.'] self.error(heading=heading,detail=detail) return