From 2ec627563efa9fdf4fc74cb4764bfebb5ab90933 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Thu, 6 Dec 2012 15:39:28 -0600 Subject: Got show_trait running again for MrnaAssay traits --- wqflask/base/data_set.py | 37 +++++++------- wqflask/wqflask/show_trait/SampleList.py | 48 +++++++++--------- wqflask/wqflask/show_trait/show_trait.py | 81 ++++++++++++++----------------- wqflask/wqflask/templates/show_trait.html | 2 +- 4 files changed, 80 insertions(+), 88 deletions(-) diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index 14e4055e..9f0f3fac 100755 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -77,6 +77,9 @@ class DatasetGroup(object): self.name = "BXD" self.incparentsf1 = False + self.f1list = None + self.parlist = None + self.allsamples = None #def read_genotype(self): @@ -95,39 +98,39 @@ class DatasetGroup(object): #genotype_1 is Dataset Object without parents and f1 #genotype_2 is Dataset Object with parents and f1 (not for intercross) - self.genotype_1 = reaper.Dataset() + genotype_1 = reaper.Dataset() # reaper barfs on unicode filenames, so here we ensure it's a string full_filename = str(os.path.join(webqtlConfig.GENODIR, self.name + '.geno')) - self.genotype_1.read(full_filename) + genotype_1.read(full_filename) print("Got to after read") try: # NL, 07/27/2010. ParInfo has been moved from webqtlForm.py to webqtlUtil.py; - _f1, _f12, _mat, _pat = webqtlUtil.ParInfo[self.name] + f1, f12, maternal, paternal = webqtlUtil.ParInfo[self.name] except KeyError: - _f1 = _f12 = _mat = _pat = None + f1 = f12 = maternal = paternal = None - self.genotype_2 = self.genotype_1 - if self.genotype_1.type == "group" and _mat and _pat: - self.genotype_2 = self.genotype_1.add(Mat=_mat, Pat=_pat) #, F1=_f1) + + if genotype_1.type == "group" and maternal and paternal: + genotype_2 = genotype_1.add(Mat=maternal, Pat=paternal) #, F1=_f1) + else: + genotype_2 = genotype_1 #determine default genotype object - if self.incparentsf1 and self.genotype_1.type != "intercross": - self.genotype = self.genotype_2 + if self.incparentsf1 and genotype_1.type != "intercross": + self.genotype = genotype_2 else: self.incparentsf1 = 0 - self.genotype = self.genotype_1 + self.genotype = genotype_1 self.samplelist = list(self.genotype.prgy) - self.f1list = [] - self.parlist = [] - if _f1 and _f12: - self.f1list = [_f1, _f12] - if _mat and _pat: - self.parlist = [_mat, _pat] + if f1 and f12: + self.f1list = [f1, f12] + if maternal and paternal: + self.parlist = [maternal, paternal] class DataSet(object): @@ -169,8 +172,6 @@ class DataSet(object): # self.get_group() # # return self._group - - diff --git a/wqflask/wqflask/show_trait/SampleList.py b/wqflask/wqflask/show_trait/SampleList.py index 53bb24fb..0c752617 100644 --- a/wqflask/wqflask/show_trait/SampleList.py +++ b/wqflask/wqflask/show_trait/SampleList.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, print_function, division +from flask import Flask, g + from base import webqtlCaseData from utility import webqtlUtil, Plot, Bunch from base.webqtlTrait import GeneralTrait @@ -8,22 +10,19 @@ from pprint import pformat as pf class SampleList(object): def __init__(self, - cursor, dataset, - variance_data_page, sample_names, this_trait, sample_group_type, header): - - self.cursor = cursor + self.dataset = dataset self.this_trait = this_trait self.sample_group_type = sample_group_type # primary or other self.header = header self.sample_list = [] # The actual list - + self.get_attributes() print("camera: attributes are:", pf(self.attributes)) @@ -54,7 +53,7 @@ class SampleList(object): sample.this_id = "Other_" + str(counter) #### For extra attribute columns; currently only used by several datasets - Zach - if self.this_trait and self.this_trait.db and self.this_trait.db.type == 'ProbeSet': + if self.this_trait and self.dataset and self.dataset.type == 'ProbeSet': sample.extra_attributes = self.get_extra_attribute_values(sample_name) print("sample.extra_attributes is", pf(sample.extra_attributes)) self.sample_list.append(sample) @@ -88,27 +87,27 @@ class SampleList(object): def get_attributes(self): """Finds which extra attributes apply to this dataset""" - #ZS: Id and name values for this trait's extra attributes - self.cursor.execute('''SELECT CaseAttribute.Id, CaseAttribute.Name + #ZS: Id and name values for this trait's extra attributes + case_attributes = g.db.execute('''SELECT CaseAttribute.Id, CaseAttribute.Name FROM CaseAttribute, CaseAttributeXRef WHERE CaseAttributeXRef.ProbeSetFreezeId = %s AND CaseAttribute.Id = CaseAttributeXRef.CaseAttributeId group by CaseAttributeXRef.CaseAttributeId''', - (str(self.this_trait.db.id),)) + (str(self.dataset.id),)) self.attributes = {} - for key, value in self.cursor.fetchall(): + for key, value in case_attributes.fetchall(): print("radish: %s - %s" % (key, value)) self.attributes[key] = Bunch() self.attributes[key].name = value - self.cursor.execute('''SELECT DISTINCT CaseAttributeXRef.Value - FROM CaseAttribute, CaseAttributeXRef - WHERE CaseAttribute.Name = %s AND - CaseAttributeXRef.CaseAttributeId = CaseAttribute.Id''', (value,)) + attribute_values = g.db.execute('''SELECT DISTINCT CaseAttributeXRef.Value + FROM CaseAttribute, CaseAttributeXRef + WHERE CaseAttribute.Name = %s AND + CaseAttributeXRef.CaseAttributeId = CaseAttribute.Id''', (value,)) - self.attributes[key].distinct_values = [item[0] for item in self.cursor.fetchall()] + self.attributes[key].distinct_values = [item[0] for item in attribute_values.fetchall()] self.attributes[key].distinct_values.sort(key=natural_sort_key) @@ -119,27 +118,28 @@ class SampleList(object): if self.attributes: #ZS: Get StrainId value for the next query - self.cursor.execute("""SELECT Strain.Id + result = g.db.execute("""SELECT Strain.Id FROM Strain, StrainXRef, InbredSet WHERE Strain.Name = %s and StrainXRef.StrainId = Strain.Id and InbredSet.Id = StrainXRef.InbredSetId and - InbredSet.Name = %s""", (sample_name, self.dataset.group.name)) + InbredSet.Name = %s""", (sample_name, + self.dataset.group.name)) - sample_id = self.cursor.fetchone()[0] + sample_id = result.fetchone().Id for attribute in self.attributes: #ZS: Add extra case attribute values (if any) - self.cursor.execute("""SELECT Value + result = g.db.execute("""SELECT Value FROM CaseAttributeXRef - WHERE ProbeSetFreezeId = '%s' AND - StrainId = '%s' AND - CaseAttributeId = '%s' - group by CaseAttributeXRef.CaseAttributeId""" % ( + WHERE ProbeSetFreezeId = %s AND + StrainId = %s AND + CaseAttributeId = %s + group by CaseAttributeXRef.CaseAttributeId""", ( self.this_trait.db.id, sample_id, str(attribute))) - attribute_value = self.cursor.fetchone()[0] #Trait-specific attributes, if any + attribute_value = result.fetchone().Value #Trait-specific attributes, if any #ZS: If it's an int, turn it into one for sorting #(for example, 101 would be lower than 80 if they're strings instead of ints) diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 73b438d0..cd61d70c 100755 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -55,7 +55,7 @@ class ShowTrait(templatePage): #fd.readGenotype() if not self.dataset.group.genotype: - self.read_data(incf1=1) + self.read_data(include_f1=True) #incf1=1) ## determine data editing page format #variance_data_page = 0 @@ -158,15 +158,15 @@ class ShowTrait(templatePage): # print("Calling dispBasicStatistics") # self.dispBasicStatistics(fd, this_trait) - self.build_correlation_tools(args, this_trait) + self.build_correlation_tools(this_trait) - self.make_sample_lists(args, variance_data_page, this_trait) + self.make_sample_lists(this_trait) - if args['allsamplelist']: - hddn['allsamplelist'] = string.join(args['allsamplelist'], ' ') + if self.dataset.group.allsamples: + hddn['allsamples'] = string.join(self.dataset.group.allsamples, ' ') - if args['varianceDispName'] != 'Variance': - hddn['isSE'] = "yes" + #if args['varianceDispName'] != 'Variance': + # hddn['isSE'] = "yes" # We'll need access to this_trait and hddn in the Jinja2 Template, so we put it inside self self.this_trait = this_trait @@ -215,22 +215,20 @@ class ShowTrait(templatePage): return this_trait - def read_data(self): + def read_data(self, include_f1=False): '''read user input data or from trait data and analysis form''' - if incf1 == None: - incf1 = [] + #if incf1 == None: + # incf1 = [] if not self.genotype: self.dataset.read_genotype_file() if not samplelist: - if incf1: + if include_f1: samplelist = self.f1list + self.samplelist else: samplelist = self.samplelist - #print("before traitfiledata self.traitfile is:", pf(self.traitfile)) - traitfiledata = getattr(self, "traitfile", None) traitpastedata = getattr(self, "traitpaste", None) variancefiledata = getattr(self, "variancefile", None) @@ -1174,39 +1172,34 @@ class ShowTrait(templatePage): dataset_menu = [] print("[tape4] webqtlConfig.PUBLICTHRESH:", webqtlConfig.PUBLICTHRESH) print("[tape4] type webqtlConfig.PUBLICTHRESH:", type(webqtlConfig.PUBLICTHRESH)) - query = - self.cursor.execute('''SELECT PublishFreeze.FullName,PublishFreeze.Name FROM + 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''', + and InbredSet.Name = %s and PublishFreeze.public > %s""", (this_group, webqtlConfig.PUBLICTHRESH)) - for item in self.cursor.fetchall(): + for item in results.fetchall(): dataset_menu.append(dict(tissue=None, datasets=[item])) - self.cursor.execute('''SELECT GenoFreeze.FullName,GenoFreeze.Name FROM GenoFreeze, + 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''', + %s and GenoFreeze.public > %s""", (this_group, webqtlConfig.PUBLICTHRESH)) - for item in self.cursor.fetchall(): + 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. - self.cursor.execute('SELECT Id, Name FROM Tissue order by Name') - for item in self.cursor.fetchall(): + tissues = g.db.execute("SELECT Id, Name FROM Tissue order by Name") + for item in tissues.fetchall(): tissue_id, tissue_name = item #databaseMenuSub = HT.Optgroup(label = '%s ------' % tissue_name) #dataset_sub_menu = [] - print("phun9") - self.cursor.execute('''SELECT ProbeSetFreeze.FullName,ProbeSetFreeze.Name FROM ProbeSetFreeze, ProbeFreeze, + data_sets = g.db.execute('''SELECT ProbeSetFreeze.FullName,ProbeSetFreeze.Name FROM ProbeSetFreeze, ProbeFreeze, InbredSet WHERE ProbeSetFreeze.ProbeFreezeId = ProbeFreeze.Id and ProbeFreeze.TissueId = %s and ProbeSetFreeze.public > %s and ProbeFreeze.InbredSetId = InbredSet.Id and InbredSet.Name like %s order by ProbeSetFreeze.CreateTime desc, ProbeSetFreeze.AvgId ''', (tissue_id, webqtlConfig.PUBLICTHRESH, "%" + this_group + "%")) - print("phun8") - dataset_sub_menu = [item for item in self.cursor.fetchall() if item] - #for item2 in self.cursor.fetchall(): - # dataset_sub_menu.append(item2) + dataset_sub_menu = [item for item in data_sets.fetchall() if item] if dataset_sub_menu: dataset_menu.append(dict(tissue=tissue_name, datasets=dataset_sub_menu)) @@ -1612,11 +1605,13 @@ class ShowTrait(templatePage): title4Body.append(submitTable) - def make_sample_lists(self, fd, variance_data_page, this_trait): - if args['parlist']: - all_samples_ordered = args['parlist'] + args['f1list'] + args['samplelist'] + def make_sample_lists(self, this_trait): + if self.dataset.group.parlist: + all_samples_ordered = (self.dataset.group.parlist + + self.dataset.group.f1list + + self.dataset.group.samplelist) else: - all_samples_ordered = args['f1list'] + args['samplelist'] + all_samples_ordered = self.dataset.group.f1list + self.dataset.group.samplelist this_trait_samples = set(this_trait.data.keys()) @@ -1624,9 +1619,7 @@ class ShowTrait(templatePage): print("-*- primary_samplelist is:", pf(primary_sample_names)) - primary_samples = SampleList(self.cursor, - args=args, - variance_data_page=variance_data_page, + primary_samples = SampleList(dataset = self.dataset, sample_names=primary_sample_names, this_trait=this_trait, sample_group_type='primary', @@ -1640,18 +1633,16 @@ class ShowTrait(templatePage): other_sample_names.append(sample) if other_sample_names: - par_f1_samples = fd.parlist + fd.f1list + parent_f1_samples = self.dataset.group.parlist + self.dataset.group.f1list other_sample_names.sort() #Sort other samples - other_sample_names = par_f1_samples + other_sample_names + other_sample_names = parent_f1_samples + other_sample_names - other_samples = SampleList(self.cursor, - fd=fd, - variance_data_page=variance_data_page, - sample_names=other_sample_names, - this_trait=this_trait, - sample_group_type='other', - header="Non-%s" % (fd.group)) + other_samples = SampleList(dataset=self.dataset, + sample_names=other_sample_names, + this_trait=this_trait, + sample_group_type='other', + header="Non-%s" % (self.dataset.group.name)) self.sample_groups = (primary_samples, other_samples) else: @@ -1661,4 +1652,4 @@ class ShowTrait(templatePage): #if (other_sample_names or (fd.f1list and this_trait.data.has_key(fd.f1list[0])) # or (fd.f1list and this_trait.data.has_key(fd.f1list[1]))): # print("hjs") - fd.allsamplelist = all_samples_ordered + self.dataset.group.allsamples = all_samples_ordered diff --git a/wqflask/wqflask/templates/show_trait.html b/wqflask/wqflask/templates/show_trait.html index b5c1d6ac..163be69c 100644 --- a/wqflask/wqflask/templates/show_trait.html +++ b/wqflask/wqflask/templates/show_trait.html @@ -19,7 +19,7 @@
-- cgit v1.2.3