aboutsummaryrefslogtreecommitdiff
path: root/wqflask/base/data_set.py
diff options
context:
space:
mode:
authorZachary Sloan2013-07-19 17:34:52 -0500
committerZachary Sloan2013-07-19 17:34:52 -0500
commit82f493650909e2351035e26e9dc82b16498beb48 (patch)
treebc66a571b7d805a75549526061b16c197cd6bc67 /wqflask/base/data_set.py
parent6aaefdaae3a9fb068278d9b94d8cdf25d4f8d852 (diff)
downloadgenenetwork2-82f493650909e2351035e26e9dc82b16498beb48.tar.gz
Finished integrating code that reads sample list from geno files
withouot using reaper and caches results so it doesn't need to read the file every single time someone loads a page
Diffstat (limited to 'wqflask/base/data_set.py')
-rwxr-xr-xwqflask/base/data_set.py48
1 files changed, 20 insertions, 28 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index cf219fda..d5aae31d 100755
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -43,6 +43,8 @@ from utility import webqtlUtil
from utility.benchmark import Bench
from wqflask.my_pylmm.pyLMM import chunks
+from maintenance import get_group_samplelists
+
from MySQLdb import escape_string as escape
from pprint import pformat as pf
@@ -258,35 +260,25 @@ class DatasetGroup(object):
if maternal and paternal:
self.parlist = [maternal, paternal]
- def get_sample_list(self):
- genofilename = str(os.path.join(webqtlConfig.GENODIR, self.name + '.geno'))
- genofile = open(genofilename, "r")
- for line in genofile:
- line = line.strip()
- if line.startswith(("#", "@")):
- continue
- headline = line
- break
- headers = headline.split("\t")
- if headers[3] == "Mb":
- self.samplelist = headers[4:]
- else:
- self.samplelist = headers[3:]
-
- #if genotype_1.type == "group" and self.parlist:
- # genotype_2 = genotype_1.add(Mat=self.parlist[0], Pat=self.parlist[1]) #, F1=_f1)
- #else:
- # genotype_2 = genotype_1
- #determine default genotype object
- #if self.incparentsf1 and genotype_1.type != "intercross":
- # genotype = genotype_2
- #else:
- # self.incparentsf1 = 0
- # genotype = genotype_1
+ def get_samplelist(self):
+ key = "samplelist:v4:" + self.name
+ print("key is:", key)
+ with Bench("Loading cache"):
+ result = Redis.get(key)
- #self.samplelist = list(genotype.prgy)
-
+ if result:
+ print("Sample List Cache hit!!!")
+ print("Before unjsonifying {}: {}".format(type(result), result))
+ self.samplelist = json.loads(result)
+ print(" type: ", type(self.samplelist))
+ print(" self.samplelist: ", self.samplelist)
+ else:
+ print("Cache not hit")
+ self.samplelist = get_group_samplelists.get_samplelist(self.name + ".geno")
+ print("after get_samplelist")
+ Redis.set(key, json.dumps(self.samplelist))
+ Redis.expire(key, 60*5)
def read_genotype_file(self):
'''Read genotype from .geno file instead of database'''
@@ -374,7 +366,7 @@ class DataSet(object):
self.retrieve_other_names()
self.group = DatasetGroup(self) # sets self.group and self.group_id and gets genotype
- self.group.read_genotype_file()
+ self.group.get_samplelist()
self.species = species.TheSpecies(self)