def __init__(self, fd, traitInfos = None): self.fd = fd # This sets self.cursor assert self.openMysql(), "No database" # When is traitInfos used? if traitInfos: database, ProbeSetID, CellID = traitInfos else: print("fd is:", fd) database = fd['database'] ProbeSetID = fd['ProbeSetID'] CellID = fd.get('CellID') thisTrait = webqtlTrait(db=database, name=ProbeSetID, cellid=CellID, cursor=self.cursor) if thisTrait.db.type == "ProbeSet": self.cursor.execute('''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers FROM ProbeSetFreeze WHERE Name = "%s"''' % database) indId, indName, indFullName, confidential, AuthorisedUsers = self.cursor.fetchall()[0] if confidential == 1: access_to_confidential_dataset = 0 #for the dataset that confidentiality is 1 #1. 'admin' and 'root' can see all of the dataset #2. 'user' can see the dataset that AuthorisedUsers contains his id(stored in the Id field of User table) if webqtlConfig.USERDICT[self.privilege] > webqtlConfig.USERDICT['user']: access_to_confidential_dataset = 1 else: AuthorisedUsersList=AuthorisedUsers.split(',') if AuthorisedUsersList.__contains__(self.userName): access_to_confidential_dataset = 1 if not access_to_confidential_dataset: #Error, Confidential Database heading = "Show Database" detail = ["The %s database you selected is not open to the public \ at this time, please go back and select other database." % indFullName] self.error(heading=heading,detail=detail,error="Confidential Database") return print("environ:", request.environ) # Becuase of proxying remote_addr is probably localhost, so we first try for # HTTP_X_FORWARDED_FOR user_ip = request.environ.get('HTTP_X_FORWARDED_FOR') or request.remote_addr # in old app was fd.remote_ip print("user_ip is:", 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: heading = "Retrieve Data" detail = ['For security reasons, the maximum access to a database is \ %d times per day per ip address. You have reached the limit, please \ try it again tomorrow.' % webqtlConfig.DAILYMAXIMUM] self.error(heading=heading,detail=detail) return if thisTrait.db.type != 'ProbeSet' and thisTrait.cellid: heading = "Retrieve Data" detail = ['The Record you requested doesn\'t exist!'] self.error(heading=heading,detail=detail) return ##identification, etc. fd.identification = '%s : %s' % (thisTrait.db.shortname,ProbeSetID) thisTrait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database, ProbeSetID, fd['RISet']) if CellID: fd.identification = '%s/%s'%(fd.identification, CellID) thisTrait.returnURL = '%s&CellID=%s' % (thisTrait.returnURL, CellID) thisTrait.retrieveInfo() thisTrait.retrieveData() self.updMysql() self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)", user_ip) self.openMysql() ##read genotype file fd.RISet = thisTrait.riset fd.readGenotype() #if webqtlUtil.ListNotNull(map(lambda x:x.var, thisTrait.data.values())): if any([x.variance for x in thisTrait.data.values()]): fd.display_variance = True fd.formID = 'varianceChoice' DataEditingPage.__init__(self, fd, thisTrait)
def __init__(self, fd, traitInfos = []): templatePage.__init__(self, fd) if not self.openMysql(): return TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee') if traitInfos: database,ProbeSetID,CellID = traitInfos else: database = fd.formdata.getfirst('database') ProbeSetID = fd.formdata.getfirst('ProbeSetID') CellID = fd.formdata.getfirst('CellID') try: thisTrait = webqtlTrait(db=database, name=ProbeSetID, cellid= CellID, cursor=self.cursor) except: heading = "Trait Data and Analysis Form" detail = ["The trait isn't available currently."] self.error(heading=heading,detail=detail,error="Error") return if thisTrait.db.type == "ProbeSet": self.cursor.execute('''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers FROM ProbeSetFreeze WHERE Name = "%s"''' % database) indId, indName, indFullName, confidential, AuthorisedUsers = self.cursor.fetchall()[0] if confidential == 1: access_to_confidential_dataset = 0 #for the dataset that confidentiality is 1 #1. 'admin' and 'root' can see all of the dataset #2. 'user' can see the dataset that AuthorisedUsers contains his id(stored in the Id field of User table) if webqtlConfig.USERDICT[self.privilege] > webqtlConfig.USERDICT['user']: access_to_confidential_dataset = 1 else: AuthorisedUsersList=AuthorisedUsers.split(',') if AuthorisedUsersList.__contains__(self.userName): access_to_confidential_dataset = 1 if not access_to_confidential_dataset: #Error, Confidential Database heading = "Show Database" detail = ["The %s database you selected is not open to the public \ at this time, please go back and select other database." % indFullName] self.error(heading=heading,detail=detail,error="Confidential Database") return user_ip = fd.remote_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: heading = "Retrieve Data" detail = ['For security reasons, the maximum access to a database is \ %d times per day per ip address. You have reached the limit, please \ try it again tomorrow.' % webqtlConfig.DAILYMAXIMUM] self.error(heading=heading,detail=detail) return else: pass else: pass if thisTrait.db.type != 'ProbeSet' and thisTrait.cellid: heading = "Retrieve Data" detail = ['The Record you requested doesn\'t exist!'] self.error(heading=heading,detail=detail) return #XZ: Aug 23, 2010: I commented out this block because this feature is not used anymore # check if animal information are available """ self.cursor.execute(''' SELECT SampleXRef.ProbeFreezeId FROM SampleXRef, ProbeSetFreeze WHERE SampleXRef.ProbeFreezeId = ProbeSetFreeze.ProbeFreezeId AND ProbeSetFreeze.Name = "%s" ''' % thisTrait.db.name) sampleId = self.cursor.fetchall() if sampleId: thisTrait.strainInfo = 1 else: thisTrait.strainInfo = None """ ##identification, etc. fd.identification = '%s : %s'%(thisTrait.db.shortname,ProbeSetID) thisTrait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ &ProbeSetID=%s&RISet=%s&parentsf1=on' %(database,ProbeSetID,fd.RISet) if CellID: fd.identification = '%s/%s'%(fd.identification, CellID) thisTrait.returnURL = '%s&CellID=%s' % (thisTrait.returnURL, CellID) #retrieve trait information try: thisTrait.retrieveInfo() thisTrait.retrieveData() self.updMysql() self.cursor.execute("insert into AccessLog(accesstime,ip_address) values(Now(),%s)" ,user_ip) self.openMysql() except: heading = "Retrieve Data" detail = ["The information you requested is not avaiable at this time."] self.error(heading=heading,detail=detail) return ##read genotype file fd.RISet = thisTrait.riset fd.readGenotype() if webqtlUtil.ListNotNull(map(lambda x:x.var, thisTrait.data.values())): fd.displayVariance = 1 fd.varianceDispName = 'SE' fd.formID = 'varianceChoice' self.dict['body']= thisTrait DataEditingPage.__init__(self, fd, thisTrait) self.dict['title'] = '%s: Display Trait' % fd.identification
def __init__(self, fd, traitInfos=None): self.fd = fd # This sets self.cursor assert self.openMysql(), "No database" # When is traitInfos used? if traitInfos: database, ProbeSetID, CellID = traitInfos else: print("fd is:", fd) database = fd['database'] ProbeSetID = fd['ProbeSetID'] CellID = fd.get('CellID') thisTrait = webqtlTrait(db=database, name=ProbeSetID, cellid=CellID, cursor=self.cursor) if thisTrait.db.type == "ProbeSet": self.cursor.execute( '''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers FROM ProbeSetFreeze WHERE Name = "%s"''' % database) indId, indName, indFullName, confidential, AuthorisedUsers = self.cursor.fetchall( )[0] if confidential == 1: access_to_confidential_dataset = 0 #for the dataset that confidentiality is 1 #1. 'admin' and 'root' can see all of the dataset #2. 'user' can see the dataset that AuthorisedUsers contains his id(stored in the Id field of User table) if webqtlConfig.USERDICT[ self.privilege] > webqtlConfig.USERDICT['user']: access_to_confidential_dataset = 1 else: AuthorisedUsersList = AuthorisedUsers.split(',') if AuthorisedUsersList.__contains__(self.userName): access_to_confidential_dataset = 1 if not access_to_confidential_dataset: #Error, Confidential Database heading = "Show Database" detail = [ "The %s database you selected is not open to the public \ at this time, please go back and select other database." % indFullName ] self.error(heading=heading, detail=detail, error="Confidential Database") return print("environ:", request.environ) # Becuase of proxying remote_addr is probably localhost, so we first try for # HTTP_X_FORWARDED_FOR user_ip = request.environ.get( 'HTTP_X_FORWARDED_FOR' ) or request.remote_addr # in old app was fd.remote_ip print("user_ip is:", 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: heading = "Retrieve Data" detail = [ 'For security reasons, the maximum access to a database is \ %d times per day per ip address. You have reached the limit, please \ try it again tomorrow.' % webqtlConfig.DAILYMAXIMUM ] self.error(heading=heading, detail=detail) return if thisTrait.db.type != 'ProbeSet' and thisTrait.cellid: heading = "Retrieve Data" detail = ['The Record you requested doesn\'t exist!'] self.error(heading=heading, detail=detail) return ##identification, etc. fd.identification = '%s : %s' % (thisTrait.db.shortname, ProbeSetID) thisTrait.returnURL = webqtlConfig.CGIDIR + webqtlConfig.SCRIPTFILE + '?FormID=showDatabase&database=%s\ &ProbeSetID=%s&RISet=%s&parentsf1=on' % (database, ProbeSetID, fd['RISet']) if CellID: fd.identification = '%s/%s' % (fd.identification, CellID) thisTrait.returnURL = '%s&CellID=%s' % (thisTrait.returnURL, CellID) thisTrait.retrieveInfo() thisTrait.retrieveData() self.updMysql() self.cursor.execute( "insert into AccessLog(accesstime,ip_address) values(Now(),%s)", user_ip) self.openMysql() ##read genotype file fd.RISet = thisTrait.riset fd.readGenotype() #if webqtlUtil.ListNotNull(map(lambda x:x.var, thisTrait.data.values())): if any([x.variance for x in thisTrait.data.values()]): fd.display_variance = True fd.formID = 'varianceChoice' DataEditingPage.__init__(self, fd, thisTrait)
def __init__(self,fd): ########## geneName means symbol ########## geneName = fd.formdata.getvalue('gene') if geneName: geneName = string.strip(geneName) refseq = fd.formdata.getvalue('refseq') if refseq: refseq = string.strip(refseq) genbankid = fd.formdata.getvalue('genbankid') if genbankid: genbankid = string.strip(genbankid) geneid = fd.formdata.getvalue('geneid') if geneid: geneid = string.strip(geneid) species = fd.formdata.getvalue('species') tissue = fd.formdata.getvalue('tissue') database = fd.formdata.getvalue('database') ########## searchAlias is just a singal, so it doesn't need be stripped ########## searchAlias = fd.formdata.getvalue('searchAlias') if not self.openMysql(): return if database: if geneName: if searchAlias: self.cursor.execute(""" SELECT ProbeSetXRef.* FROM ProbeSet, ProbeSetXRef, DBList WHERE ProbeSetXRef.ProbeSetFreezeId = DBList.FreezeId AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND (DBList.Name=%s or DBList.Code=%s) AND MATCH (ProbeSet.symbol, alias) AGAINST ("+%s" IN BOOLEAN MODE) ORDER BY ProbeSetXRef.mean DESC """ , (database, database, geneName)) else: self.cursor.execute(""" SELECT ProbeSetXRef.* FROM ProbeSet, ProbeSetXRef, DBList WHERE ProbeSetXRef.ProbeSetFreezeId = DBList.FreezeId AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND (DBList.Name=%s or DBList.Code=%s) AND ProbeSet.symbol = %s ORDER BY ProbeSetXRef.mean DESC """ , (database, database, geneName)) elif refseq: self.cursor.execute(""" SELECT ProbeSetXRef.* FROM ProbeSet, ProbeSetXRef, DBList WHERE ProbeSetXRef.ProbeSetFreezeId = DBList.FreezeId AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND (DBList.Name=%s or DBList.Code=%s) AND ProbeSet.RefSeq_TranscriptId = %s ORDER BY ProbeSetXRef.mean DESC """ , (database, database, refseq)) elif genbankid: self.cursor.execute(""" SELECT ProbeSetXRef.* FROM ProbeSet, ProbeSetXRef, DBList WHERE ProbeSetXRef.ProbeSetFreezeId = DBList.FreezeId AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND (DBList.Name=%s or DBList.Code=%s) AND ProbeSet.GenbankId = %s ORDER BY ProbeSetXRef.mean DESC """ , (database, database, genbankid)) elif geneid: self.cursor.execute(""" SELECT ProbeSetXRef.* FROM ProbeSet, ProbeSetXRef, DBList WHERE ProbeSetXRef.ProbeSetFreezeId = DBList.FreezeId AND ProbeSetXRef.ProbeSetId = ProbeSet.Id AND (DBList.Name=%s or DBList.Code=%s) AND ProbeSet.GeneId = %s ORDER BY ProbeSetXRef.mean DESC """ , (database, database, geneid)) Results = self.cursor.fetchone() ########## select the Data that match the selection(currently, only max mean available) ########## if Results: ProbeSetFreezeId = Results[0] ProbeSetId = Results[1] DataId = Results[2] self.cursor.execute(""" select InbredSet.Name from InbredSet, ProbeFreeze, ProbeSetFreeze where InbredSet.Id=ProbeFreeze.InbredSetId and ProbeFreeze.Id=ProbeSetFreeze.ProbeFreezeId and ProbeSetFreeze.Id=%s """, ProbeSetFreezeId) fd.RISet = self.cursor.fetchone()[0] #fd.RISet = Results[0] self.cursor.execute("select Name, FullName from ProbeSetFreeze where Id=%s", ProbeSetFreezeId) fd.database, fd.identification = self.cursor.fetchone() self.cursor.execute("select Name, symbol, description from ProbeSet where Id=%s", ProbeSetId) fd.ProbeSetID, fd.symbol, fd.description = self.cursor.fetchone() fd.identification += ' : '+fd.ProbeSetID fd.formdata['fullname'] = fd.database+'::'+fd.ProbeSetID #XZ, 03/03/2009: Xiaodong changed Data to ProbeSetData self.cursor.execute("select Strain.Name, ProbeSetData.Value from Strain, ProbeSetData where Strain.Id=ProbeSetData.StrainId and ProbeSetData.Id=%s", DataId) Results = self.cursor.fetchall() fd.allstrainlist = [] for item in Results: fd.formdata[item[0]] = item[1] fd.allstrainlist.append(item[0]) #XZ, 03/12/2009: Xiaodong changed SE to ProbeSetSE self.cursor.execute("select Strain.Name, ProbeSetSE.error from Strain, ProbeSetSE where Strain.Id = ProbeSetSE.StrainId and ProbeSetSE.DataId=%s", DataId) Results = self.cursor.fetchall() for item in Results: fd.formdata['V'+item[0]] = item[1] else: fd.RISet = 'BXD' fd.database = 'KI_2A_0405_Rz' fd.ProbeSetID = '1367452_at' else: fd.RISet = 'BXD' fd.database = 'KI_2A_0405_Rz' fd.ProbeSetID = '1367452_at' #BasicStatisticsPage.__init__(self, fd) thisTrait = webqtlTrait(db=fd.database, name=fd.ProbeSetID, cursor=self.cursor) thisTrait.retrieveInfo() thisTrait.retrieveData() DataEditingPage.__init__(self, fd, thisTrait) self.dict['title'] = '%s: Display Trait' % fd.identification