aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Ockman2012-06-03 04:08:15 -0400
committerSam Ockman2012-06-03 04:08:15 -0400
commitc1432f41d243047e767a4ec1dc423b9fd0055e0f (patch)
tree7dfecbb76d532c58c794cb6873b611c338db10df
parent93fdf06d57770c985e0ca8169977c210a891e262 (diff)
downloadgenenetwork2-c1432f41d243047e767a4ec1dc423b9fd0055e0f.tar.gz
Cleaning up trait stuff in flask
-rwxr-xr-xwqflask/base/webqtlTrait.py228
-rw-r--r--wqflask/wqflask/show_trait/show_trait_page.py42
2 files changed, 145 insertions, 125 deletions
diff --git a/wqflask/base/webqtlTrait.py b/wqflask/base/webqtlTrait.py
index f5051e45..c3c0cded 100755
--- a/wqflask/base/webqtlTrait.py
+++ b/wqflask/base/webqtlTrait.py
@@ -1,3 +1,5 @@
+from __future__ import division, print_function
+
import string
from htmlgen import HTMLgen2 as HT
@@ -8,14 +10,18 @@ from webqtlDataset import webqtlDataset
from dbFunction import webqtlDatabaseFunction
from utility import webqtlUtil
+from pprint import pformat as pf
+
class webqtlTrait:
"""
- Trait class defines a trait in webqtl, can be either Microarray,
+ Trait class defines a trait in webqtl, can be either Microarray,
Published phenotype, genotype, or user input trait
+
"""
def __init__(self, cursor = None, **kw):
+ print("in webqtlTrait")
self.cursor = cursor
self.db = None # database object
self.name = '' # Trait ID, ProbeSet ID, Published ID, etc.
@@ -25,6 +31,9 @@ class webqtlTrait:
self.haveinfo = 0
self.sequence = '' # Blat sequence, available for ProbeSet
self.data = {}
+ print("foo")
+ print("kw in webqtlTrait are:", pf(kw))
+ print("printed\n\n")
for name, value in kw.items():
if self.__dict__.has_key(name):
setattr(self, name, value)
@@ -35,28 +44,29 @@ class webqtlTrait:
elif len(name2) == 3:
self.db, self.name, self.cellid = name2
else:
- raise KeyError, `value` + ' parameter format error.'
+ raise KeyError, repr(value) + ' parameter format error.'
else:
- raise KeyError, `name`+' not a valid parameter for this class.'
-
- if self.db and type(self.db) == type("1"):
- assert self.cursor
+ raise KeyError, repr(name) + ' not a valid parameter for this class.'
+
+ if self.db and isinstance(self.db, basestring):
+ assert self.cursor, "Don't have a cursor"
self.db = webqtlDataset(self.db, self.cursor)
#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":
self.cursor.execute('''
- SELECT
- InbredSet.Name
- FROM
- InbredSet, Temp
- WHERE
- Temp.InbredSetId = InbredSet.Id AND
+ SELECT
+ InbredSet.Name
+ FROM
+ InbredSet, Temp
+ WHERE
+ Temp.InbredSetId = InbredSet.Id AND
Temp.Name = "%s"
- ''' % self.name)
+ ''', self.name)
self.riset = self.cursor.fetchone()[0]
- else:
+ else:
self.riset = self.db.getRISet()
#
@@ -73,8 +83,9 @@ class webqtlTrait:
if self.db:
if self.db.type == 'ProbeSet':
+ print("Doing ProbeSet Query")
query = '''
- SELECT
+ SELECT
ProbeSet.BlatSeq
FROM
ProbeSet, ProbeSetFreeze, ProbeSetXRef
@@ -84,10 +95,11 @@ class webqtlTrait:
ProbeSet.Name = "%s" and
ProbeSetFreeze.Name = "%s"
''' % (self.name, self.db.name)
+ print("query is:", query)
self.cursor.execute(query)
self.sequence = self.cursor.fetchone()[0]
-
+
def getName(self):
str = ""
if self.db and self.name:
@@ -98,12 +110,12 @@ class webqtlTrait:
str = self.description
return str
- #
+ #
# when user enter a trait or GN generate a trait, user want show the name
# not the name that generated by GN randomly, the two follow function are
- # used to give the real name and the database. displayName() will show the
- # database also, getGivenName() just show the name.
- # For other trait, displayName() as same as getName(), getGivenName() as
+ # used to give the real name and the database. displayName() will show the
+ # database also, getGivenName() just show the name.
+ # For other trait, displayName() as same as getName(), getGivenName() as
# same as self.name
#
# Hongqiang 11/29/07
@@ -137,10 +149,10 @@ class webqtlTrait:
str += "::" + self.cellid
else:
str = self.description
-
+
return str
-
+
#def __str__(self):
# #return "%s %s" % (self.getName(), self.riset)
# return self.getName()
@@ -166,7 +178,7 @@ class webqtlTrait:
else:
result.append(None)
return result
-
+
def exportInformative(self, incVar=0):
"""
export informative strain
@@ -195,7 +207,7 @@ class webqtlTrait:
assert self.cursor
if self.db.type == 'ProbeSet':
query = '''
- SELECT
+ SELECT
ProbeSet.BlatSeq
FROM
ProbeSet, ProbeSetFreeze, ProbeSetXRef
@@ -209,40 +221,40 @@ class webqtlTrait:
results = self.fetchone()
return results[0]
-
-
-
+
+
+
def retrieveData(self, strainlist=[]):
assert self.db and self.cursor
if self.db.type == 'Temp':
query = '''
- SELECT
- Strain.Name, TempData.value, TempData.SE, TempData.NStrain, TempData.Id
- FROM
- TempData, Temp, Strain
- WHERE
- TempData.StrainId = Strain.Id AND
- TempData.Id = Temp.DataId AND
+ SELECT
+ Strain.Name, TempData.value, TempData.SE, TempData.NStrain, TempData.Id
+ FROM
+ TempData, Temp, Strain
+ WHERE
+ TempData.StrainId = Strain.Id AND
+ TempData.Id = Temp.DataId AND
Temp.name = '%s'
Order BY
Strain.Name
''' % self.name
#XZ, 03/02/2009: Xiaodong changed Data to PublishData, SE to PublishSE
- elif self.db.type == 'Publish':
+ elif self.db.type == 'Publish':
query = '''
- SELECT
- Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id
- FROM
+ SELECT
+ Strain.Name, PublishData.value, PublishSE.error, NStrain.count, PublishData.Id
+ FROM
(PublishData, Strain, PublishXRef, PublishFreeze)
- left join PublishSE on
+ left join PublishSE on
(PublishSE.DataId = PublishData.Id AND PublishSE.StrainId = PublishData.StrainId)
- left join NStrain on
- (NStrain.DataId = PublishData.Id AND
- NStrain.StrainId = PublishData.StrainId)
- WHERE
- PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND
- PublishData.Id = PublishXRef.DataId AND PublishXRef.Id = %s AND
+ left join NStrain on
+ (NStrain.DataId = PublishData.Id AND
+ NStrain.StrainId = PublishData.StrainId)
+ WHERE
+ PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND
+ PublishData.Id = PublishXRef.DataId AND PublishXRef.Id = %s AND
PublishFreeze.Id = %d AND PublishData.StrainId = Strain.Id
Order BY
Strain.Name
@@ -252,21 +264,21 @@ class webqtlTrait:
elif self.cellid:
#Probe Data
query = '''
- SELECT
- Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id
- FROM
- (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef,
+ SELECT
+ Strain.Name, ProbeData.value, ProbeSE.error, ProbeData.Id
+ FROM
+ (ProbeData, ProbeFreeze, ProbeSetFreeze, ProbeXRef,
Strain, Probe, ProbeSet)
- left join ProbeSE on
+ left join ProbeSE on
(ProbeSE.DataId = ProbeData.Id AND ProbeSE.StrainId = ProbeData.StrainId)
- 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.Name = '%s' AND
- ProbeXRef.DataId = ProbeData.Id AND
+ 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.Name = '%s' AND
+ ProbeXRef.DataId = ProbeData.Id AND
ProbeData.StrainId = Strain.Id
Order BY
Strain.Name
@@ -295,23 +307,23 @@ class webqtlTrait:
#Geno Data
#XZ: The SpeciesId is not necessary, but it's nice to keep it to speed up database search.
query = '''
- SELECT
- Strain.Name, GenoData.value, GenoSE.error, GenoData.Id
- FROM
+ SELECT
+ Strain.Name, GenoData.value, GenoSE.error, GenoData.Id
+ FROM
(GenoData, GenoFreeze, Strain, Geno, GenoXRef)
left join GenoSE on
(GenoSE.DataId = GenoData.Id AND GenoSE.StrainId = GenoData.StrainId)
- WHERE
+ WHERE
Geno.SpeciesId = %s AND Geno.Name = '%s' AND GenoXRef.GenoId = Geno.Id AND
- GenoXRef.GenoFreezeId = GenoFreeze.Id AND
- GenoFreeze.Name = '%s' AND
- GenoXRef.DataId = GenoData.Id AND
+ GenoXRef.GenoFreezeId = GenoFreeze.Id AND
+ GenoFreeze.Name = '%s' AND
+ GenoXRef.DataId = GenoData.Id AND
GenoData.StrainId = Strain.Id
Order BY
Strain.Name
''' % (webqtlDatabaseFunction.retrieveSpeciesId(self.cursor, self.db.riset), self.name, self.db.name)
-
+
self.cursor.execute(query)
results = self.cursor.fetchall()
self.data.clear()
@@ -328,7 +340,7 @@ class webqtlTrait:
ndata = item[3]
self.data[item[0]] = webqtlCaseData(val, var, ndata)
#end for
- else:
+ else:
for item in results:
val = item[1]
if val != None:
@@ -341,16 +353,16 @@ class webqtlTrait:
#end if
else:
pass
-
+
def keys(self):
return self.__dict__.keys()
-
+
def has_key(self, key):
return self.__dict__.has_key(key)
-
+
def items(self):
return self.__dict__.items()
-
+
def retrieveInfo(self, QTL = None):
assert self.db and self.cursor
if self.db.type == 'Publish':
@@ -358,22 +370,22 @@ class webqtlTrait:
# 'Abstract', 'Journal','Volume','Pages','Month','Year','Sequence',\
# 'Units', 'comments']
query = '''
- SELECT
- PublishXRef.Id, Publication.PubMed_ID,
- Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description,
- Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation,
+ SELECT
+ PublishXRef.Id, Publication.PubMed_ID,
+ Phenotype.Pre_publication_description, Phenotype.Post_publication_description, Phenotype.Original_description,
+ Phenotype.Pre_publication_abbreviation, Phenotype.Post_publication_abbreviation,
Phenotype.Lab_code, Phenotype.Submitter, Phenotype.Owner, Phenotype.Authorized_Users,
- Publication.Authors, Publication.Title, Publication.Abstract,
- Publication.Journal, Publication.Volume, Publication.Pages,
- Publication.Month, Publication.Year, PublishXRef.Sequence,
- Phenotype.Units, PublishXRef.comments
- FROM
- PublishXRef, Publication, Phenotype, PublishFreeze
- WHERE
- PublishXRef.Id = %s AND
- Phenotype.Id = PublishXRef.PhenotypeId AND
- Publication.Id = PublishXRef.PublicationId AND
- PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND
+ Publication.Authors, Publication.Title, Publication.Abstract,
+ Publication.Journal, Publication.Volume, Publication.Pages,
+ Publication.Month, Publication.Year, PublishXRef.Sequence,
+ Phenotype.Units, PublishXRef.comments
+ FROM
+ PublishXRef, Publication, Phenotype, PublishFreeze
+ WHERE
+ PublishXRef.Id = %s AND
+ Phenotype.Id = PublishXRef.PhenotypeId AND
+ Publication.Id = PublishXRef.PublicationId AND
+ PublishXRef.InbredSetId = PublishFreeze.InbredSetId AND
PublishFreeze.Id =%s
''' % (self.name, self.db.id)
#XZ, 05/08/2009: Xiaodong add this block to use ProbeSet.Id to find the probeset instead of just using ProbeSet.Name
@@ -382,7 +394,7 @@ class webqtlTrait:
disfieldString = string.join(self.db.disfield,',ProbeSet.')
disfieldString = 'ProbeSet.' + disfieldString
query = """
- SELECT %s
+ SELECT %s
FROM ProbeSet, ProbeSetFreeze, ProbeSetXRef
WHERE
ProbeSetXRef.ProbeSetFreezeId = ProbeSetFreeze.Id AND
@@ -396,7 +408,7 @@ class webqtlTrait:
disfieldString = string.join(self.db.disfield,',Geno.')
disfieldString = 'Geno.' + disfieldString
query = """
- SELECT %s
+ SELECT %s
FROM Geno, GenoFreeze, GenoXRef
WHERE
GenoXRef.GenoFreezeId = GenoFreeze.Id AND
@@ -408,7 +420,7 @@ class webqtlTrait:
query = 'SELECT %s FROM %s WHERE Name = "%s"' % \
(string.join(self.db.disfield,','), self.db.type, self.name)
-
+
self.cursor.execute(query)
traitInfo = self.cursor.fetchone()
if traitInfo:
@@ -457,12 +469,12 @@ class webqtlTrait:
if QTL:
if self.db.type == 'ProbeSet' and not self.cellid:
query = '''
- SELECT
- ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean
- FROM
+ SELECT
+ ProbeSetXRef.Locus, ProbeSetXRef.LRS, ProbeSetXRef.pValue, ProbeSetXRef.mean
+ FROM
ProbeSetXRef, ProbeSet
- WHERE
- ProbeSetXRef.ProbeSetId = ProbeSet.Id AND
+ WHERE
+ ProbeSetXRef.ProbeSetId = ProbeSet.Id AND
ProbeSet.Name = "%s" AND
ProbeSetXRef.ProbeSetFreezeId =%s
''' % (self.name, self.db.id)
@@ -491,11 +503,11 @@ class webqtlTrait:
self.locus = self.lrs = ""
else:
raise KeyError, `self.name`+' information is not found in the database.'
-
+
def genHTML(self, formName = "", dispFromDatabase=0, privilege="guest", userName="Guest", authorized_users=""):
if not self.haveinfo:
self.retrieveInfo()
-
+
if self.db.type == 'Publish':
PubMedLink = ""
if self.pubmed_id:
@@ -503,14 +515,14 @@ class webqtlTrait:
target = "_blank", url = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id)
else:
PubMedLink = HT.Span("Unpublished : ", Class="fs15")
-
+
if formName:
- setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" %
+ setDescription2 = HT.Href(url="javascript:showDatabase3('%s','%s','%s','')" %
(formName, self.db.name, self.name), Class = "fs14")
else:
- setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" %
+ setDescription2 = HT.Href(url="javascript:showDatabase2('%s','%s','')" %
(self.db.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))
else:
@@ -526,12 +538,12 @@ class webqtlTrait:
setDescription2.append(' by ')
setDescription2.append(HT.Italic('%s, and colleagues' % a1))
setDescription = HT.Span(PubMedLink, setDescription2)
-
+
elif self.db.type == 'Temp':
setDescription = HT.Href(text="%s" % (self.description),url="javascript:showDatabase2\
('%s','%s','')" % (self.db.name,self.name), Class = "fs14")
setDescription = HT.Span(setDescription)
-
+
elif self.db.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,\
@@ -541,16 +553,16 @@ class webqtlTrait:
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")
-
+
setDescription = HT.Span(setDescription)
-
+
else:
if self.cellid:
- if formName:
+ 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), \
Class = "fs14")
- else:
+ 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), \
Class = "fs14")
@@ -572,10 +584,8 @@ class webqtlTrait:
if self.probe_target_description:
setDescription.append('; %s' % self.probe_target_description)
setDescription = HT.Span(setDescription)
-
+
if self.db.type != 'Temp' and dispFromDatabase:
setDescription.append( ' --- FROM : ')
setDescription.append(self.db.genHTML(Class='cori'))
return setDescription
-
-
diff --git a/wqflask/wqflask/show_trait/show_trait_page.py b/wqflask/wqflask/show_trait/show_trait_page.py
index 03f8b9b3..c7d6618e 100644
--- a/wqflask/wqflask/show_trait/show_trait_page.py
+++ b/wqflask/wqflask/show_trait/show_trait_page.py
@@ -36,29 +36,39 @@ from DataEditingPage import DataEditingPage
class ShowTraitPage(DataEditingPage):
- def __init__(self, fd, traitInfos = []):
+ def __init__(self, fd, traitInfos = None):
- templatePage.__init__(self, fd)
+ #templatePage.__init__(self, fd)
if not self.openMysql():
return
- TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')
-
+ #TD_LR = HT.TD(height=200,width="100%",bgColor='#eeeeee')
+ print("j2")
+ # When is traitInfos used?
if traitInfos:
- database,ProbeSetID,CellID = traitInfos
+ print("j2.2")
+ 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
-
+ print("j2.3")
+ print("fd is:", fd)
+ database = fd['database']
+ ProbeSetID = fd['ProbeSetID']
+ print("j2.4")
+ CellID = fd.get('CellID')
+ print("j2.6")
+
+ # We're no longer wrapping this in an exception. If we fail, let's fail hard
+ # Log it and fix it
+ #try:
+ print("j3")
+ 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
+ print("j4")
if thisTrait.db.type == "ProbeSet":
self.cursor.execute('''SELECT Id, Name, FullName, confidentiality, AuthorisedUsers