From 2b47c104b3baeb2871f7669cef41ab5a112779ea Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 13 Apr 2016 20:41:49 +0000 Subject: Global search should be able to return description and location columns now --- wqflask/base/trait.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index ce3a7608..51a4d986 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -2,7 +2,7 @@ from __future__ import absolute_import, division, print_function import string import resource - +import codecs from htmlgen import HTMLgen2 as HT @@ -309,6 +309,42 @@ class GeneralTrait(object): holder = unicode(trait_info[i], "utf8", "ignore") setattr(self, field, holder) + description_string = unicode(str(self.description).strip(codecs.BOM_UTF8), 'utf-8') + target_string = unicode(str(self.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8') + + if len(description_string) > 1 and description_string != 'None': + description_display = description_string + else: + description_display = self.symbol + + if (len(description_display) > 1 and description_display != 'N/A' and + len(target_string) > 1 and target_string != 'None'): + description_display = description_display + '; ' + target_string.strip() + + # Save it for the jinja2 template + self.description_display = description_display + + #XZ: trait_location_value is used for sorting + trait_location_repr = 'N/A' + trait_location_value = 1000000 + + if self.chr and self.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(self.chr, self.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" + self.location_repr = 'Chr%s: %.6f' % (self.chr, float(self.mb)) + self.location_value = trait_location_value + if self.dataset.type == 'Publish': self.confidential = 0 if self.pre_publication_description and not self.pubmed_id: @@ -662,7 +698,17 @@ class GeneralTrait(object): ZValue = ZValue*sqrt(self.overlap-3) self.p_value = 2.0*(1.0 - reaper.normp(abs(ZValue))) - +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(): -- cgit v1.2.3 From 15b3a1543f59a097039ae964ba26775236022401 Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 13 Apr 2016 21:16:22 +0000 Subject: Moved the code getting the description/location because it was throwing an error for phenotype traits --- wqflask/base/trait.py | 75 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) (limited to 'wqflask/base') diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 51a4d986..6c5ca8b2 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -308,42 +308,6 @@ class GeneralTrait(object): if isinstance(trait_info[i], basestring): holder = unicode(trait_info[i], "utf8", "ignore") setattr(self, field, holder) - - description_string = unicode(str(self.description).strip(codecs.BOM_UTF8), 'utf-8') - target_string = unicode(str(self.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8') - - if len(description_string) > 1 and description_string != 'None': - description_display = description_string - else: - description_display = self.symbol - - if (len(description_display) > 1 and description_display != 'N/A' and - len(target_string) > 1 and target_string != 'None'): - description_display = description_display + '; ' + target_string.strip() - - # Save it for the jinja2 template - self.description_display = description_display - - #XZ: trait_location_value is used for sorting - trait_location_repr = 'N/A' - trait_location_value = 1000000 - - if self.chr and self.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(self.chr, self.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" - self.location_repr = 'Chr%s: %.6f' % (self.chr, float(self.mb)) - self.location_value = trait_location_value if self.dataset.type == 'Publish': self.confidential = 0 @@ -378,8 +342,8 @@ class GeneralTrait(object): if self.pubmed_id: self.pubmed_link = webqtlConfig.PUBMEDLINK_URL % self.pubmed_id + self.homologeneid = None - if self.dataset.type == 'ProbeSet' and self.dataset.group and self.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. @@ -407,6 +371,43 @@ class GeneralTrait(object): if result: self.homologeneid = result[0] + + description_string = unicode(str(self.description).strip(codecs.BOM_UTF8), 'utf-8') + target_string = unicode(str(self.probe_target_description).strip(codecs.BOM_UTF8), 'utf-8') + + if len(description_string) > 1 and description_string != 'None': + description_display = description_string + else: + description_display = self.symbol + + if (len(description_display) > 1 and description_display != 'N/A' and + len(target_string) > 1 and target_string != 'None'): + description_display = description_display + '; ' + target_string.strip() + + # Save it for the jinja2 template + self.description_display = description_display + + #XZ: trait_location_value is used for sorting + trait_location_repr = 'N/A' + trait_location_value = 1000000 + + if self.chr and self.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(self.chr, self.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" + self.location_repr = 'Chr%s: %.6f' % (self.chr, float(self.mb)) + self.location_value = trait_location_value + if get_qtl_info: #LRS and its location -- cgit v1.2.3