diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/search_results.py | 21 | ||||
-rw-r--r-- | wqflask/wqflask/templates/quick_search.html | 323 |
2 files changed, 235 insertions, 109 deletions
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index 89f146b3..5f3c036f 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -74,6 +74,7 @@ class SearchResultPage(object): self.search_terms = kw['q'] print("self.search_terms is: ", self.search_terms) self.quick_search() + self.get_group_species_tree() else: self.results = [] #self.quick_search = False @@ -134,16 +135,32 @@ class SearchResultPage(object): type_dict = {'PublishXRef': 'phenotype', 'ProbeSetXRef': 'mrna_assay', 'GenoXRef': 'genotype'} - + + self.species_groups = {} for dbresult in dbresults: this_result = {} this_result['table_name'] = dbresult.table_name this_result['key'] = dbresult.the_key this_result['result_fields'] = json.loads(dbresult.result_fields) - + this_species = this_result['result_fields']['species'] + this_group = this_result['result_fields']['group_name'] + if type_dict[dbresult.table_name] not in self.species_groups: + self.species_groups[type_dict[dbresult.table_name]] = {} + if this_species not in self.species_groups[type_dict[dbresult.table_name]]: + self.species_groups[type_dict[dbresult.table_name]][this_species] = collections.defaultdict(list) + if this_group not in self.species_groups[type_dict[dbresult.table_name]][this_species]: + self.species_groups[type_dict[dbresult.table_name]][this_species].append(this_group) self.results[type_dict[dbresult.table_name]].append(this_result) #print("results: ", pf(self.results['phenotype'])) + + #def get_group_species_tree(self): + # self.species_groups = collections.default_dict(list) + # for key in self.results: + # for item in self.results[key]: + # self.species_groups[item['result_fields']['species']].append( + # item['result_fields']['group_name']) + #def quick_search(self): # self.search_terms = parser.parse(self.search_terms) diff --git a/wqflask/wqflask/templates/quick_search.html b/wqflask/wqflask/templates/quick_search.html index 769c40e6..9d5b0c74 100644 --- a/wqflask/wqflask/templates/quick_search.html +++ b/wqflask/wqflask/templates/quick_search.html @@ -21,9 +21,7 @@ <ul> {% if search_terms %} <li> - {% for word in search_terms %} - <strong>{{word}}</strong> {% if not loop.last %} or {% endif %} - {% endfor %} + <strong>{{search_terms}}</strong> </li> {% endif %} </ul> @@ -33,20 +31,166 @@ <div class="tabbable"> <!-- Only required for left/right tabs --> <ul class="nav nav-tabs"> + {% if results.phenotype %} <li class="active"> <a href="#tab1" data-toggle="tab">Phenotype</a></li> + {% endif %} + {% if results.mrna_assay %} <li> <a href="#tab2" data-toggle="tab">mRNA Assay</a></li> + {% endif %} + {% if results.genotype %} <li> <a href="#tab3" data-toggle="tab">Genotype</a></li> + {% endif %} </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> - <table class="table table-hover"> + <div class="tabbable tabs-left"> + <ul class="nav nav-tabs"> + {% for species in species_groups.phenotype %} + <li> <a href="#tab1_{{ loop.index }}" data-toggle="tab">{{ species }}</a></li> + {% endfor %} + </ul> + <div class="tab-content"> + {% for species in species_groups.phenotype %} + <div class="tab-pane active" id="tab{{ loop.index }}"> + <table id="pheno_results" class="table table-hover table-striped table-bordered"> + <thead> + <tr> + <th>Id</th> + <th>Species</th> + <th>Group</th> + <th>Description</th> + <th>LRS</th> + <th>Year</th> + <th>Authors</th> + </tr> + </thead> + <tbody> + {% for result in results.phenotype %} + {% if result.result_fields['species'] == species %} + <tr> + <td>{{ result.result_fields['phenotype_id'] }}</td> + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['description'] }}</td> + <td>{{ result.result_fields['lrs'] }}</td> + <td> + <a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids={{ result.result_fields['pubmed_id'] }}&dopt=Abstract"> + {{ result.result_fields['year'] }} + </a> + </td> + <td>{{ result.result_fields['authors'] }}</td> + </tr> + {% endif %} + {% endfor %} + </tbody> + </table> + </div> + {% endfor %} + </div> + </div> + </div> + <div class="tab-pane active" id="tab2"> + <div class="tabbable tabs-left"> + <ul class="nav nav-tabs"> + {% for species in species_groups.mrna_assay %} + <li> <a href="#tab2_{{ loop.index }}" data-toggle="tab">{{ species }}</a></li> + {% endfor %} + </ul> + <div class="tab-content"> + {% for species in species_groups.mrna_assay %} + <div class="tab-pane active" id="tab{{ loop.index }}"> + <table id="mrna_assay_results" class="table table-hover table-striped table-bordered"> + <thead> + <tr> + <th>Record ID</th> + <th>Species</th> + <th>Group</th> + <th>Data Set</th> + <th>Symbol</th> + <th>Description</th> + <th>Location</th> + <th>Mean Expr</th> + <th>Max LRS</th> + </tr> + </thead> + <tbody> + {% for result in results.mrna_assay %} + {% if result.result_fields['species'] == species %} + <tr> + <td> + <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result.result_fields['name'] }}&dataset={{ result.result_fields['dataset'] }}" + {{ result.result_fields['name'] }} + </a> + </td> + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['dataset_name'] }}</td> + <td>{{ result.result_fields['symbol'] }}</td> + <td>{{ result.result_fields['description'] }}</td> + <td>{{ result.result_fields['chr'] }} : {{ result['mb'] }}</td> + <td>{{ result.result_fields['mean'] }}</td> + <td>{{ result.result_fields['lrs'] }}</td> + </tr> + {% endif %} + {% endfor %} + </tbody> + </table> + </div> + {% endfor %} + </div> + </div> + </div> + <div class="tab-pane active" id="tab3"> + <div class="tabbable tabs-left"> + <ul class="nav nav-tabs"> + {% for species in species_groups.genotype %} + <li> <a href="#tab3_{{ loop.index }}" data-toggle="tab">{{ species }}</a></li> + {% endfor %} + </ul> + <div class="tab-content"> + {% for species in species_groups.genotype %} + <div class="tab-pane active" id="tab{{ loop.index }}"> + <table id="geno_results" class="table table-hover table-striped table-bordered"> + <thead> + <tr> + <th>Marker</th> + <th>Species</th> + <th>Group</th> + <th>Data Set</th> + <th>Location</th> + </tr> + </thead> + <tbody> + {% for result in results.genotype %} + {% if result.result_fields['species'] == species %} + <tr> + <td> + <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result.result_fields['marker_name'] }}&dataset={{ result.result_fields['dataset'] }}"> + {{ result.result_fields['marker_name'] }} + </a> + </td> + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['dataset_name'] }}</td> + <td>{{ result.result_fields['chr'] }} : {{ result.result_fields['mb'] }}</td> + </tr> + {% endif %} + {% endfor %} + </tbody> + </table> + </div> + {% endfor %} + </div> + </div> + </div> + </div> + </div> + </div> + + {# + <table id="pheno_results" class="table table-hover table-striped table-bordered"> <thead> <tr> - {# - {% for key, _value in results.phenotype[0].result_fields.items() %} - <th>{{key}}</th> - {% endfor %} - #} <th>Id</th> <th>Species</th> <th>Group</th> @@ -59,26 +203,24 @@ <tbody> {% for result in results.phenotype %} <tr> - {% for result in result.result_fields.items() %} - <td>{{ result['phenotype_id'] }}</td> - <td>{{ result['species'] }}</td> - <td>{{ result['group_name'] }}</td> - <td>{{ result['description'] }}</td> - <td>{{ result['lrs'] }}</td> + <td>{{ result.result_fields['phenotype_id'] }}</td> + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['description'] }}</td> + <td>{{ result.result_fields['lrs'] }}</td> <td> - <a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids={{ result['pubmed_id'] }}&dopt=Abstract"> - {{ result['year'] }} + <a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids={{ result.result_fields['pubmed_id'] }}&dopt=Abstract"> + {{ result.result_fields['year'] }} </a> </td> - <td>{{ result['authors'] }}</td> - {% endfor %} + <td>{{ result.result_fields['authors'] }}</td> </tr> {% endfor %} </tbody> </table> </div> <div class="tab-pane" id="tab2"> - <table class="table table-hover"> + <table id="mrna_assay_results" class="table table-hover table-striped table-bordered"> <thead> <tr> <th>Record ID</th> @@ -95,28 +237,26 @@ <tbody> {% for result in results.mrna_assay %} <tr> - {% for result in result.result_fields.items() %} <td> - <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result['name'] }}&dataset={{ result['dataset'] }}" - {{ result['name'] }} + <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result.result_fields['name'] }}&dataset={{ result.result_fields['dataset'] }}" + {{ result.result_fields['name'] }} </a> </td> - <td>{{ result['species'] }}</td> - <td>{{ result['group_name'] }}</td> - <td>{{ result['dataset_name'] }}</td> - <td>{{ result['symbol'] }}</td> - <td>{{ result['description'] }}</td> - <td>{{ result['chr'] }} : {{ result['mb'] }}</td> - <td>{{ result['mean'] }}</td> - <td>{{ result['lrs'] }}</td> - {% endfor %} + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['dataset_name'] }}</td> + <td>{{ result.result_fields['symbol'] }}</td> + <td>{{ result.result_fields['description'] }}</td> + <td>{{ result.result_fields['chr'] }} : {{ result['mb'] }}</td> + <td>{{ result.result_fields['mean'] }}</td> + <td>{{ result.result_fields['lrs'] }}</td> </tr> {% endfor %} </tbody> </table> </div> <div class="tab-pane" id="tab3"> - <table class="table table-hover"> + <table id="geno_results" class="table table-hover table-striped table-bordered"> <thead> <tr> <th>Marker</th> @@ -127,91 +267,60 @@ </tr> </thead> <tbody> - {% for result in results.mrna_assay %} + {% for result in results.genotype %} <tr> - {% for result in result.result_fields.items() %} <td> - <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result['marker_name'] }}&dataset={{ result['dataset'] }}"> - {{ result['marker_name'] }} + <a href="http://gn2python.genenetwork.org/show_trait?trait_id={{ result.result_fields['marker_name'] }}&dataset={{ result.result_fields['dataset'] }}"> + {{ result.result_fields['marker_name'] }} </a> </td> - <td>{{ result['species'] }}</td> - <td>{{ result['group_name'] }}</td> - <td>{{ result['dataset_name'] }}</td> - <td>{{ result['chr'] }} : {{ result['mb'] }}</td> - {% endfor %} + <td>{{ result.result_fields['species'] }}</td> + <td>{{ result.result_fields['group_name'] }}</td> + <td>{{ result.result_fields['dataset_name'] }}</td> + <td>{{ result.result_fields['chr'] }} : {{ result.result_fields['mb'] }}</td> </tr> {% endfor %} </tbody> </table> </div> - </div> - </div> - - - - <!--<div class="bs-docs-example"> - <table class="table table-hover"> - <thead> - <tr> - {% for header in header_fields %} - <th>{{header}}</th> - {% endfor %} - </tr> - </thead> - - <tbody> - {% for this_trait in trait_list %} - <TR id="{{ this_trait }}"> - <TD> - <INPUT TYPE="checkbox" NAME="searchResult" class="checkbox" - VALUE="{{ this_trait }}"> - </TD> - <TD> - <a href="{{ url_for('show_trait_page', - trait_id = this_trait.name, - dataset = dataset.name - )}}"> - {{ this_trait.name }} - </a> - </TD> - {% if dataset.type == 'ProbeSet' %} - <TD>{{ this_trait.symbol }}</TD> - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.location_repr }}</TD> - <TD>{{ this_trait.mean }}</TD> - <TD>{{ this_trait.LRS_score_repr }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - {% elif dataset.type == 'Publish' %} - <TD>{{ this_trait.description_display }}</TD> - <TD>{{ this_trait.authors }}</TD> - <TD> - <a href="{{ this_trait.pubmed_link }}"> - {{ this_trait.pubmed_text }} - </a> - </TD> - <TD>{{ this_trait.LRS_score_repr }}</TD> - <TD>{{ this_trait.LRS_location_repr }}</TD> - {% elif dataset.type == 'Geno' %} - <TD>{{ this_trait.location_repr }}</TD> - {% endif %} - </TR> - {% endfor %} - </tbody> + #} - </table> - - <br /> - - <button class="btn"><i class="icon-ok"></i> Select</button> - <button class="btn"><i class="icon-remove"></i> Deselect</button> - <button class="btn"><i class="icon-resize-vertical"></i> Invert</button> - <button class="btn"><i class="icon-plus-sign"></i> Add</button> - <button class="btn btn-primary pull-right"><i class="icon-download icon-white"></i> Download Table</button> - </div>--> +<!-- End of body --> - </div> +{% endblock %} -<!-- End of body --> +{% block js %} + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.js"></script> + <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script> + <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script> + + <script type="text/javascript" charset="utf-8"> + $(document).ready( function () { + console.time("Creating table"); + $('#pheno_results, #mrna_assay_results, #geno_results').dataTable( { + //"sDom": "<<'span3'l><'span3'T><'span4'f>'row-fluid'r>t<'row-fluid'<'span6'i><'span6'p>>", + "sDom": "lTftipr", + "oTableTools": { + "aButtons": [ + "copy", + "print", + { + "sExtends": "collection", + "sButtonText": 'Save <span class="caret" />', + "aButtons": [ "csv", "xls", "pdf" ] + } + ], + "sSwfPath": "/static/packages/TableTools/media/swf/copy_csv_xls_pdf.swf" + }, + "iDisplayLength": 50, + "bLengthChange": true, + "bDeferRender": true, + "bSortClasses": false + } ); + console.timeEnd("Creating table"); + }); + </script> {% endblock %} |