aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base/trait.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/base/trait.py')
-rw-r--r--wqflask/base/trait.py206
1 files changed, 0 insertions, 206 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index acc055d8..b71dacf6 100644
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -25,10 +25,6 @@ logger = getLogger(__name__ )
from wqflask import user_manager
-def print_mem(stage=""):
- mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
- print("{}: {}".format(stage, mem/1024))
-
class GeneralTrait(object):
"""
Trait class defines a trait in webqtl, can be either Microarray,
@@ -63,9 +59,7 @@ class GeneralTrait(object):
self.symbol = None
self.LRS_score_repr = "N/A"
- self.LRS_score_value = 0
self.LRS_location_repr = "N/A"
- self.LRS_location_value = 1000000
if kw.get('fullname'):
name2 = value.split("::")
@@ -82,90 +76,6 @@ class GeneralTrait(object):
if get_sample_info != False:
self = retrieve_sample_data(self, self.dataset)
-
- def get_name(self):
- stringy = ""
- if self.dataset and self.name:
- stringy = "%s::%s" % (self.dataset, self.name)
- if self.cellid:
- stringy += "::" + self.cellid
- else:
- stringy = self.description
- return stringy
-
-
- def get_given_name(self):
- """
- 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
- same as self.name
-
- Hongqiang 11/29/07
-
- """
- stringy = self.name
- if self.dataset and self.name:
- desc = self.dataset.get_desc()
- if desc:
- #desc = self.handle_pca(desc)
- stringy = desc
- return stringy
-
-
- def display_name(self):
- stringy = ""
- if self.dataset and self.name:
- desc = self.dataset.get_desc()
- #desc = self.handle_pca(desc)
- if desc:
- #desc = self.handle_pca(desc)
- #stringy = desc
- #if desc.__contains__('PCA'):
- # desc = desc[desc.rindex(':')+1:].strip()
- #else:
- # desc = desc[:desc.index('entered')].strip()
- #desc = self.handle_pca(desc)
- stringy = "%s::%s" % (self.dataset, desc)
- else:
- stringy = "%s::%s" % (self.dataset, self.name)
- if self.cellid:
- stringy += "::" + self.cellid
- else:
- stringy = self.description
-
- return stringy
-
-
- #def __str__(self):
- # #return "%s %s" % (self.getName(), self.group)
- # return self.getName()
- #__str__ = getName
- #__repr__ = __str__
-
- def export_data(self, samplelist, the_type="val"):
- """
- export data according to samplelist
- mostly used in calculating correlation
-
- """
- result = []
- for sample in samplelist:
- if self.data.has_key(sample):
- if the_type=='val':
- result.append(self.data[sample].val)
- elif the_type=='var':
- result.append(self.data[sample].var)
- elif the_type=='N':
- result.append(self.data[sample].N)
- else:
- raise KeyError, `the_type`+' the_type is incorrect.'
- else:
- result.append(None)
- return result
-
def export_informative(self, include_variance=0):
"""
export informative sample
@@ -185,19 +95,6 @@ class GeneralTrait(object):
sample_aliases.append(sample_data.name2)
return samples, vals, the_vars, sample_aliases
-
- @property
- def name_header_fmt(self):
- '''Return a human-readable name for use in page header'''
- if self.dataset.type == 'ProbeSet':
- return self.symbol
- elif self.dataset.type == 'Geno':
- return self.name
- elif self.dataset.type == 'Publish':
- return self.post_publication_abbreviation
- else:
- return "unnamed"
-
@property
def description_fmt(self):
'''Return a text formated description'''
@@ -252,29 +149,6 @@ class GeneralTrait(object):
fmt += (' on the minus strand ')
return fmt
-
-# In ProbeSet, there are maybe several annotations match one sequence
-# so we need use sequence(BlatSeq) as the identification, when we update
-# one annotation, we update the others who match the sequence also.
-#
-# Hongqiang Li, 3/3/2008
-def getSequence(trait, dataset_name):
- dataset = create_dataset(dataset_name)
-
- if dataset.type == 'ProbeSet':
- results = g.db.execute('''
- SELECT
- ProbeSet.BlatSeq
- FROM
- ProbeSet, ProbeSetFreeze, ProbeSetXRef
- WHERE
- ProbeSet.Id=ProbeSetXRef.ProbeSetId and
- ProbeSetFreeze.Id = ProbeSetXRef.ProbSetFreezeId and
- ProbeSet.Name = %s
- ProbeSetFreeze.Name = %s
- ''', trait.name, dataset.name).fetchone()
-
- return results[0]
def retrieve_sample_data(trait, dataset, samplelist=None):
if samplelist == None:
@@ -293,18 +167,6 @@ def retrieve_sample_data(trait, dataset, samplelist=None):
if not samplelist or (samplelist and name in samplelist):
trait.data[name] = webqtlCaseData(*item) #name, value, variance, num_cases)
return trait
-
-def convert_location_to_value(chromosome, mb):
- try:
- location_value = int(chromosome)*1000 + float(mb)
- except ValueError:
- if chromosome.upper() == 'X':
- location_value = 20*1000 + float(mb)
- else:
- location_value = (ord(str(chromosome).upper()[0])*1000 +
- float(mb))
-
- return location_value
@app.route("/trait/get_sample_data")
def get_sample_data():
@@ -542,38 +404,7 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
if trait.pubmed_id:
trait.pubmed_link = webqtlConfig.PUBMEDLINK_URL % trait.pubmed_id
-
- trait.homologeneid = None
if dataset.type == 'ProbeSet' and dataset.group:
- if trait.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.
- #try:
- # float(self.geneid)
- # geneidIsNumber = True
- #except ValueError:
- # geneidIsNumber = False
- #if geneidIsNumber:
- query = """
- SELECT
- HomologeneId
- FROM
- Homologene, Species, InbredSet
- WHERE
- Homologene.GeneId ='%s' AND
- InbredSet.Name = '%s' AND
- InbredSet.SpeciesId = Species.Id AND
- Species.TaxonomyId = Homologene.TaxonomyId
- """ % (escape(str(trait.geneid)), escape(dataset.group.name))
- logger.sql(query)
- result = g.db.execute(query).fetchone()
- #else:
- # result = None
-
- if result:
- trait.homologeneid = result[0]
-
description_string = unicode(str(trait.description).strip(codecs.BOM_UTF8), 'utf-8')
target_string = unicode(str(trait.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8')
@@ -589,46 +420,19 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
# Save it for the jinja2 template
trait.description_display = description_display
- #XZ: trait_location_value is used for sorting
trait.location_repr = 'N/A'
- trait.location_value = 1000000
-
if trait.chr and trait.mb:
- #Checks if the chromosome number can be cast to an int (i.e. isn't "X" or "Y")
- #This is so we can convert the location to a number used for sorting
- trait_location_value = convert_location_to_value(trait.chr, trait.mb)
- #try:
- # trait_location_value = int(self.chr)*1000 + self.mb
- #except ValueError:
- # if self.chr.upper() == 'X':
- # trait_location_value = 20*1000 + self.mb
- # else:
- # trait_location_value = (ord(str(self.chr).upper()[0])*1000 +
- # self.mb)
-
- #ZS: Put this in function currently called "convert_location_to_value"
trait.location_repr = 'Chr%s: %.6f' % (trait.chr, float(trait.mb))
- trait.location_value = trait_location_value
elif dataset.type == "Geno":
trait.location_repr = 'N/A'
- trait.location_value = 1000000
-
if trait.chr and trait.mb:
- #Checks if the chromosome number can be cast to an int (i.e. isn't "X" or "Y")
- #This is so we can convert the location to a number used for sorting
- trait_location_value = convert_location_to_value(trait.chr, trait.mb)
-
- #ZS: Put this in function currently called "convert_location_to_value"
trait.location_repr = 'Chr%s: %.6f' % (trait.chr, float(trait.mb))
- trait.location_value = trait_location_value
if get_qtl_info:
#LRS and its location
trait.LRS_score_repr = "N/A"
- trait.LRS_score_value = 0
trait.LRS_location_repr = "N/A"
- trait.LRS_location_value = 1000000
if dataset.type == 'ProbeSet' and not trait.cellid:
query = """
SELECT
@@ -699,19 +503,9 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False):
trait.locus = trait.lrs = trait.additive = ""
if (dataset.type == 'Publish' or dataset.type == "ProbeSet") and trait.locus_chr != "" and trait.locus_mb != "":
- #XZ: LRS_location_value is used for sorting
- try:
- LRS_location_value = int(trait.locus_chr)*1000 + float(trait.locus_mb)
- except:
- if trait.locus_chr.upper() == 'X':
- LRS_location_value = 20*1000 + float(trait.locus_mb)
- else:
- LRS_location_value = ord(str(trait.locus_chr).upper()[0])*1000 + float(trait.locus_mb)
-
trait.LRS_location_repr = LRS_location_repr = 'Chr%s: %.6f' % (trait.locus_chr, float(trait.locus_mb))
if trait.lrs != "":
trait.LRS_score_repr = LRS_score_repr = '%3.1f' % trait.lrs
- trait.LRS_score_value = LRS_score_value = trait.lrs
else:
raise KeyError, `trait.name`+' information is not found in the database.'