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))
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"
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 __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"
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 __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 __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 __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))