aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsloan2019-09-20 13:19:18 -0500
committerzsloan2019-09-20 13:19:18 -0500
commita08427e95e4d37d6beb2fcc46b05beaf7ae7c617 (patch)
tree6139fab247fcb6b33e37f018fea51e373e909135
parentbdd13bac1a0f30ebd6abf6344190e8cc3d0b7b9e (diff)
downloadgenenetwork2-a08427e95e4d37d6beb2fcc46b05beaf7ae7c617.tar.gz
Include wikidata aliases in search; need to make it also include GN alises though
-rw-r--r--wqflask/wqflask/do_search.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py
index 8476649f..e0f4eb17 100644
--- a/wqflask/wqflask/do_search.py
+++ b/wqflask/wqflask/do_search.py
@@ -1,6 +1,8 @@
from __future__ import print_function, division
import string
+import requests
+import json
from flask import Flask, g
@@ -108,6 +110,12 @@ class MrnaAssaySearch(DoSearch):
def get_where_clause(self):
+ aliases = get_aliases(escape(self.search_term[0]), self.dataset.group.species)
+ if len(aliases) > 0:
+ search_string = " ".join(aliases)
+ else:
+ search_string = escape(self.search_term[0])
+
if self.search_term[0] != "*":
match_clause = """(MATCH (ProbeSet.Name,
ProbeSet.description,
@@ -117,7 +125,7 @@ class MrnaAssaySearch(DoSearch):
UniGeneId,
Probe_Target_Description)
AGAINST ('%s' IN BOOLEAN MODE)) and
- """ % (escape(self.search_term[0]))
+ """ % (search_string)
else:
match_clause = ""
@@ -868,6 +876,26 @@ def is_number(s):
except ValueError:
return False
+def get_aliases(symbol, species):
+ if species == "mouse":
+ symbol_string = symbol.capitalize()
+ elif species == "human":
+ symbol_string = symbol.upper()
+
+ response = requests.get("http://gn2.genenetwork.org/gn3/gene/aliases/" + symbol_string)
+ alias_list = json.loads(response.content)
+
+ filtered_aliases = []
+ seen = set()
+ for item in alias_list:
+ if item in seen:
+ continue
+ else:
+ filtered_aliases.append(item)
+ seen.add(item)
+
+ return filtered_aliases
+
if __name__ == "__main__":
### Usually this will be used as a library, but call it from the command line for testing
### And it runs the code below