From 94300b4488aa334ced34981981ad5d0ecdec01d6 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Thu, 29 Nov 2012 18:44:01 -0600 Subject: Changed a number of variables (riset to group, db to dataset) Put most of the code for cisLRS and transLRS searches into the class CisTransLrsSearch (might change this name to something else later) Simplified escape code for searches in do_search.py Got search_results working again after some changes --- wqflask/base/data_set.py | 5 +- wqflask/base/webqtlFormData.py | 26 ++++---- wqflask/base/webqtlTrait.py | 146 +++++++++++++++++++++-------------------- 3 files changed, 90 insertions(+), 87 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index d9d3a52b..633f7545 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -392,8 +392,9 @@ class MrnaAssayDataSet(DataSet): if len(description_display) > 1 and description_display != 'N/A' and len(target_string) > 1 and target_string != 'None': description_display = description_display + '; ' + target_string.strip() - # Save it for the jinja2 tablet + # Save it for the jinja2 template this_trait.description_display = description_display + #print(" xxxxdd [%s]: %s" % (type(this_trait.description_display), description_display)) #XZ: trait_location_value is used for sorting trait_location_repr = 'N/A' @@ -418,7 +419,7 @@ class MrnaAssayDataSet(DataSet): where ProbeSetXRef.ProbeSetFreezeId = %s and ProbeSet.Id = ProbeSetXRef.ProbeSetId and ProbeSet.Name = '%s' - """ % (self.db_conn.escape_string(str(this_trait.db.id)), + """ % (self.db_conn.escape_string(str(this_trait.dataset.id)), self.db_conn.escape_string(this_trait.name))) print("query is:", pf(query)) diff --git a/wqflask/base/webqtlFormData.py b/wqflask/base/webqtlFormData.py index ff1db0e8..a3537c87 100755 --- a/wqflask/base/webqtlFormData.py +++ b/wqflask/base/webqtlFormData.py @@ -47,7 +47,7 @@ from utility import webqtlUtil class webqtlFormData(object): 'Represents data from a WebQTL form page, needed to generate the next page' - attrs = ('formID','RISet','genotype','samplelist','allsamplelist', 'display_variance' + attrs = ('formID','group','genotype','samplelist','allsamplelist', 'display_variance' 'suggestive','significance','submitID','identification', 'enablevariance', 'nperm','nboot','email','incparentsf1','genotype_1','genotype_2','traitInfo') @@ -104,11 +104,11 @@ class webqtlFormData(object): self.ppolar = None self.mpolar = None - print("[yellow] self.RISet is:", self.RISet) - if self.RISet: + print("[yellow] self.group is:", self.group) + if self.group: #try: # # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; - _f1, _f12, self.mpolar, self.ppolar = webqtlUtil.ParInfo[self.RISet] + _f1, _f12, self.mpolar, self.ppolar = webqtlUtil.ParInfo[self.group] #except: # f1 = f12 = self.mpolar = self.ppolar = None @@ -129,8 +129,8 @@ class webqtlFormData(object): #self.readGenotype() #self.readData() - if self.RISet == 'BXD300': - self.RISet = 'BXD' + if self.group == 'BXD300': + self.group = 'BXD' def __getitem__(self, key): @@ -153,17 +153,17 @@ class webqtlFormData(object): def readGenotype(self): '''read genotype from .geno file''' - if self.RISet == 'BXD300': - self.RISet = 'BXD' + if self.group == 'BXD300': + self.group = 'BXD' - assert self.RISet, "self.RISet needs to be set" + assert self.group, "self.group needs to be set" #genotype_1 is Dataset Object without parents and f1 #genotype_2 is Dataset Object with parents and f1 (not for intercross) self.genotype_1 = reaper.Dataset() - full_filename = os.path.join(webqtlConfig.GENODIR, self.RISet + '.geno') + full_filename = os.path.join(webqtlConfig.GENODIR, self.group + '.geno') # reaper barfs on unicode filenames, so here we ensure it's a string full_filename = str(full_filename) @@ -173,12 +173,12 @@ class webqtlFormData(object): try: # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; - _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.RISet] + _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.group] except KeyError: _f1 = _f12 = _mat = _pat = None self.genotype_2 = self.genotype_1 - if self.genotype_1.type == "riset" and _mat and _pat: + if self.genotype_1.type == "group" and _mat and _pat: self.genotype_2 = self.genotype_1.add(Mat=_mat, Pat=_pat) #, F1=_f1) #determine default genotype object @@ -333,7 +333,7 @@ class webqtlFormData(object): def Sample(self): 'Create some dummy data for testing' - self.RISet = 'BXD' + self.group = 'BXD' self.incparentsf1 = 'on' #self.display = 9.2 #self.significance = 16.1 diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py index 29087721..cc0e2321 100755 --- a/wqflask/base/webqtlTrait.py +++ b/wqflask/base/webqtlTrait.py @@ -24,11 +24,11 @@ class webqtlTrait: print("in webqtlTrait") self.db_conn = db_conn self.cursor = self.db_conn.cursor() - self.db = None # database object + self.dataset = None # database object self.name = '' # Trait ID, ProbeSet ID, Published ID, etc. self.cellid = '' self.identification = 'un-named trait' - self.riset = '' + self.group = '' self.haveinfo = 0 self.sequence = '' # Blat sequence, available for ProbeSet self.data = {} @@ -41,22 +41,22 @@ class webqtlTrait: elif name == 'fullname': name2 = value.split("::") if len(name2) == 2: - self.db, self.name = name2 + self.dataset, self.name = name2 elif len(name2) == 3: - self.db, self.name, self.cellid = name2 + self.dataset, self.name, self.cellid = name2 else: raise KeyError, repr(value) + ' parameter format error.' else: raise KeyError, repr(name) + ' not a valid parameter for this class.' - if self.db and isinstance(self.db, basestring): + if self.dataset and isinstance(self.dataset, basestring): assert self.cursor, "Don't have a cursor" - self.db = create_dataset(self.db_conn, self.db) + self.dataset = create_dataset(self.db_conn, self.dataset) - #if self.db == None, not from a database - print("self.db is:", self.db, type(self.db)) - if self.db: - if self.db.type == "Temp": + #if self.dataset == None, not from a database + print("self.dataset is:", self.dataset, type(self.dataset)) + if self.dataset: + if self.dataset.type == "Temp": self.cursor.execute(''' SELECT InbredSet.Name @@ -66,9 +66,11 @@ class webqtlTrait: Temp.InbredSetId = InbredSet.Id AND Temp.Name = "%s" ''', self.name) - self.riset = self.cursor.fetchone()[0] + self.group = self.cursor.fetchone()[0] else: - self.riset = self.db.get_group() + self.group = self.dataset.get_group() + + print("trinity, self.group is:", self.group) # # In ProbeSet, there are maybe several annotations match one sequence @@ -82,8 +84,8 @@ class webqtlTrait: # The variable self.sequence should be changed to self.BlatSeq # It also should be changed in other places where it are used. - if self.db: - if self.db.type == 'ProbeSet': + if self.dataset: + if self.dataset.type == 'ProbeSet': print("Doing ProbeSet Query") query = ''' SELECT @@ -95,7 +97,7 @@ class webqtlTrait: ProbeSetFreeze.Id = ProbeSetXRef.ProbeSetFreezeId and ProbeSet.Name = %s and ProbeSetFreeze.Name = %s - ''', (self.name, self.db.name) + ''', (self.name, self.dataset.name) print("query is:", query) self.cursor.execute(*query) self.sequence = self.cursor.fetchone()[0] @@ -104,8 +106,8 @@ class webqtlTrait: def getName(self): str = "" - if self.db and self.name: - str = "%s::%s" % (self.db, self.name) + if self.dataset and self.name: + str = "%s::%s" % (self.dataset, self.name) if self.cellid: str += "::" + self.cellid else: @@ -124,8 +126,8 @@ class webqtlTrait: # def getGivenName(self): str = self.name - if self.db and self.name: - if self.db.type=='Temp': + if self.dataset and self.name: + if self.dataset.type=='Temp': self.cursor.execute('SELECT description FROM Temp WHERE Name=%s', self.name) desc = self.cursor.fetchone()[0] if desc.__contains__('PCA'): @@ -137,16 +139,16 @@ class webqtlTrait: def displayName(self): str = "" - if self.db and self.name: - if self.db.type=='Temp': + if self.dataset and self.name: + if self.dataset.type=='Temp': desc = self.description if desc.__contains__('PCA'): desc = desc[desc.rindex(':')+1:].strip() else: desc = desc[:desc.index('entered')].strip() - str = "%s::%s" % (self.db, desc) + str = "%s::%s" % (self.dataset, desc) else: - str = "%s::%s" % (self.db, self.name) + str = "%s::%s" % (self.dataset, self.name) if self.cellid: str += "::" + self.cellid else: @@ -156,7 +158,7 @@ class webqtlTrait: #def __str__(self): - # #return "%s %s" % (self.getName(), self.riset) + # #return "%s %s" % (self.getName(), self.group) # return self.getName() #__str__ = getName #__repr__ = __str__ @@ -207,7 +209,7 @@ class webqtlTrait: # def getSequence(self): assert self.cursor - if self.db.type == 'ProbeSet': + if self.dataset.type == 'ProbeSet': self.cursor.execute(''' SELECT ProbeSet.BlatSeq @@ -218,7 +220,7 @@ class webqtlTrait: ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and ProbeSet.Name = %s ProbeSetFreeze.Name = %s - ''', self.name, self.db.name) + ''', self.name, self.dataset.name) #self.cursor.execute(query) results = self.fetchone() @@ -230,9 +232,9 @@ class webqtlTrait: if samplelist == None: samplelist = [] - assert self.db and self.cursor + assert self.dataset and self.cursor - if self.db.type == 'Temp': + if self.dataset.type == 'Temp': query = ''' SELECT Strain.Name, TempData.value, TempData.SE, TempData.NStrain, TempData.Id @@ -246,7 +248,7 @@ class webqtlTrait: Strain.Name ''' % self.name #XZ, 03/02/2009: Xiaodong changed Data to PublishData, SE to PublishSE - elif self.db.type == 'Publish': + elif self.dataset.type == 'Publish': query = ''' SELECT Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id @@ -263,7 +265,7 @@ class webqtlTrait: PublishFreeze.Id = %d AND PublishData.StrainId = Strain.Id Order BY Strain.Name - ''' % (self.name, self.db.id) + ''' % (self.name, self.dataset.id) #XZ, 03/02/2009: Xiaodong changed Data to ProbeData, SE to ProbeSE elif self.cellid: @@ -287,9 +289,9 @@ class webqtlTrait: ProbeData.StrainId = Strain.Id Order BY Strain.Name - ''' % (self.cellid, self.name, self.db.name) + ''' % (self.cellid, self.name, self.dataset.name) #XZ, 03/02/2009: Xiaodong added this block for ProbeSetData and ProbeSetSE - elif self.db.type == 'ProbeSet': + elif self.dataset.type == 'ProbeSet': #ProbeSet Data query = ''' SELECT @@ -306,7 +308,7 @@ class webqtlTrait: ProbeSetData.StrainId = Strain.Id Order BY Strain.Name - ''' % (self.name, self.db.name) + ''' % (self.name, self.dataset.name) #XZ, 03/02/2009: Xiaodong changeded Data to GenoData, SE to GenoSE else: #Geno Data @@ -326,7 +328,7 @@ class webqtlTrait: GenoData.StrainId = Strain.Id Order BY Strain.Name - ''' % (webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.db.riset), self.name, self.db.name) + ''' % (webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.dataset.group), self.name, self.dataset.name) self.cursor.execute(query) @@ -341,7 +343,7 @@ class webqtlTrait: if not samplelist or (samplelist and name in samplelist): #if value != None: # num_cases = None - # if self.db.type in ('Publish', 'Temp'): + # if self.dataset.type in ('Publish', 'Temp'): # ndata = item[3] name = item[0] self.data[name] = webqtlCaseData(*item) #name, value, variance, num_cases) @@ -352,7 +354,7 @@ class webqtlTrait: # if val != None: # var = item[2] # ndata = None - # if self.db.type in ('Publish', 'Temp'): + # if self.dataset.type in ('Publish', 'Temp'): # ndata = item[3] # self.data[item[0]] = webqtlCaseData(val, var, ndata) # #end for @@ -370,9 +372,9 @@ class webqtlTrait: # return self.__dict__.items() def retrieveInfo(self, QTL = None): - assert self.db and self.cursor - if self.db.type == 'Publish': - #self.db.DisField = ['Name','PubMed_ID','Phenotype','Abbreviation','Authors','Title',\ + assert self.dataset and self.cursor + if self.dataset.type == 'Publish': + #self.dataset.DisField = ['Name','PubMed_ID','Phenotype','Abbreviation','Authors','Title',\ # 'Abstract', 'Journal','Volume','Pages','Month','Year','Sequence',\ # 'Units', 'comments'] query = ''' @@ -393,11 +395,11 @@ class webqtlTrait: Publication.Id = PublishXRef.PublicationId AND PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND PublishFreeze.Id =%s - ''' % (self.name, self.db.id) + ''' % (self.name, self.dataset.id) #XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name #XZ, 05/08/2009: to avoid the problem of same probeset name from different platforms. - elif self.db.type == 'ProbeSet': - display_fields_string = ',ProbeSet.'.join(self.db.display_fields) + elif self.dataset.type == 'ProbeSet': + display_fields_string = ',ProbeSet.'.join(self.dataset.display_fields) display_fields_string = 'ProbeSet.' + display_fields_string query = """ SELECT %s @@ -407,11 +409,11 @@ class webqtlTrait: ProbeSetXRef.ProbeSetId = ProbeSet.Id AND ProbeSetFreeze.Name = '%s' AND ProbeSet.Name = '%s' - """ % (display_fields_string, self.db.name, self.name) + """ % (display_fields_string, self.dataset.name, self.name) #XZ, 05/08/2009: We also should use Geno.Id to find marker instead of just using Geno.Name # to avoid the problem of same marker name from different species. - elif self.db.type == 'Geno': - display_fields_string = string.join(self.db.display_fields,',Geno.') + elif self.dataset.type == 'Geno': + display_fields_string = string.join(self.dataset.display_fields,',Geno.') display_fields_string = 'Geno.' + display_fields_string query = """ SELECT %s @@ -421,10 +423,10 @@ class webqtlTrait: GenoXRef.GenoId = Geno.Id AND GenoFreeze.Name = '%s' AND Geno.Name = '%s' - """ % (display_fields_string, self.db.name, self.name) + """ % (display_fields_string, self.dataset.name, self.name) else: #Temp type query = 'SELECT %s FROM %s WHERE Name = "%s"' % \ - (string.join(self.db.display_fields,','), self.db.type, self.name) + (string.join(self.dataset.display_fields,','), self.dataset.type, self.name) self.cursor.execute(query) @@ -433,16 +435,16 @@ class webqtlTrait: self.haveinfo = 1 #XZ: assign SQL query result to trait attributes. - for i, field in enumerate(self.db.display_fields): + for i, field in enumerate(self.dataset.display_fields): setattr(self, field, traitInfo[i]) - if self.db.type == 'Publish': + if self.dataset.type == 'Publish': self.confidential = 0 if self.pre_publication_description and not self.pubmed_id: self.confidential = 1 self.homologeneid = None - if self.db.type == 'ProbeSet' and self.riset and self.geneid: + if self.dataset.type == 'ProbeSet' and self.group and self.geneid: #XZ, 05/26/2010: From time to time, this query get error message because some geneid values in database are not number. #XZ: So I have to test if geneid is number before execute the query. #XZ: The geneid values in database should be cleaned up. @@ -463,7 +465,7 @@ class webqtlTrait: InbredSet.Name = '%s' AND InbredSet.SpeciesId = Species.Id AND Species.TaxonomyId = Homologene.TaxonomyId - """ % (self.geneid, self.riset) + """ % (self.geneid, self.group) self.cursor.execute(query) result = self.cursor.fetchone() else: @@ -473,7 +475,7 @@ class webqtlTrait: self.homologeneid = result[0] if QTL: - if self.db.type == 'ProbeSet' and not self.cellid: + if self.dataset.type == 'ProbeSet' and not self.cellid: query = ''' SELECT ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean @@ -483,14 +485,14 @@ class webqtlTrait: ProbeSetXRef.ProbeSetId = ProbeSet.Id AND ProbeSet.Name = "%s" AND ProbeSetXRef.ProbeSetFreezeId =%s - ''' % (self.name, self.db.id) + ''' % (self.name, self.dataset.id) self.cursor.execute(query) traitQTL = self.cursor.fetchone() if traitQTL: self.locus, self.lrs, self.pvalue, self.mean = traitQTL else: self.locus = self.lrs = self.pvalue = self.mean = "" - if self.db.type == 'Publish': + if self.dataset.type == 'Publish': query = ''' SELECT PublishXRef.Locus, PublishXRef.LRS @@ -500,7 +502,7 @@ class webqtlTrait: PublishXRef.Id = %s AND PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND PublishFreeze.Id =%s - ''' % (self.name, self.db.id) + ''' % (self.name, self.dataset.id) self.cursor.execute(query) traitQTL = self.cursor.fetchone() if traitQTL: @@ -514,7 +516,7 @@ class webqtlTrait: if not self.haveinfo: self.retrieveInfo() - if self.db.type == 'Publish': + if self.dataset.type == 'Publish': PubMedLink = "" if self.pubmed_id: PubMedLink = HT.Href(text="PubMed %d : " % self.pubmed_id, @@ -524,10 +526,10 @@ class webqtlTrait: if formName: setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" % - (formName, self.db.name, self.name), Class = "fs14") + (formName, self.dataset.name, self.name), Class = "fs14") else: setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" % - (self.db.name,self.name), Class = "fs14") + (self.dataset.name,self.name), Class = "fs14") if self.confidential and not webqtlUtil.hasAccessToConfidentialPhenotypeTrait(privilege=privilege, userName=userName, authorized_users=authorized_users): setDescription2.append('RecordID/%s - %s' % (self.name, self.pre_publication_description)) @@ -545,20 +547,20 @@ class webqtlTrait: setDescription2.append(HT.Italic('%s, and colleagues' % a1)) setDescription = HT.Span(PubMedLink, setDescription2) - elif self.db.type == 'Temp': + elif self.dataset.type == 'Temp': setDescription = HT.Href(text="%s" % (self.description),url="javascript:showDatabase2\ - ('%s','%s','')" % (self.db.name,self.name), Class = "fs14") + ('%s','%s','')" % (self.dataset.name,self.name), Class = "fs14") setDescription = HT.Span(setDescription) - elif self.db.type == 'Geno': # Genome DB only available for single search + elif self.dataset.type == 'Geno': # Genome DB only available for single search if formName: setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ '%2.3f' % self.mb),url="javascript:showDatabase3('%s','%s','%s','')" % \ - (formName, self.db.name, self.name), Class = "fs14") + (formName, self.dataset.name, self.name), Class = "fs14") else: setDescription = HT.Href(text="Locus %s [Chr %s @ %s Mb]" % (self.name,self.chr,\ '%2.3f' % self.mb),url="javascript:showDatabase2('%s','%s','')" % \ - (self.db.name,self.name), Class = "fs14") + (self.dataset.name,self.name), Class = "fs14") setDescription = HT.Span(setDescription) @@ -566,20 +568,20 @@ class webqtlTrait: if self.cellid: if formName: setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name, self.cellid),url=\ - "javascript:showDatabase3('%s','%s','%s','%s')" % (formName, self.db.name,self.name,self.cellid), \ + "javascript:showDatabase3('%s','%s','%s','%s')" % (formName, self.dataset.name,self.name,self.cellid), \ Class = "fs14") else: setDescription = HT.Href(text="ProbeSet/%s/%s" % (self.name,self.cellid),url=\ - "javascript:showDatabase2('%s','%s','%s')" % (self.db.name,self.name,self.cellid), \ + "javascript:showDatabase2('%s','%s','%s')" % (self.dataset.name,self.name,self.cellid), \ Class = "fs14") else: if formName: setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase3('%s','%s','%s','')" % (formName, self.db.name,self.name), \ + "javascript:showDatabase3('%s','%s','%s','')" % (formName, self.dataset.name,self.name), \ Class = "fs14") else: setDescription = HT.Href(text="ProbeSet/%s" % self.name, url=\ - "javascript:showDatabase2('%s','%s','')" % (self.db.name,self.name), \ + "javascript:showDatabase2('%s','%s','')" % (self.dataset.name,self.name), \ Class = "fs14") if self.symbol and self.chr and self.mb: setDescription.append(' [') @@ -591,9 +593,9 @@ class webqtlTrait: setDescription.append('; %s' % self.probe_target_description) setDescription = HT.Span(setDescription) - if self.db.type != 'Temp' and dispFromDatabase: + if self.dataset.type != 'Temp' and dispFromDatabase: setDescription.append( ' --- FROM : ') - setDescription.append(self.db.genHTML(Class='cori')) + setDescription.append(self.dataset.genHTML(Class='cori')) return setDescription @property @@ -654,13 +656,13 @@ class webqtlTrait: select ProbeFreeze.Name from ProbeFreeze, ProbeSetFreeze where ProbeFreeze.Id = ProbeSetFreeze.ProbeFreezeId AND - ProbeSetFreeze.Id = %d""" % thisTrait.db.id) + ProbeSetFreeze.Id = %d""" % thisTrait.dataset.id) probeDBName = self.cursor.fetchone()[0] return dict(name = probeDBName, url = None) else: - return dict(name = self.db.fullname, - url = webqtlConfig.INFOPAGEHREF % self.db.name) + return dict(name = self.dataset.fullname, + url = webqtlConfig.INFOPAGEHREF % self.dataset.name) def calculate_correlation(self, values, method): """Calculate the correlation value and p value according to the method specified""" -- cgit v1.2.3