def traitInfo(self, fd, specialStrains = None):
        species = webqtlDatabaseFunction.retrieveSpecies(cursor=self.cursor, RISet=fd.RISet)
        heading2 = HT.Paragraph(HT.Strong('Population: '), "%s %s" % (species.title(), fd.RISet) , HT.BR())
        if self.Trait:
            trait_url = HT.Href(text=self.Trait.name, url = os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE) + \
                            "?FormID=showDatabase&incparentsf1=1&database=%s&ProbeSetID=%s" % (self.Trait.db.name, self.Trait.name), \
                            target='_blank', Class="fs13 fwn")
            heading2.append(HT.Strong("Database: "),
                    HT.Href(text=self.Trait.db.fullname, url = webqtlConfig.INFOPAGEHREF % self.Trait.db.name ,
                            target='_blank',Class="fs13 fwn"),HT.BR())
            if self.Trait.db.type == 'ProbeSet':
                heading2.append(HT.Strong('Trait ID: '), trait_url, HT.BR(),
                        HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.symbol,id="green"),HT.BR())
                if self.Trait.chr and self.Trait.mb:
                    heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb))
            elif self.Trait.db.type == 'Geno':
                heading2.append(HT.Strong('Locus : '), trait_url, HT.BR())
                #heading2.append(HT.Strong("Gene Symbol: "), HT.Italic('%s' % self.Trait.Symbol,id="green"),HT.BR())
                if self.Trait.chr and self.Trait.mb:
                    heading2.append(HT.Strong("Location: "), 'Chr %s @ %s Mb' % (self.Trait.chr, self.Trait.mb))
            elif self.Trait.db.type == 'Publish':
                heading2.append(HT.Strong('Record ID: '), trait_url, HT.BR())
                heading2.append(HT.Strong('Phenotype: '), self.Trait.phenotype, HT.BR())
                heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR())
            elif self.Trait.db.type == 'Temp':
                heading2.append(HT.Strong('Description: '), self.Trait.description, HT.BR())
                #heading2.append(HT.Strong('Author: '), self.Trait.authors, HT.BR())
            else:
                pass
        else:
            heading2.append(HT.Strong("Trait Name: "), fd.identification)

        if specialStrains:
            mdpform = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='MDP_Form',submit=HT.Input(type='hidden'))
            mdphddn = {'FormID':'dataEditing', 'submitID':'basicStatistics','RISet':fd.RISet, "allstrainlist":string.join(fd.allstrainlist, " "), "ptype":self.plotType, 'identification':fd.identification, "incparentsf1":1}
            if self.fullname:  mdphddn['fullname'] = self.fullname
            webqtlUtil.exportData(mdphddn, fd.allTraitData)
            for key in mdphddn.keys():
                mdpform.append(HT.Input(name=key, value=mdphddn[key], type='hidden'))
            btn0 = HT.Input(type='button' ,name='',value='All Cases',onClick="this.form.ptype.value=0;submit();", Class="button")
            btn1 = HT.Input(type='button' ,name='',value='%s Only' % fd.RISet,onClick="this.form.ptype.value=1;submit();", Class="button")
            btn2 = HT.Input(type='button' ,name='',value='MDP Only', onClick="this.form.ptype.value=2;submit();", Class="button")
            mdpform.append(btn0)
            mdpform.append(btn1)
            mdpform.append(btn2)
            heading2.append(HT.P(), mdpform)

        return HT.Span(heading2)
	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
Esempio n. 3
0
    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 insertCheckPage(self, fd, newRecord):
		#generate html
		form = HT.Form(cgi= os.path.join(webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE), name='dataInput',submit=HT.Input(type='hidden'))
		hddn = {'database':self.db.name, 'curStatus':'insertResult', 'FormID':'dataEditing', 'submitID':'addPublish', 'RISet':fd.RISet}
		
		recordTable = HT.TableLite(border=0, align="left")
		title1 = HT.Paragraph("Trait Information:", Class="subtitle")
		title2 = HT.Paragraph("Trait Data:", Class="subtitle")
		recordInfoContainer = HT.Div(align="left")
		recordDataContainer = HT.Div(align="left")
		addButton = HT.Input(type='submit',name='submit', value='Add to Publish',Class="button")
		resetButton = HT.Input(type='reset',Class="button")

		recordInfoTable = HT.TableLite(border=0, cellspacing=1, cellpadding=5, align="left")
		for field in self.db.disfield:
			if newRecord[field]:
				recordInfoTable.append(HT.TR(
					HT.TD("%s :" % webqtlUtil.formatField(field), Class="fs12 fwb ff1", valign="top",align="right"),
					HT.TD(width=20),HT.TD(newRecord[field])))
				hddn[field] = newRecord[field]

		recordInfoContainer.append(addButton, resetButton, HT.P(), title1, HT.BR(), recordInfoTable)
		
		recordDataTable = HT.TableLite(border=0, width = "80%",cellspacing=3, cellpadding=2)	
		recordDataTable.append(HT.TR(HT.TD('Strain Name',Class="fs12 ffl fwb",align="left"), 
			HT.TD('TraitData',Class="fs12 ffl fwb",align="right"), 
			HT.TD('SE',Class="fs12 ffl fwb",align="right"),
			HT.TD('N Per Strain',Class="fs12 ffl fwb",align="right"),
			HT.TD('&nbsp'*8,Class="fs12 ffl fwb",align="center"),
			HT.TD('Strain Name',Class="fs12 ffl fwb",align="left"), 
			HT.TD('TraitData',Class="fs12 ffl fwb",align="right"), 
			HT.TD('SE',Class="fs12 ffl fwb",align="right"),
			HT.TD('N Per Strain',Class="fs12 ffl fwb",align="right")))
		
		tempTR = HT.TR(align="Center")
		for i, strainName in enumerate(fd.strainlist):
			if fd.allTraitData.has_key(strainName):
				tdata = fd.allTraitData[strainName]
				traitVal, traitVar, traitNP = tdata.val, tdata.var, tdata.N
			else:
				traitVal, traitVar, traitNP = None, None, None
			
			if traitVal != None:	
				traitVal = "%2.3f" % traitVal
			else:
				traitVal = 'x'
			if traitVar != None:	
				traitVar = "%2.3f" % traitVar
			else:
				traitVar = 'x'
			if traitNP != None:	
				traitNP = "%d" % traitNP
			else:
				traitNP = 'x'
					
			tempTR.append(HT.TD(HT.Paragraph(strainName),align='left'), 
				HT.TD(traitVal,align='right'), 
				HT.TD(traitVar,align='right'),
				HT.TD(traitNP,align='right'),
				HT.TD('',align='center'))
			if i % 2:
				recordDataTable.append(tempTR)
				tempTR = HT.TR(align="Center")
				
		if (i+1) % 2:
			tempTR.append(HT.TD(''))
			tempTR.append(HT.TD(''))
			recordDataTable.append(tempTR)

		info = HT.Paragraph("Please review the trait information and data in the text below. Check the values for errors. If no error is found, please click the \"Add to Publish\" button to submit it.")
		recordDataContainer.append(title2, HT.BR(), info, HT.P(), recordDataTable, HT.P(), addButton, resetButton, HT.P())

		recordTable.append(HT.TR(HT.TD(recordInfoContainer)), HT.TR(HT.TD(recordDataContainer)))			

		webqtlUtil.exportData(hddn, fd.allTraitData, 1)
		for key in hddn.keys():
			form.append(HT.Input(name=key, value=hddn[key], type='hidden'))

		
		#############################
		TD_LR = HT.TD(valign="top",colspan=2,bgcolor="#ffffff")
		
		mainTitle = HT.Paragraph("Add Trait to Published Database", Class="title")

		form.append(recordTable)
		
		TD_LR.append(mainTitle, HT.Blockquote(form))
		
		self.dict['body'] = TD_LR