diff options
author | Artem Tarasov | 2015-05-13 14:16:14 +0300 |
---|---|---|
committer | Artem Tarasov | 2015-05-13 14:16:14 +0300 |
commit | 73be62c9e5ef5c4b3a87d3fcdc46f338679bf5e1 (patch) | |
tree | da7faca70491e4c71ea23ca44154e5488e078601 | |
parent | ee84f921331e7e68df0d57a1bc285b5f91780135 (diff) | |
download | genenetwork2-73be62c9e5ef5c4b3a87d3fcdc46f338679bf5e1.tar.gz |
combine three similar queries into one
-rwxr-xr-x | wqflask/base/data_set.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index f5bd5cb8..706b193d 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -319,38 +319,39 @@ class DatasetGroup(object): dataset_menu = [] print("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH) print("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH)) - results = g.db.execute("""SELECT PublishFreeze.FullName,PublishFreeze.Name FROM - PublishFreeze,InbredSet WHERE PublishFreeze.InbredSetId = InbredSet.Id - and InbredSet.Name = %s and PublishFreeze.public > %s""", - (self.name, webqtlConfig.PUBLICTHRESH)) - for item in results.fetchall(): - dataset_menu.append(dict(tissue=None, - datasets=[item])) - - results = g.db.execute("""SELECT GenoFreeze.FullName,GenoFreeze.Name FROM GenoFreeze, - InbredSet WHERE GenoFreeze.InbredSetId = InbredSet.Id and InbredSet.Name = - %s and GenoFreeze.public > %s""", - (self.name, webqtlConfig.PUBLICTHRESH)) - for item in results.fetchall(): - dataset_menu.append(dict(tissue=None, - datasets=[item])) - - #03/09/2009: Xiaodong changed the SQL query to order by Name as requested by Rob. results = g.db.execute(''' - SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name - FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue - WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and - ProbeFreeze.TissueId = Tissue.Id and - ProbeSetFreeze.public > %s and - ProbeFreeze.InbredSetId = InbredSet.Id and - InbredSet.Name like %s - ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId - ''', (webqtlConfig.PUBLICTHRESH, "%" + self.name + "%")) + (SELECT '#PublishFreeze',PublishFreeze.FullName,PublishFreeze.Name + FROM PublishFreeze,InbredSet + WHERE PublishFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name = %s + and PublishFreeze.public > %s) + UNION + (SELECT '#GenoFreeze',GenoFreeze.FullName,GenoFreeze.Name + FROM GenoFreeze, InbredSet + WHERE GenoFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name = %s + and GenoFreeze.public > %s) + UNION + (SELECT Tissue.Name, ProbeSetFreeze.FullName,ProbeSetFreeze.Name + FROM ProbeSetFreeze, ProbeFreeze, InbredSet, Tissue + WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id + and ProbeFreeze.TissueId = Tissue.Id + and ProbeFreeze.InbredSetId = InbredSet.Id + and InbredSet.Name like %s + and ProbeSetFreeze.public > %s + ORDER BY Tissue.Name, ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId) + ''', (self.name, webqtlConfig.PUBLICTHRESH, + self.name, webqtlConfig.PUBLICTHRESH, + "%" + self.name + "%", webqtlConfig.PUBLICTHRESH)) for tissue_name, dataset in itertools.groupby(results.fetchall(), itemgetter(0)): - dataset_sub_menu = [item[1:] for item in dataset] - dataset_menu.append(dict(tissue=tissue_name, - datasets=dataset_sub_menu)) + if tissue_name in ['#PublishFreeze', '#GenoFreeze']: + for item in dataset: + dataset_menu.append(dict(tissue=None, datasets=[item[1:]])) + else: + dataset_sub_menu = [item[1:] for item in dataset] + dataset_menu.append(dict(tissue=tissue_name, + datasets=dataset_sub_menu)) Redis.set(key, pickle.dumps(dataset_menu, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60*5) |