aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base/trait.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/base/trait.py')
-rwxr-xr-xwqflask/base/trait.py35
1 files changed, 26 insertions, 9 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py
index dde8b8d8..7847c0a6 100755
--- a/wqflask/base/trait.py
+++ b/wqflask/base/trait.py
@@ -1,6 +1,8 @@
from __future__ import absolute_import, division, print_function
import string
+import resource
+
from htmlgen import HTMLgen2 as HT
@@ -15,7 +17,11 @@ from pprint import pformat as pf
from flask import Flask, g
-class GeneralTrait:
+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,
Published phenotype, genotype, or user input trait
@@ -23,8 +29,12 @@ class GeneralTrait:
"""
def __init__(self, **kw):
- print("in GeneralTrait")
- self.dataset = kw.get('dataset') # database name
+ # xor assertion
+ assert bool(kw.get('dataset')) != bool(kw.get('dataset_name')), "Needs dataset ob. or name";
+ if kw.get('dataset_name'):
+ self.dataset = create_dataset(kw.get('dataset_name'))
+ else:
+ self.dataset = kw.get('dataset')
self.name = kw.get('name') # Trait ID, ProbeSet ID, Published ID, etc.
self.cellid = kw.get('cellid')
self.identification = kw.get('identification', 'un-named trait')
@@ -39,8 +49,6 @@ class GeneralTrait:
# self.cellid is set to None above
elif len(name2) == 3:
self.dataset, self.name, self.cellid = name2
-
- self.dataset = create_dataset(self.dataset)
# Todo: These two lines are necessary most of the time, but perhaps not all of the time
# So we could add a simple if statement to short-circuit this if necessary
@@ -78,7 +86,7 @@ class GeneralTrait:
#desc = self.handle_pca(desc)
stringy = desc
return stringy
-
+
def display_name(self):
@@ -269,7 +277,7 @@ class GeneralTrait:
escape(self.dataset.name),
escape(self.name))
traitInfo = g.db.execute(query).fetchone()
- print("traitInfo is: ", pf(traitInfo))
+ #print("traitInfo is: ", pf(traitInfo))
#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.dataset.type == 'Geno':
@@ -287,7 +295,7 @@ class GeneralTrait:
escape(self.dataset.name),
escape(self.name))
traitInfo = g.db.execute(query).fetchone()
- print("traitInfo is: ", pf(traitInfo))
+ #print("traitInfo is: ", pf(traitInfo))
else: #Temp type
query = """SELECT %s FROM %s WHERE Name = %s
""" % (string.join(self.dataset.display_fields,','),
@@ -355,8 +363,17 @@ class GeneralTrait:
#traitQTL = self.cursor.fetchone()
if traitQTL:
self.locus, self.lrs, self.pvalue, self.mean = traitQTL
+ if self.locus:
+ result = g.db.execute("""
+ select Geno.Chr, Geno.Mb from Geno, Species
+ where Species.Name = '%s' and
+ Geno.Name = '%s' and
+ Geno.SpeciesId = Species.Id
+ """, (species, self.locus)).fetchone()
+ self.locus_chr = result[0]
+ self.locus_mb = result[1]
else:
- self.locus = self.lrs = self.pvalue = self.mean = ""
+ self.locus = self.locus_chr = self.locus_mb = self.lrs = self.pvalue = self.mean = ""
if self.dataset.type == 'Publish':
traitQTL = g.db.execute("""
SELECT