From 840285e3533790760b763aaa43d3099f9b0a5d69 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 10 Jul 2015 18:15:40 +0000 Subject: Added an OR ("Get Any") search to the index page Fixed several issues with existing searches; for example, the user can type "Chr" before the chromosome parameter (for example LRS=(9 999 Chr2 100 105) ) --- wqflask/wqflask/do_search.py | 44 +++++++++++---------- wqflask/wqflask/search_results.py | 15 +++++-- .../static/new/javascript/dataset_select_menu.js | 10 +++-- wqflask/wqflask/templates/index_page.html | 46 +++++++++++++--------- 4 files changed, 68 insertions(+), 47 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index fc8db204..02e73bb0 100755 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -534,7 +534,14 @@ class LrsSearch(DoSearch): DoSearch.search_types['LRS'] = 'LrsSearch' def get_from_clause(self): - if self.search_operator == "=": + #If the user typed, for example "Chr4", the "Chr" substring needs to be removed so that all search elements can be converted to floats + if len(self.search_term) > 2 and "Chr" in self.search_term[2]: + chr_num = self.search_term[2].replace("Chr", "") + self.search_term[2] = chr_num + + self.search_term = [float(value) for value in self.search_term] + + if len(self.search_term) > 2: from_clause = ", Geno" else: from_clause = "" @@ -542,41 +549,36 @@ class LrsSearch(DoSearch): return from_clause def get_where_clause(self): - self.search_term = [float(value) for value in self.search_term] - if self.search_operator == "=": assert isinstance(self.search_term, (list, tuple)) - self.lrs_min, self.lrs_max = self.search_term[:2] + lrs_min, lrs_max = self.search_term[:2] - self.sub_clause = """ %sXRef.LRS > %s and - %sXRef.LRS < %s and """ % self.mescape(self.dataset.type, - min(self.lrs_min, self.lrs_max), + where_clause = """ %sXRef.LRS > %s and + %sXRef.LRS < %s """ % self.mescape(self.dataset.type, + min(lrs_min, lrs_max), self.dataset.type, - max(self.lrs_min, self.lrs_max)) + max(lrs_min, lrs_max)) if len(self.search_term) > 2: - self.chr_num = self.search_term[2] - self.sub_clause += """ Geno.Chr = %s and """ % (self.chr_num) + chr_num = self.search_term[2] + where_clause += """ and Geno.Chr = %s """ % (chr_num) if len(self.search_term) == 5: - self.mb_low, self.mb_high = self.search_term[3:] - self.sub_clause += """ Geno.Mb > %s and - Geno.Mb < %s and - """ % self.mescape(min(self.mb_low, self.mb_high), - max(self.mb_low, self.mb_high)) - print("self.sub_clause is:", pf(self.sub_clause)) - - #%s.Chr = Geno.Chr - where_clause = self.sub_clause + """ %sXRef.Locus = Geno.name and + mb_low, mb_high = self.search_term[3:] + where_clause += """ and Geno.Mb > %s and + Geno.Mb < %s + """ % self.mescape(min(mb_low, mb_high), + max(mb_low, mb_high)) + + where_clause += """ and %sXRef.Locus = Geno.name and Geno.SpeciesId = %s """ % self.mescape(self.dataset.type, self.species_id) else: # Deal with >, <, >=, and <= print("self.search_term is:", self.search_term) - self.sub_clause = """ %sXRef.LRS %s %s """ % self.mescape(self.dataset.type, + where_clause = """ %sXRef.LRS %s %s """ % self.mescape(self.dataset.type, self.search_operator, self.search_term[0]) - where_clause = self.sub_clause return where_clause diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index b48c9583..01d65278 100755 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -77,10 +77,15 @@ class SearchResultPage(object): self.trait_type = kw['trait_type'] self.quick_search() else: + print("kw is:", kw) + if kw['search_terms_or']: + self.and_or = "or" + self.search_terms = kw['search_terms_or'] + else: + self.and_or = "and" + self.search_terms = kw['search_terms_and'] self.search_term_exists = True self.results = [] - print("kw is:", kw) - self.search_terms = kw['search_terms'] if kw['type'] == "Phenotypes": dataset_type = "Publish" elif kw['type'] == "Genotypes": @@ -237,10 +242,14 @@ class SearchResultPage(object): where_clause = the_search.get_where_clause() combined_where_clause += "(" + where_clause + ")" if (i+1) < len(self.search_terms): - combined_where_clause += "AND" + if self.and_or == "and": + combined_where_clause += "AND" + else: + combined_where_clause += "OR" else: self.search_term_exists = False if self.search_term_exists: + combined_where_clause = "(" + combined_where_clause + ")" final_query = the_search.compile_final_query(combined_from_clause, combined_where_clause) results = the_search.execute(final_query) self.results.extend(results) diff --git a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js index 5bd54359..fb9fdcf3 100644 --- a/wqflask/wqflask/static/new/javascript/dataset_select_menu.js +++ b/wqflask/wqflask/static/new/javascript/dataset_select_menu.js @@ -134,10 +134,12 @@ $(function() { return _results; }; check_search_term = function() { - var search_term; - search_term = $('#tfor').val(); - console.log("search_term:", search_term); - if (search_term === "") { + var or_search_term, and_search_term; + or_search_term = $('#or_search').val(); + and_search_term = $('#and_search').val(); + console.log("or_search_term:", or_search_term); + console.log("and_search_term:", and_search_term); + if (or_search_term === "" && and_search_term === "") { alert("Please enter one or more search terms or search equations."); return false; } diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html index 150a71f1..3d5ddde4 100755 --- a/wqflask/wqflask/templates/index_page.html +++ b/wqflask/wqflask/templates/index_page.html @@ -76,30 +76,44 @@
- +
- +
+
+ +
+
+ Enter terms, genes, ID numbers in the Search field.
+ Use * or ? wildcards (Cyp*a?, synap*).
+ Use quotes for terms such as "tyrosine kinase". +
+
+
+ +
+ +
+
+ +
+
+
+
-
- Enter terms, genes, ID numbers in the Search field - Use * or ? wildcards (Cyp*a?, synap*) - Use quotes for terms such as "tyrosine kinase" -
-
@@ -116,21 +130,15 @@

Advanced commands

-

GeneNetwork supports a variety of advanced searches.

- -

To try them out copy these examples into the search field:

+

You can also use advanced commands. Copy these simple examples into the Get Any or Combined search fields:

-- cgit v1.2.3