diff options
author | zsloan | 2019-09-20 13:13:03 -0500 |
---|---|---|
committer | GitHub | 2019-09-20 13:13:03 -0500 |
commit | a708a0097e29509b209494e21a09f49d79467750 (patch) | |
tree | 3d8fe0530ee36ec65a72ed5196a6e0243c5c1c71 /wqflask/base/trait.py | |
parent | ff67d4bb0e15339697e97c918df1f1cc4385dce6 (diff) | |
parent | 78d3086c3978525065d91c0e02f2c2e0583f8705 (diff) | |
download | genenetwork2-a708a0097e29509b209494e21a09f49d79467750.tar.gz |
Merge branch 'testing' into 360_update_htmlgen
Diffstat (limited to 'wqflask/base/trait.py')
-rw-r--r-- | wqflask/base/trait.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/wqflask/base/trait.py b/wqflask/base/trait.py index 6fecf725..58169b5c 100644 --- a/wqflask/base/trait.py +++ b/wqflask/base/trait.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function import string import resource import codecs +import requests import redis Redis = redis.StrictRedis() @@ -120,11 +121,34 @@ class GeneralTrait(object): @property def alias_fmt(self): '''Return a text formatted alias''' + + alias = 'Not available' if self.alias: alias = string.replace(self.alias, ";", " ") alias = string.join(string.split(alias), ", ") - else: - alias = 'Not available' + + return alias + + @property + def wikidata_alias_fmt(self): + '''Return a text formatted alias''' + + alias = 'Not available' + if self.symbol: + human_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.upper()) + mouse_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.capitalize()) + other_response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + self.symbol.lower()) + alias_list = json.loads(human_response.content) + json.loads(mouse_response.content) + json.loads(other_response.content) + + filtered_aliases = [] + seen = set() + for item in alias_list: + if item in seen: + continue + else: + filtered_aliases.append(item) + seen.add(item) + alias = "; ".join(filtered_aliases) return alias @@ -396,8 +420,10 @@ def retrieve_trait_info(trait, dataset, get_qtl_info=False): #XZ: assign SQL query result to trait attributes. for i, field in enumerate(dataset.display_fields): holder = trait_info[i] - if isinstance(trait_info[i], basestring): - holder = unicode(trait_info[i], "utf-8", "ignore") + # if isinstance(trait_info[i], basestring): + # logger.debug("HOLDER:", holder) + # logger.debug("HOLDER2:", holder.decode(encoding='latin1')) + # holder = unicode(trait_info[i], "utf-8", "ignore") setattr(trait, field, holder) if dataset.type == 'Publish': |