about summary refs log tree commit diff
path: root/web/webqtl/textUI
diff options
context:
space:
mode:
Diffstat (limited to 'web/webqtl/textUI')
-rwxr-xr-xweb/webqtl/textUI/__init__.py0
-rwxr-xr-xweb/webqtl/textUI/cmdClass.py224
-rwxr-xr-xweb/webqtl/textUI/cmdCorrelation.py325
-rwxr-xr-xweb/webqtl/textUI/cmdGeno.py118
-rwxr-xr-xweb/webqtl/textUI/cmdGet.py86
-rwxr-xr-xweb/webqtl/textUI/cmdHelp.py105
-rwxr-xr-xweb/webqtl/textUI/cmdInterval.py174
-rwxr-xr-xweb/webqtl/textUI/cmdMap.py144
-rwxr-xr-xweb/webqtl/textUI/cmdSearchGene.py70
-rwxr-xr-xweb/webqtl/textUI/cmdShowEditing.py50
10 files changed, 1296 insertions, 0 deletions
diff --git a/web/webqtl/textUI/__init__.py b/web/webqtl/textUI/__init__.py
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/web/webqtl/textUI/__init__.py
diff --git a/web/webqtl/textUI/cmdClass.py b/web/webqtl/textUI/cmdClass.py
new file mode 100755
index 00000000..e394218e
--- /dev/null
+++ b/web/webqtl/textUI/cmdClass.py
@@ -0,0 +1,224 @@
+import string
+import os
+import MySQLdb
+
+from base import webqtlConfig
+
+######################################### 
+#      Basic Class
+#########################################
+class cmdClass:
+	def __init__(self,fd):
+		self.contents = []
+		self.accessError = 0
+		self.error = 0
+		self.accessCode = '###Database Code : <a href="%s%s?cmd=help">%s%s?cmd=help</a>' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE)
+		self.data = fd.formdata
+		self.cmdID = self.data.getvalue('cmd')
+		self.showurl = self.data.getvalue('url')
+		self.cursor = None
+		self.user_ip = fd.remote_ip
+		
+		try:
+			if not self.openMysql():
+				self.accessError = 1
+				self.contents = ['###Error: Database is not ready']
+				return
+			
+			if not self.accessCount():
+				self.accessError = 1
+				self.contents = ['###Error: You have reached maximum access today ']
+				return
+			self.accessRecord()
+		except:
+			self.accessError = 1
+			self.contents = ['###Error: Database is not ready']
+			return
+
+		
+		self.probeset = self.data.getvalue('probeset')
+		self.database = self.data.getvalue('db')
+		self.probe = self.data.getvalue('probe')
+		
+		self.sourcedata = []
+		
+		
+		try:
+			self.format = self.data.getvalue('format')[:3]
+		except:
+			self.format = 'row'
+		if not self.probeset or not self.database:
+			self.error = 1
+			return
+
+	def openMysql(self):
+		try:
+			# con = MySQLdb.Connect(db='db_webqtl', host = webqtlConfig.MYSQL_SERVER)
+			# Modified by Fan Zhang
+			con = MySQLdb.Connect(db=webqtlConfig.DB_NAME,host=webqtlConfig.MYSQL_SERVER, user=webqtlConfig.DB_USER,passwd=webqtlConfig.DB_PASSWD)
+			self.cursor = con.cursor()
+			return 1
+		except:
+			return 0
+
+	#XZ, 03/23/2009: The function name is confusing. This function is to get the database type(ProbeSet, Publish, Geno) id.	
+	def getDBId(self,code):
+		self.cursor.execute('SELECT DBType.Name, DBList.FreezeId from DBType, DBList WHERE DBType.Id = DBList.DBTypeId and DBList.code= "%s"' % code)
+		result = self.cursor.fetchall()
+		if not result:
+			return (None, None)
+		else:
+			return result[0]
+
+	#XZ, 03/23/2009: This is to get the inbredset name.
+	def getRISet(self,prefix, DbId):
+		if prefix == 'ProbeSet':
+			self.cursor.execute('SELECT InbredSet.Name from InbredSet, ProbeSetFreeze, ProbeFreeze WHERE ProbeFreeze.InbredSetId = InbredSet.Id and ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId and ProbeSetFreeze.Id = %d' % DbId)
+		else:
+			self.cursor.execute('SELECT InbredSet.Name from %sFreeze, InbredSet WHERE %sFreeze.InbredSetId = InbredSet.Id and %sFreeze.Id = %d' % (prefix, prefix, prefix, DbId))
+		result = self.cursor.fetchall()
+		if result:
+			if result[0][0] == "BXD300":
+				return "BXD"
+			else:
+				return result[0][0]
+		else:
+			return None
+		
+	def accessCount(self):
+		try:
+			user_ip = self.user_ip
+			query = """SELECT count(id) FROM AccessLog WHERE ip_address = %s AND UNIX_TIMESTAMP()-UNIX_TIMESTAMP(accesstime)<86400"""
+			self.cursor.execute(query,user_ip)
+			daycount = self.cursor.fetchall()
+			if daycount:
+				daycount = daycount[0][0]
+				if daycount > webqtlConfig.DAILYMAXIMUM:
+					return 0
+				else:
+					return 1
+			else:
+				return 1
+		except:
+			return 0
+		
+	def accessRecord(self):
+		try:
+			user_ip = self.user_ip
+			self.updMysql()
+			query = """INSERT INTO AccessLog(accesstime,ip_address) values(Now(),%s)""" 
+			self.cursor.execute(query,user_ip)
+			self.openMysql()
+		except:
+			pass
+
+	def __str__(self):
+		text = map(str,self.contents)
+		if self.showurl:
+			text.append('http://%s%s?%s' % (os.environ['HTTP_HOST'],os.environ['SCRIPT_NAME'],os.environ['QUERY_STRING'][:-8]))
+			text += self.sourcedata
+		return string.join(text,'\n')
+
+	def write(self):
+		if self.cursor:
+			self.cursor.close()
+		try:
+			browser = os.environ['HTTP_USER_AGENT']
+			return '<pre>%s</pre>' % str(self)
+		except:
+			return str(self)
+	
+	def write2(self):
+		print str(self)
+	
+	def getTraitData(self, prefix, dbId, probeset, probe = None): 
+		headerDict = {'ProbeSet':'ProbeSetID', 'Publish':'RecordID', 'Geno':'Locus'}
+		if prefix == None or dbId == None:
+			return None, None
+		if probe and prefix=='ProbeSet':
+			#XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=get&probeset=98332_at&db=bra08-03MAS5&probe=pm&format=col
+			if string.lower(probe) in ("all","mm","pm"):
+				query = "SELECT Probe.Name from Probe, ProbeSet WHERE Probe.ProbeSetId = ProbeSet.Id and ProbeSet.Name = '%s' order by Probe.Name" % probeset
+				self.cursor.execute(query)
+				allprobes = self.cursor.fetchall()
+				if not allprobes:
+					return None, None
+					
+				fetchprobes = []
+				for item in allprobes:
+					if probe == 'all':
+						fetchprobes.append(item[0])
+					else:		
+						try:
+							taildigit =  int(item[0][-1]) % 2
+							if probe == "pm" and taildigit == 1:
+								fetchprobes.append(item[0])
+							if probe == "mm" and taildigit == 0:
+								fetchprobes.append(item[0])
+						except:
+							pass
+				if not fetchprobes:
+					return None, None
+				#XZ, 03/05/2009: Xiaodong changed Data to ProbeData	
+				query = "SELECT Strain.Name, ProbeData.value, Probe.Name from ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef, Strain, Probe, ProbeSet WHERE ProbeSet.Name = '%s' and Probe.ProbeSetId = ProbeSet.Id and ProbeXRef.ProbeId = Probe.Id and ProbeXRef.ProbeFreezeId = ProbeFreeze.Id and ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and ProbeSetFreeze.Id = %d and ProbeXRef.DataId = ProbeData.Id and ProbeData.StrainId = Strain.Id and Probe.Name in (%s) order by Strain.Id, Probe.Name " % (probeset,dbId, "'" + string.join(fetchprobes, "', '") +"'")
+				self.cursor.execute(query)
+				traitdata = self.cursor.fetchall()
+				if not traitdata:
+					pass
+				else:
+					nfield = len(fetchprobes)
+					heads = [['ProbeSet'] + [probeset]*nfield]
+					heads.append(['probe'] + fetchprobes)
+					posdict = {}
+					i = 0
+					for item in fetchprobes:
+						posdict[item] = i
+						i += 1
+					prevStrain = ''
+					traitdata2 = []
+					i = -1 
+					for item in traitdata:
+						if item[0] != prevStrain:
+							prevStrain = item[0]
+							i += 1
+							traitdata2.append([item[0]] +  [None] * nfield)
+						else:
+							pass
+						traitdata2[i][posdict[item[-1]]+1] = item[1]
+					
+					traitdata = traitdata2
+			#XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=get&probeset=98332_at&db=bra08-03MAS5&probe=119637&format=col
+			else:
+				heads = [('ProbeSetId', probeset), ('ProbeId',probe)]
+				#XZ, 03/05/2009: Xiaodong changed Data to ProbeData
+				query = "SELECT Strain.Name, ProbeData.value from ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef, Strain, Probe, ProbeSet WHERE Probe.Name = '%s' and ProbeSet.Name = '%s' and Probe.ProbeSetId = ProbeSet.Id and ProbeXRef.ProbeId = Probe.Id and ProbeXRef.ProbeFreezeId = ProbeFreeze.Id and ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and ProbeSetFreeze.Id = %d and ProbeXRef.DataId = ProbeData.Id and ProbeData.StrainId = Strain.Id" % (probe,probeset,dbId)
+				#print 'Content-type: text/html\n'
+				self.cursor.execute(query)
+				traitdata = self.cursor.fetchall()
+		#XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=get&probeset=98332_at&db=bra08-03MAS5&format=col
+		elif prefix=='ProbeSet': #XZ: probeset data
+			heads = [(headerDict[prefix], probeset)]
+			query = "SELECT Strain.Name, %sData.value from %sData, Strain, %s, %sXRef WHERE %s.Name = '%s' and %sXRef.%sId = %s.Id and %sXRef.%sFreezeId = %d and  %sXRef.DataId = %sData.Id and %sData.StrainId = Strain.Id order by Strain.Id" % (prefix, prefix, prefix, prefix, prefix, probeset,prefix, prefix, prefix, prefix, prefix, dbId, prefix, prefix, prefix)
+			self.cursor.execute(query)
+			traitdata = self.cursor.fetchall()
+		#XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=get&probeset=10834&db=BXDPublish&format=col
+		elif prefix=='Publish':
+			heads = [(headerDict[prefix], probeset)]
+			#XZ, 03/05/2009: Xiaodong changed Data to PublishData
+			query = "SELECT Strain.Name, PublishData.value from PublishData, Strain, PublishXRef, PublishFreeze WHERE PublishXRef.InbredSetId = PublishFreeze.InbredSetId and PublishData.Id = PublishXRef.DataId and PublishXRef.Id = %s and PublishFreeze.Id = %d and PublishData.StrainId = Strain.Id" % (probeset, dbId)
+			self.cursor.execute(query)
+			traitdata = self.cursor.fetchall()
+		#XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=get&probeset=rs13475701&db=BXDGeno&format=col
+		else: #XZ: genotype data
+			heads = [(headerDict[prefix], probeset)]
+			RISet = self.getRISet(prefix, dbId)
+			self.cursor.execute("select SpeciesId from InbredSet where Name = '%s'" % RISet)
+			speciesId = self.cursor.fetchone()[0]			
+			#XZ, 03/05/2009: Xiaodong changed Data to %sData
+			query = "SELECT Strain.Name, %sData.value from %sData, Strain, %s, %sXRef WHERE %s.SpeciesId=%s and %s.Name = '%s' and %sXRef.%sId = %s.Id and %sXRef.%sFreezeId = %d and  %sXRef.DataId = %sData.Id and %sData.StrainId = Strain.Id order by Strain.Id" % (prefix, prefix, prefix, prefix, prefix, speciesId, prefix, probeset,prefix, prefix, prefix, prefix, prefix, dbId, prefix, prefix, prefix)
+			self.cursor.execute(query)
+			traitdata = self.cursor.fetchall()
+		if traitdata:
+			return traitdata, heads
+		else:
+			return None, None
diff --git a/web/webqtl/textUI/cmdCorrelation.py b/web/webqtl/textUI/cmdCorrelation.py
new file mode 100755
index 00000000..04595fc5
--- /dev/null
+++ b/web/webqtl/textUI/cmdCorrelation.py
@@ -0,0 +1,325 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import os
+import string
+from math import *
+import time
+
+import reaper
+
+from base import webqtlConfig
+from utility import webqtlUtil
+from cmdClass import cmdClass
+
+
+#########################################
+#      Correlation Class
+#########################################
+class cmdCorrelation(cmdClass):
+
+	calFunction = 'webqtlUtil.calCorrelation'
+
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+
+		self.example = '###Example : <a href="%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&searchdb=BXDPublish&return=500&sort=pvalue">%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&searchdb=BXDPublish&return=500&sort=pvalue</a>' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID, webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID)
+
+		if self.accessError:
+			return
+			
+		self.searchDB = self.data.getvalue('searchdb')
+		if not self.searchDB or self.error:
+			self.contents.append("###Error: source trait doesn't exist or no target database was given")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		
+		try:
+			self.returnNumber = int(self.data.getvalue('return'))
+		except:
+			self.returnNumber = None
+		
+		self.sort = self.data.getvalue('sort')
+
+		prefix, dbId = self.getDBId(self.database)
+		if not prefix or not dbId or (self.probe and string.lower(self.probe) in ("all","mm","pm")):
+			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		RISet = self.getRISet(prefix, dbId)
+		prefix2, dbId2 = self.getDBId(self.searchDB)
+		if not prefix2 or not dbId2:
+			self.contents.append("###Error: target database doesn't exist.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		RISet2 = self.getRISet(prefix2, dbId2)
+		if RISet2 != RISet:
+			self.contents.append("###Error: target database has different Mouse InbredSet.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		
+		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
+		if not traitdata:
+			self.contents.append("###Error: source trait doesn't exist.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+			
+		StrainNames = []
+		sourceTrait = []
+		StrainIds = []
+
+		#XZ, Jan 27, 2011: Only the strains that are of the same inbredset are used to calculate correlation.
+		for item in traitdata:
+			one_strain_name = item[0]
+			one_strain_value = item[1]
+
+			self.cursor.execute('SELECT Strain.Id from Strain,StrainXRef, InbredSet WHERE Strain.Name="%s" and Strain.Id = StrainXRef.StrainId and StrainXRef.InbredSetId = InbredSet.Id and InbredSet.Name = "%s"' % (one_strain_name, RISet2))
+			Results = self.cursor.fetchall()
+			if Results:
+				StrainIds.append('%d' % Results[0][0])
+				StrainNames.append( one_strain_name )
+				sourceTrait.append( one_strain_value )
+
+		correlationArray = []
+
+		useFastMethod = False
+		if prefix2 == "ProbeSet":
+			DatabaseFileName = self.getFileName( target_db_id=dbId2 )
+			DirectoryList = os.listdir(webqtlConfig.TEXTDIR)  ### List of existing text files.  Used to check if a text file already exists
+			if DatabaseFileName in DirectoryList:
+				useFastMethod = True
+
+		if useFastMethod:
+			datasetFile = open(webqtlConfig.TEXTDIR+DatabaseFileName,'r')
+
+			#XZ, 01/08/2009: read the first line
+			line = datasetFile.readline()
+			dataset_strains = webqtlUtil.readLineCSV(line)[1:]
+
+			#XZ, 01/08/2009: This step is critical. It is necessary for this new method.
+			_newvals = []
+			for item in dataset_strains:
+				if item in StrainNames:
+					_newvals.append(sourceTrait[StrainNames.index(item)])
+				else:
+					_newvals.append('None')
+
+			nnCorr = len(_newvals)
+
+			
+			for line in datasetFile:
+				traitdata=webqtlUtil.readLineCSV(line)
+				traitdataName = traitdata[0]
+				traitvals = traitdata[1:]
+
+				corr,nOverlap = webqtlUtil.calCorrelationText(traitvals,_newvals,nnCorr)
+				traitinfo = [traitdataName,corr,nOverlap]
+				correlationArray.append( traitinfo )
+
+		#calculate correlation with slow method
+		else:
+			correlationArray = self.calCorrelation(sourceTrait, self.readDB(StrainIds, prefix2, dbId2) )
+
+		correlationArray.sort(self.cmpCorr) #XZ: Do not forget the sort step
+
+		if not self.returnNumber:
+			correlationArray = correlationArray[:100]
+		else:
+			if self.returnNumber < len(correlationArray):
+				correlationArray = correlationArray[:self.returnNumber]
+		NN = len(correlationArray)
+		for i in range(NN):
+			nOverlap = correlationArray[i][-1]
+			corr = correlationArray[i][-2]
+			if nOverlap < 3:
+				corrPValue = 1.0
+			else:
+				if abs(corr) >= 1.0:
+					corrPValue = 0.0
+				else:
+					ZValue = 0.5*log((1.0+corr)/(1.0-corr))
+					ZValue = ZValue*sqrt(nOverlap-3)
+					corrPValue = 2.0*(1.0 - reaper.normp(abs(ZValue)))
+			correlationArray[i].append(corrPValue)
+		if self.sort == 'pvalue':
+			correlationArray.sort(self.cmpPValue)
+		
+		if prefix2 == 'Publish':
+			self.contents.append("RecordID\tCorrelation\t#Strains\tp-value")
+		elif  prefix2 == 'Geno':
+			self.contents.append("Locus\tCorrelation\t#Strains\tp-value")
+		else:
+			pass
+
+		if prefix2 == 'Publish' or prefix2 == 'Geno':
+			for item in correlationArray:
+				self.contents.append("%s\t%2.6f\t%d\t%2.6f" % tuple(item))
+		else:
+			id = self.data.getvalue('id')
+			if id == 'yes':					
+				self.contents.append("ProbesetID\tCorrelation\t#Strains\tp-value\tGeneID")
+				for item in correlationArray:
+					query = """SELECT GeneID from %s WHERE Name = '%s'""" % (prefix2,item[0])
+					self.cursor.execute(query)
+					results = self.cursor.fetchall()
+					if not results:
+						item = item + [None]
+					else:
+						item = item + list(results[0])
+					self.contents.append("%s\t%2.6f\t%d\t%2.6f\t%s" % tuple(item))
+			elif id == 'only':					
+				self.contents.append("GenID")
+				for item in correlationArray:
+					query = """SELECT GeneID from %s WHERE Name = '%s'""" % (prefix2,item[0])
+					self.cursor.execute(query)
+					results = self.cursor.fetchall()
+					if not results:
+						self.contents.append('None')
+					else:
+						self.contents.append(results[0][0])
+			else:
+				self.contents.append("ProbesetID\tCorrelation\t#Strains\tp-value")
+				for item in correlationArray:
+					self.contents.append("%s\t%2.6f\t%d\t%2.6f" % tuple(item))
+
+
+
+
+	def getFileName(self, target_db_id):
+
+		query = 'SELECT Id, FullName FROM ProbeSetFreeze WHERE Id = %s' %  target_db_id
+		self.cursor.execute(query)
+		result = self.cursor.fetchone()
+		Id = result[0]
+		FullName = result[1]
+		FullName = FullName.replace(' ','_')
+		FullName = FullName.replace('/','_')
+
+		FileName = 'ProbeSetFreezeId_' + str(Id) + '_FullName_' + FullName + '.txt'
+
+		return FileName
+
+
+	
+	def calCorrelation(self,source,target):
+		allcorrelations = []
+		NN = len(source)
+
+		if len(source) != len(target[0]) - 1:
+			return allcorrelations
+		else:
+			for traitData in target:
+				corr,nOverlap = eval("%s(traitData[1:],source,NN)" % self.calFunction)
+				traitinfo = [traitData[0],corr,nOverlap]				
+				allcorrelations.append(traitinfo)
+
+			return allcorrelations
+	
+	def cmpCorr(self,A,B):
+		try:
+			if abs(A[1]) < abs(B[1]):
+				return 1
+			elif abs(A[1]) == abs(B[1]):
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
+
+	def cmpPValue(self,A,B):
+		try:
+			if A[-1] > B[-1]:
+				return 1
+			elif A[-1] ==  B[-1]:
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
+
+
+        def  readDB(self, StrainIds=[], prefix2='', dbId2=''):
+
+                #retrieve data from target database
+                nnn = len(StrainIds) / 25
+                if len(StrainIds) % 25:
+                        nnn += 1
+                oridata = []
+                for step in range(nnn):
+                        temp = []
+                        StrainIdstep = StrainIds[step*25:min(len(StrainIds), (step+1)*25)]
+                        for item in StrainIdstep:
+                                temp.append('T%s.value' % item)
+                        #XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=cor&probeset=100001_at&probe=136415&db=bra08-03MAS5&searchdb=BXDPublish&return=500&sort=pvalue
+                        if prefix2 == "Publish":
+                                query = "SELECT PublishXRef.Id, "
+                                dataStartPos = 1
+                                query += string.join(temp,', ')
+                                query += ' from (PublishXRef, PublishFreeze)\n'
+                                #XZ, 03/05/2009: Xiaodong changed Data to PublishData
+                                for item in StrainIdstep:
+                                        query += 'left join PublishData as T%s on T%s.Id = PublishXRef.DataId and T%s.StrainId=%s\n' %(item,item,item,item)
+                                query += "WHERE PublishXRef.InbredSetId = PublishFreeze.InbredSetId and PublishFreeze.Id = %d" % (dbId2, )
+                        #XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=cor&probeset=100001_at&probe=136415&db=bra08-03MAS5&searchdb=HC_M2_1005_M&return=500&sort=pvalue
+                        #XZ, 03/05/2009: test http://www.genenetwork.org/webqtl/WebQTL.py?cmd=cor&probeset=100001_at&probe=136415&db=bra08-03MAS5&searchdb=BXDGeno&return=500&sort=pvalue
+                        else:
+                                query = "SELECT %s.Name," %  prefix2
+                                query += string.join(temp,', ')
+                                query += ' from (%s, %sXRef, %sFreeze) \n' % (prefix2,prefix2,prefix2)
+                                #XZ, 03/05/2009: Xiaodong changed Data to %sData
+                                for item in StrainIdstep:
+                                        query += 'left join %sData as T%s on T%s.Id = %sXRef.DataId and T%s.StrainId=%s\n' %(prefix2,item,item,prefix2,item,item)
+                                query += "WHERE %sXRef.%sFreezeId = %sFreeze.Id and %sFreeze.Id = %d  and %s.Id = %sXRef.%sId" % (prefix2, prefix2, prefix2, prefix2, dbId2, prefix2, prefix2, prefix2)
+                        self.cursor.execute(query)
+                        results = self.cursor.fetchall()
+                        if not results:
+                                self.contents.append("###Error: target database doesn't exist.")
+                                self.contents.append(self.example)
+                                self.contents.append(self.accessCode)
+                                return
+                        oridata.append(results)
+
+                datasize = len(oridata[0])
+                targetTrait = []
+                for j in range(datasize):
+                        traitdata = list(oridata[0][j])
+                        for i in range(1,nnn):
+                                traitdata += list(oridata[i][j][1:])
+                        targetTrait.append(traitdata)
+
+                return targetTrait
+			
diff --git a/web/webqtl/textUI/cmdGeno.py b/web/webqtl/textUI/cmdGeno.py
new file mode 100755
index 00000000..8dd0f924
--- /dev/null
+++ b/web/webqtl/textUI/cmdGeno.py
@@ -0,0 +1,118 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+import os
+
+import reaper
+
+from base import webqtlConfig
+from cmdClass import cmdClass
+
+#########################################
+#      Geno Class
+#########################################
+class cmdGeno(cmdClass):
+
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+		if self.accessError:
+			return
+		self.error = 0
+		self.RISet = None
+		self.chr = None
+		self.dataset = None
+		self.strainList = []
+		try:
+			self.RISet = self.data.getvalue('riset')
+			if not self.RISet:
+				raise ValueError
+		except:
+			self.error = 1
+			self.contents.append('###Example : http://www.genenetwork.org%s%s?cmd=%s&riset=BXD&chr=1' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID))
+			return
+		try:
+			self.format = self.data.getvalue('format')[:3]
+		except:
+			self.format = 'row'
+
+		try:
+			self.dataset = reaper.Dataset()
+			try:
+				self.dataset.read(os.path.join(webqtlConfig.GENODIR, self.RISet + '.geno'))
+			except:
+				self.dataset.read(os.path.join(webqtlConfig.GENODIR, self.RISet.upper() + '.geno'))
+			self.strainList = list(self.dataset.prgy)
+		except:
+			self.error = 1
+			#traceback.print_exc()	
+			self.contents.append('###The name of RISet is incorrect')
+			return
+
+		try:
+			self.chr = self.data.getvalue('chr')
+			if self.chr:
+				if self.chr == 'X' or self.chr == 'x':
+					self.chr = '20'
+				self.chr = int(self.chr)
+		except:
+			pass
+		
+		self.readGeno()
+
+	def  readGeno(self):
+		try:
+			table = [['Chr'] + ['Locus'] + self.strainList]
+			if self.chr:
+				chr = self.dataset[self.chr-1]
+				for locus in chr:
+					items = string.split(string.join(locus.genotext, " "))
+					items = [chr.name] + [locus.name] + items
+					table += [items]
+			else:
+				for chr in self.dataset:
+					for locus in chr:
+						items = string.split(string.join(locus.genotext, " "))
+						items = [chr.name] + [locus.name] + items
+						table += [items]
+			if self.format == 'col':
+				table = [[r[col] for r in table] for col in range(1, len(table[0]))]
+				table[0][0] = 'Line'
+			lines = string.join(map(lambda x: string.join(x, '\t'), table), '\n')
+			self.contents.append(lines)
+		except:	
+			self.contents =['###Error: Read file error or name of chromosome is incorrect']
+			#traceback.print_exc()	
+			return
+
+		
+			
diff --git a/web/webqtl/textUI/cmdGet.py b/web/webqtl/textUI/cmdGet.py
new file mode 100755
index 00000000..a11c97a3
--- /dev/null
+++ b/web/webqtl/textUI/cmdGet.py
@@ -0,0 +1,86 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+
+from base import webqtlConfig
+from cmdClass import cmdClass
+
+#########################################
+#      Get trait value Class
+#########################################
+class cmdGet(cmdClass):
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+		self.example = '###Example : <a href="%s%s?cmd=%s&probeset=100001_at&db=bra03-03Mas5&probe=all">%s%s?cmd=%s&probeset=100001_at&db=bra03-03Mas5&probe=all</a>' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID, webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID)
+		if self.accessError:
+			return
+		if not self.error:
+			self.readDB()
+		else:
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+
+	def  readDB(self):
+		prefix, dbId = self.getDBId(self.database)
+		
+		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
+		try:	
+			if not traitdata:
+				raise ValueError
+			traitdata = heads + list(traitdata)
+			if self.format == 'col':
+				self.formatCols(traitdata)
+			else:
+				self.formatRows(traitdata)
+		except:
+			self.contents.append('Error: no record was found')
+			self.contents.append(self.accessCode)
+			return
+
+	def formatCols(self, traitdata):
+		for item in traitdata:
+			lines = []
+			for item2 in item:
+				lines.append(item2)
+			lines = string.join(map(str,lines), '\t')
+			self.contents.append(lines)
+			
+	def formatRows(self, traitdata):
+		for i in range(len(traitdata[0])):
+			lines = []
+			for j in range(len(traitdata)):
+				lines.append(traitdata[j][i])
+			lines = string.join(map(str,lines), '\t')
+			self.contents.append(lines)
+
+			
diff --git a/web/webqtl/textUI/cmdHelp.py b/web/webqtl/textUI/cmdHelp.py
new file mode 100755
index 00000000..754ff5b5
--- /dev/null
+++ b/web/webqtl/textUI/cmdHelp.py
@@ -0,0 +1,105 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+
+from base import webqtlConfig
+from base.admin import ADMIN_tissue_alias
+from cmdClass import cmdClass
+
+#########################################
+#      Help Class
+#########################################
+
+#XZ, 03/23/2009: There are several issues need attention.
+#1. Some probeset datasets are not added into DBList.
+#2. Do NOT show confidential datasets. 
+#3. Get rid of ADMIN_tissue_alias. We should use info from database instead.
+
+class cmdHelp(cmdClass):
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+
+		machineParse = self.data.getvalue('parse')
+		topic = self.data.getvalue('topic')
+		if topic:
+			topic = topic.lower()
+			if topic == 'tissue':
+				self.contents.append("%s%s|          %s" %("Tissue", ' '*(50-len("Tissue")), "Tissue Abbreviations"))
+				self.contents.append("%s%s| %s" %("", ' '*50, "(Separated by space, case insensitive)"))
+				self.contents.append("%s|%s" %('_'*50, '_'*40))
+			
+				keys = ADMIN_tissue_alias.keys()
+				keys.sort()
+				for key in keys:
+					self.contents.append("%s%s|   %s" % (key , ' '*(50-len(key)),  string.join(ADMIN_tissue_alias[key], "  ")))
+					self.contents.append("%s|%s" %('_'*50, '_'*40))
+			else:	
+				pass
+		else:
+			self.contents = ["#Use database code table below to access data", "#For machine parse friendly output please use",
+					     "#http://www.genenetwork.org%s%s?cmd=help&parse=machine" % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE)]
+			self.cursor.execute("""(SELECT DBType.Name, DBList.FreezeId, DBList.Code, ProbeSetFreeze.CreateTime as Time
+						from ProbeSetFreeze, DBType, DBList WHERE DBType.Id = DBList.DBTypeId and 
+						DBType.Name = 'ProbeSet' and DBList.FreezeId = ProbeSetFreeze.Id  and 
+						ProbeSetFreeze.public > %d order by ProbeSetFreeze.CreateTime ,DBList.Name, DBList.Id) 
+						UNION 
+						(SELECT DBType.Name, DBList.FreezeId, DBList.Code, PublishFreeze.CreateTime as Time
+						from PublishFreeze, DBType, DBList WHERE DBType.Id = DBList.DBTypeId and 
+						DBType.Name = 'Publish' and DBList.FreezeId = PublishFreeze.Id order by 
+						PublishFreeze.CreateTime ,DBList.Name, DBList.Id) 
+						UNION
+						(SELECT DBType.Name, DBList.FreezeId, DBList.Code, GenoFreeze.CreateTime 
+						from GenoFreeze, DBType, DBList WHERE DBType.Id = DBList.DBTypeId and 
+						DBType.Name = 'Geno' and DBList.FreezeId = GenoFreeze.Id order by 
+						GenoFreeze.CreateTime ,DBList.Name, DBList.Id)""" % webqtlConfig.PUBLICTHRESH)
+			dbs = self.cursor.fetchall()
+			if machineParse =="machine":
+				pass
+			else:
+				self.contents.append("\n")
+				self.contents.append("%s%s|          %s" %("Database_Name", ' '*(50-len("Database_Name")), "Database_Access_Code_Name"))
+				self.contents.append("%s|%s" %('_'*50, '_'*40))
+			for dbInfo in dbs:
+				self.cursor.execute('SELECT FullName from %sFreeze WHERE Id = %d and public > %d' % (dbInfo[0], dbInfo[1],webqtlConfig.PUBLICTHRESH))
+				results = self.cursor.fetchall()
+				if not results:
+					pass
+				else:
+					if machineParse =="machine":
+						self.contents.append(results[0][0]+ ',' +dbInfo[2])
+					else:
+						self.contents.append("%s%s|          %s" %(results[0][0], ' '*(50-len(results[0][0])), dbInfo[2]))
+						self.contents.append("%s|%s" %('_'*50, '_'*40))
+	
+
+			
diff --git a/web/webqtl/textUI/cmdInterval.py b/web/webqtl/textUI/cmdInterval.py
new file mode 100755
index 00000000..0b97c7c3
--- /dev/null
+++ b/web/webqtl/textUI/cmdInterval.py
@@ -0,0 +1,174 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+import os
+
+import reaper
+
+from base import webqtlConfig
+from cmdClass import cmdClass
+		
+#########################################
+#      Interval Mapping Class
+#########################################
+class cmdInterval(cmdClass):
+
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+
+		self.example = '###Example : <a href="%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&sort=pos&return=100&chr=12">%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&sort=pos&return=100&chr=12</a>' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID, webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID)
+		if self.accessError:
+			return
+		self.sort = None
+		self.step = 0.01
+		self.peak = 1
+		self.chr = None
+		self.sort = None
+		self.returnnumber = 20
+		if self.error:
+			self.error = 1
+			self.contents.append(self.example)
+			return
+		else:
+			try:
+				self.sort = self.data.getvalue('sort')
+				if string.lower(self.sort) == 'pos':
+					self.sort = 'pos'
+				else:
+					self.sort = 'lrs'
+			except:
+				self.sort = None
+			
+			try:
+				self.returnnumber = int(self.data.getvalue('return'))
+			except:
+				self.returnnumber = 20
+			try:	
+				self.chr = self.data.getvalue('chr')
+			except:
+				self.chr = None
+				
+			self.readDB()
+
+	def  readDB(self):
+		prefix, dbId = self.getDBId(self.database)
+		if not prefix or not dbId or (self.probe and string.lower(self.probe) in ("all","mm","pm")):
+			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		RISet = self.getRISet(prefix, dbId)
+		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
+		if not traitdata:
+			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+			
+		dataset0 = reaper.Dataset()
+		dataset0.read(os.path.join(webqtlConfig.GENODIR, RISet + '.geno'))
+		strainList = list(dataset0.prgy)
+		dataset = dataset0.addinterval()
+		if self.chr != None:
+			for _chr in dataset:
+				if string.lower(_chr.name) ==  string.lower(self.chr):
+					dataset.chromosome = [_chr]
+					break
+		
+		strains = []
+		trait = []
+		_prgy = dataset.prgy
+		for item in traitdata:
+			if item[0] in _prgy:
+				strains.append(item[0])	
+				trait.append(item[1])
+
+		qtlscan = dataset.regression(strains, trait)
+		LRS = dataset.permutation(strains, trait)
+		nperm = len(LRS)
+		
+		#print inter1[0]
+		returnPeak = []
+		nqtl = len(qtlscan)
+		if self.peak:
+			for i in range(nqtl):
+				if i == 0 or qtlscan[i].locus.chr != qtlscan[i-1].locus.chr:
+					if qtlscan[i].lrs < qtlscan[i+1].lrs:
+						continue
+				elif i == nqtl-1 or qtlscan[i].locus.chr != qtlscan[i+1].locus.chr:
+					if qtlscan[i].lrs < qtlscan[i-1].lrs:
+						continue
+				else:
+					if qtlscan[i].lrs < qtlscan[i+1].lrs or qtlscan[i].lrs < qtlscan[i-1].lrs:
+						continue
+				returnPeak.append(qtlscan[i])
+		else:
+			returnPeak = qtlscan[:]
+			
+		if returnPeak:
+			self.contents.append("Locus\tLRS\tChr\tAdditive\tp-value\tcM") 
+			qtlresult = []
+			for item in returnPeak:
+				p_value = reaper.pvalue(item.lrs,LRS)
+				qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value, item.locus.cM))
+			if self.sort == 'lrs':
+				qtlresult.sort(self.cmpLRS2)
+			for item in qtlresult:
+				self.contents.append("%s\t%2.4f\t%s\t%2.4f\t%1.4f\t%s" % item)
+		else:
+			self.contents.append("###Error: Error occurs while regression.")
+			return
+	
+	def cmpPValue(self,A,B):
+		try:
+			if A[-1] > B[-1]:
+				return 1
+			elif A[-1] ==  B[-1]:
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
+
+	def cmpLRS2(self,A,B):
+		try:
+			if A[1] < B[1]:
+				return 1
+			elif A[1] == B[1]:
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
+
+			
diff --git a/web/webqtl/textUI/cmdMap.py b/web/webqtl/textUI/cmdMap.py
new file mode 100755
index 00000000..1fbff5a5
--- /dev/null
+++ b/web/webqtl/textUI/cmdMap.py
@@ -0,0 +1,144 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+import os
+
+import reaper
+
+from base import webqtlConfig
+from cmdClass import cmdClass
+
+
+#########################################
+#      Mapping Class
+#########################################
+class cmdMap(cmdClass):
+
+	def __init__(self,fd=None):
+
+		cmdClass.__init__(self,fd)
+
+		if not webqtlConfig.TEXTUI:
+			self.contents.append("Please send your request to http://robot.genenetwork.org")
+			return
+
+		self.example = '###Example : <a href="%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&sort=lrs&return=20">%s%s?cmd=%s&probeset=100001_at&probe=136415&db=bra03-03Mas5&sort=lrs&return=20</a>' % (webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID, webqtlConfig.CGIDIR, webqtlConfig.SCRIPTFILE, self.cmdID)
+		if self.accessError:
+			return
+		try:
+			self.returnnumber = int(self.data.getvalue('return'))
+		except:
+			self.returnnumber = None
+		
+		if self.error:
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+		else:
+			self.sort = self.data.getvalue('sort')
+			self.readDB()
+		
+	def  readDB(self):
+		prefix, dbId = self.getDBId(self.database)
+		if not prefix or not dbId or (self.probe and string.lower(self.probe) in ("all","mm","pm")):
+			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+		RISet = self.getRISet(prefix, dbId)
+		traitdata, heads = self.getTraitData(prefix, dbId, self.probeset, self.probe)
+		if not traitdata:
+			self.contents.append("###Error: source trait doesn't exist or SELECT more than one trait.")
+			self.contents.append(self.example)
+			self.contents.append(self.accessCode)
+			return
+			
+		dataset = reaper.Dataset()
+		dataset.read(os.path.join(webqtlConfig.GENODIR, RISet + '.geno'))
+		strainList = list(dataset.prgy)
+		
+		strains = []
+		trait = []
+		_prgy = dataset.prgy
+		for item in traitdata:
+			if item[0] in _prgy:
+				strains.append(item[0])	
+				trait.append(item[1])
+		
+		qtlscan = dataset.regression(strains, trait)
+		LRS = dataset.permutation(strains, trait)
+		nperm = len(LRS)	
+		if qtlscan:
+			self.contents.append("Locus\tLRS\tChr\tAdditive\tp-value") 
+			qtlresult = []
+			if self.returnnumber:
+				self.returnnumber = min(self.returnnumber,len(qtlscan))
+				if self.sort == 'lrs':
+					qtlscan.sort(self.cmpLRS)
+					for item in qtlscan[:self.returnnumber]:
+						p_value = reaper.pvalue(item.lrs,LRS)	
+						qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
+				else:#sort by position
+					qtlscan2 = qtlscan[:]
+					qtlscan2.sort(self.cmpLRS)
+					LRSthresh = qtlscan2[self.returnnumber].lrs
+					for item in qtlscan:
+						if item.lrs >= LRSthresh:
+							p_value = reaper.pvalue(item.lrs,LRS)	
+							qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
+			else:
+				for item in qtlscan:
+					p_value = reaper.pvalue(item.lrs,LRS)
+					qtlresult.append((item.locus.name,item.lrs,item.locus.chr,item.additive,p_value))
+				if self.sort == 'lrs':
+					qtlresult.sort(self.cmpLRS2)
+			for item in qtlresult:
+				self.contents.append("%s\t%2.5f\t%s\t%2.5f\t%1.5f" % item)
+		else:
+			self.contents.append("###Error: Error occurs while regression.")
+			return
+			
+	def cmpLRS(self,A,B):
+		try:
+			if A.lrs < B.lrs:
+				return 1
+			elif A.lrs == B.lrs:
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
+
+	def cmpLRS2(self,A,B):
+		try:
+			if A[1] < B[1]:
+				return 1
+			elif A[1] == B[1]:
+				return 0
+			else:
+				return -1	
+		except:
+			return 0
diff --git a/web/webqtl/textUI/cmdSearchGene.py b/web/webqtl/textUI/cmdSearchGene.py
new file mode 100755
index 00000000..c2c71815
--- /dev/null
+++ b/web/webqtl/textUI/cmdSearchGene.py
@@ -0,0 +1,70 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+import string
+
+from cmdClass import cmdClass
+from search.TextSearchPage import TextSearchPage
+
+######################################### 
+#      Search Gene Symbol PAGE
+#########################################
+class cmdSearchGene(cmdClass):
+	def __init__(self,fd):
+		#example
+		cmdClass.__init__(self,fd)
+		self.page = None
+		self.text = ""
+		fd.geneName = fd.formdata.getvalue('gene')
+		fd.returnFmt = fd.formdata.getvalue('format', 'html')
+		if fd.geneName:
+			fd.geneName = string.strip(fd.geneName)
+		fd.refseq = fd.formdata.getvalue('refseq')
+		if fd.refseq:
+			fd.refseq = string.strip(fd.refseq)
+		fd.genbankid = fd.formdata.getvalue('genbankid')
+		if fd.genbankid:
+			fd.genbankid = string.strip(fd.genbankid)
+		fd.geneid = fd.formdata.getvalue('geneid')
+		if fd.geneid:
+			fd.geneid = string.strip(fd.geneid)
+		if 1:
+			if not (fd.geneName or fd.refseq or fd.genbankid or fd.geneid):
+				raise "ValueError"
+			fd.searchAlias = fd.formdata.getvalue('alias')
+			if fd.searchAlias != '1':
+				fd.searchAlias = None
+			self.page = TextSearchPage(fd)
+			if fd.returnFmt != 'text':
+				pass
+			else:
+				self.text = self.page.output
+				self.page = None
+		elif "ValueError":
+			self.text = "You need to submit a Gene name, a Refseq ID, or a GenBank ID"
+		else:
+			self.text = "Error occurs while searching the database"
+			
diff --git a/web/webqtl/textUI/cmdShowEditing.py b/web/webqtl/textUI/cmdShowEditing.py
new file mode 100755
index 00000000..918e83a7
--- /dev/null
+++ b/web/webqtl/textUI/cmdShowEditing.py
@@ -0,0 +1,50 @@
+# Copyright (C) University of Tennessee Health Science Center, Memphis, TN.
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License
+# as published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Affero General Public License for more details.
+#
+# This program is available from Source Forge: at GeneNetwork Project
+# (sourceforge.net/projects/genenetwork/).
+#
+# Contact Drs. Robert W. Williams and Xiaodong Zhou (2010)
+# at rwilliams@uthsc.edu and xzhou15@uthsc.edu
+#
+#
+#
+# This module is used by GeneNetwork project (www.genenetwork.org)
+#
+# Created by GeneNetwork Core Team 2010/08/10
+#
+# Last updated by GeneNetwork Core Team 2010/10/20
+
+from cmdClass import cmdClass
+from showTrait.ShowTraitPage import ShowTraitPage
+
+
+######################################### 
+#      SHOW DATA-EDITING PAGE
+#########################################
+class cmdShowEditing(cmdClass):
+	def __init__(self,fd):
+		###example = http://www.webqtl.org/cgi-bin/beta/WebQTL?cmd=snp&chr=1&start=0&end=21345677
+		cmdClass.__init__(self,fd)
+		self.page = None
+		prefix, dbId = self.getDBId(self.database)
+		try:
+			if not prefix or not dbId:
+				raise ValueError
+			self.cursor.execute('SELECT Name from %sFreeze WHERE Id=%d' % (prefix, dbId))
+			database = self.cursor.fetchall()[0][0]
+			traitInfos = (database,self.probeset,self.probe)
+			self.page = ShowTraitPage(fd,traitInfos)
+			#self = page
+		except:
+			print "Database Name Incorrect"
+