diff options
author | zsloan | 2015-07-10 18:15:40 +0000 |
---|---|---|
committer | zsloan | 2015-07-10 18:15:40 +0000 |
commit | 840285e3533790760b763aaa43d3099f9b0a5d69 (patch) | |
tree | 59a43443751938194f578cb1f5571cd0f68f584b | |
parent | 6680ff9356e34a488c70a8cedc041dbf2ce7903f (diff) | |
download | genenetwork2-840285e3533790760b763aaa43d3099f9b0a5d69.tar.gz |
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) )
-rwxr-xr-x | wqflask/wqflask/do_search.py | 44 | ||||
-rwxr-xr-x | wqflask/wqflask/search_results.py | 15 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/dataset_select_menu.js | 10 | ||||
-rwxr-xr-x | wqflask/wqflask/templates/index_page.html | 46 |
4 files changed, 68 insertions, 47 deletions
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,10 +76,10 @@ <!-- GET ANY SEARCH --> <div class="form-group"> - <label for="tfor" class="col-xs-1 control-label" style="padding-left: 0px; padding-right: 0px; width: 65px !important;">Search for:</label> + <label for="or_search" class="col-xs-1 control-label" style="padding-left: 0px; padding-right: 0px; width: 65px !important;">Get Any:</label> <div class="col-xs-10 controls"> <div class="col-xs-8"> - <textarea name="search_terms" rows="2" class="form-control search-query" style="max-width: 550px; width: 450px !important;" id="tfor"></textarea> + <textarea name="search_terms_or" rows="1" class="form-control search-query" style="max-width: 550px; width: 450px !important;" id="or_search"></textarea> </div> </div> </div> @@ -87,19 +87,33 @@ <!-- GET ANY HELP --> <div class="form-group"> <label for="btsearch" class="col-xs-1 control-label" style="width: 65px !important;"></label> + <div class="col-xs-10 controls"> + <div class="col-xs-12 controls"> + Enter terms, genes, ID numbers in the <b>Search</b> field.<br> + Use <b>*</b> or <b>?</b> wildcards (Cyp*a?, synap*).<br> + Use <b>quotes</b> for terms such as <i>"tyrosine kinase"</i>. + </div> + </div> + </div> + + <div class="form-group"> + <label for="and_search" class="col-xs-1 control-label" style="padding-left: 0px; padding-right: 0px; width: 65px !important;">Combined:</label> + <div class="col-xs-10 controls"> + <div class="col-xs-8"> + <textarea name="search_terms_and" rows="1" class="form-control search-query" style="max-width: 550px; width: 450px !important;" id="and_search"></textarea> + </div> + </div> + </div> + + <div class="form-group"> + <label for="btsearch" class="col-xs-1 control-label" style="width: 65px !important;"></label> <div class="col-xs-10 controls"> <div class="col-xs-2 controls" style="width: 100px !important;"> <input id="btsearch" type="submit" class="btn btn-primary form-control" value="Search"> </div> - <div class="col-xs-9 controls"> - Enter terms, genes, ID numbers in the <b>Search</b> field - Use <b>*</b> or <b>?</b> wildcards (Cyp*a?, synap*) - Use <b>quotes</b> for terms such as <i>"tyrosine kinase"</i> - </div> </div> </div> - <!-- SEARCH, MAKE DEFAULT --> <div class="form-group"> @@ -116,21 +130,15 @@ <h2>Advanced commands</h2> </div> - <p>GeneNetwork supports a variety of advanced searches.</p> - - <p>To try them out copy these examples into the search field:</p> + <p>You can also use advanced commands. Copy these simple examples into the Get Any or Combined search fields:</p> <ul> - <!--<li><b>POSITION=(chr1 25 30)</b> finds genes, markers, or transcripts on + <li><b>POSITION=(chr1 25 30)</b> finds genes, markers, or transcripts on chromosome 1 between 25 and 30 Mb.</li> <li><b>MEAN=(15 16) LRS=(23 46)</b> in the <b>Combined</b> field finds highly expressed genes (15 to 16 log2 units) AND with peak <a href="http://www.genenetwork.org/glossary.html#L" target="_blank">LRS</a> - linkage between 23 and 46.</li>--> - - <li><b>MEAN=(15 16)</b> finds highly expressed genes (15 to 16 log2 units).</li> - - <li><b>LRS=(23 46)</b> finds genes with peak <a href="http://www.genenetwork.org/glossary.html#L" target="_blank">LRS</a> linkage between 23 and 46.</li> + linkage between 23 and 46.</li> <li><b>RIF=mitochondrial</b> searches RNA databases for <a href="http://www.ncbi.nlm.nih.gov/projects/GeneRIF/GeneRIFhelp.html" target="_blank"> GeneRIF</a> links.</li> @@ -146,12 +154,12 @@ <li><b>GO:0045202 LRS=(9 99 Chr4 122 155) cisLRS=(9 999 10)</b> finds synapse-associated genes with <a href="http://www.genenetwork.org/glossary.html#E" target="_blank"> cis eQTL</a> on Chr 4 from 122 and 155 Mb with LRS scores - between 9 and 999.</li> + between 9 and 999.</li>--> <li><b>RIF=diabetes LRS=(9 999 Chr2 100 105) transLRS=(9 999 10)</b> finds diabetes-associated transcripts with peak <a href="http://www.genenetwork.org/glossary.html#E" target="_blank"> trans eQTLs</a> on Chr 2 between 100 and 105 Mb with LRS - scores between 9 and 999.</li>--> + scores between 9 and 999.</li> </ul> </section> </div> |