aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorZachary Sloan2013-04-10 21:19:08 +0000
committerZachary Sloan2013-04-10 21:19:08 +0000
commit4d736528dd650793a498b24909567638972d2d08 (patch)
tree7ac2f765dbe270251e8f3980b9fda51a7ddb72d7 /wqflask
parentd2e64633a40ecab55c9cedd46b0a8f9e93761aad (diff)
downloadgenenetwork2-4d736528dd650793a498b24909567638972d2d08.tar.gz
Created template for quick search page
Fixed a couple bugs with quick_search_table.py
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/maintenance/quick_search_table.py64
-rw-r--r--wqflask/wqflask/search_results.py7
-rw-r--r--wqflask/wqflask/templates/quick_search.html215
3 files changed, 256 insertions, 30 deletions
diff --git a/wqflask/maintenance/quick_search_table.py b/wqflask/maintenance/quick_search_table.py
index a6ca6265..75bc7d00 100644
--- a/wqflask/maintenance/quick_search_table.py
+++ b/wqflask/maintenance/quick_search_table.py
@@ -24,6 +24,8 @@ from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.ext.declarative import declarative_base
+from pprint import pformat as pf
+
import zach_settings as settings
Engine = sa.create_engine(settings.SQLALCHEMY_DATABASE_URI,
@@ -124,6 +126,7 @@ class PublishXRef(Base):
"description",
"lrs",
"publication_id",
+ "pubmed_id",
"year",
"authors"
).from_statement(
@@ -133,6 +136,7 @@ class PublishXRef(Base):
"Phenotype.Original_description as description, "
"PublishXRef.LRS as lrs, "
"PublishXRef.PublicationId as publication_id, "
+ "Publication.PubMed_ID"
"Publication.Year as year, "
"Publication.Authors as authors "
"FROM PublishXRef, "
@@ -173,7 +177,7 @@ class PublishXRef(Base):
return json_results
class GenoXRef(Base):
- __tablename__ = 'ProbeSetXRef'
+ __tablename__ = 'GenoXRef'
GenoFreezeId = sa.Column(sa.Integer, primary_key=True)
GenoId = sa.Column(sa.Integer, primary_key=True)
@@ -191,14 +195,16 @@ class GenoXRef(Base):
values['the_key'] = json.dumps([item.GenoId, item.GenoFreezeId])
values['terms'] = cls.get_unique_terms(item.GenoId)
print("terms is:", values['terms'])
- values['result_fields'] = cls.get_result_fields(item.GenoId, item.GenoFreezeId)
- ins = QuickSearch.insert().values(**values)
- conn.execute(ins)
+ if values['terms']:
+ values['result_fields'] = cls.get_result_fields(item.GenoId, item.GenoFreezeId)
+ ins = QuickSearch.insert().values(**values)
+ conn.execute(ins)
counter += 1
print("Done:", counter)
@staticmethod
def get_unique_terms(geno_id):
+ print("geno_id: ", geno_id)
results = Session.query(
"name",
"marker_name"
@@ -208,23 +214,26 @@ class GenoXRef(Base):
"FROM Geno "
"WHERE Geno.Id = :geno_id ").params(geno_id=geno_id).all()
+ print("results: ", pf(results))
+
unique = set()
- for item in results[0]:
- #print("locals:", locals())
- if not item:
- continue
- for token in item.split():
- if len(token) > 2:
- try:
- # This hopefully ensures that the token is utf-8
- token = token.encode('utf-8')
- print(" ->", token)
- except UnicodeDecodeError:
- print("\n-- UDE \n")
- # Can't get it into utf-8, we won't use it
- continue
-
- unique.add(token)
+ if len(results):
+ for item in results[0]:
+ #print("locals:", locals())
+ if not item:
+ continue
+ for token in item.split():
+ if len(token) > 2:
+ try:
+ # This hopefully ensures that the token is utf-8
+ token = token.encode('utf-8')
+ print(" ->", token)
+ except UnicodeDecodeError:
+ print("\n-- UDE \n")
+ # Can't get it into utf-8, we won't use it
+ continue
+
+ unique.add(token)
print("\nUnique terms are: {}\n".format(unique))
return " ".join(unique)
@@ -233,18 +242,13 @@ class GenoXRef(Base):
def get_result_fields(geno_id, dataset_id):
results = Session.query(
"name",
- "species",
+ "marker_name",
"group_name",
+ "species",
"dataset",
"dataset_name",
- "symbol",
- "description",
"chr", "mb",
- "lrs",
- "genbank_id",
- "gene_id",
- "chip_id",
- "chip_name"
+ "source"
).from_statement(
"SELECT Geno.Name as name, "
"Geno.Marker_Name as marker_name, "
@@ -374,7 +378,7 @@ class ProbeSetXRef(Base):
"symbol",
"description",
"chr", "mb",
- "lrs",
+ "lrs", "mean",
"genbank_id",
"gene_id",
"chip_id",
@@ -390,6 +394,7 @@ class ProbeSetXRef(Base):
"ProbeSet.Chr as chr, "
"ProbeSet.Mb as mb, "
"ProbeSetXRef.LRS as lrs, "
+ "ProbeSetXRef.mean as mean, "
"ProbeSet.GenbankId as genbank_id, "
"ProbeSet.GeneId as gene_id, "
"ProbeSet.ChipId as chip_id, "
@@ -463,6 +468,7 @@ def page_query(q):
def main():
+ GenoXRef.run()
ProbeSetXRef.run()
PublishXRef.run()
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index 499782ac..dc872a8b 100644
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -39,8 +39,13 @@ from utility import formatting
#from base.JinjaPage import JinjaEnv, JinjaPage
+#class QuickSearchResult(object):
+ #def __init__(self, key, result_fields):
+ # self.key = key
+ # self.result_fields = result_fields
+
-class SearchResultPage():
+class SearchResultPage(object):
#maxReturn = 3000
diff --git a/wqflask/wqflask/templates/quick_search.html b/wqflask/wqflask/templates/quick_search.html
new file mode 100644
index 00000000..d50b4937
--- /dev/null
+++ b/wqflask/wqflask/templates/quick_search.html
@@ -0,0 +1,215 @@
+{% extends "base.html" %}
+{% block title %}QuickSearch Results{% endblock %}
+{% block content %}
+<!-- Start of body -->
+ <header class="jumbotron subhead" id="overview">
+ <div class="container">
+ <h1>QuickSearch Results</h1>
+ <p class="lead">
+ GeneNetwork found {{ numify(results|count, "record", "records") }}.
+ </p>
+ </div>
+ </header>
+
+ <div class="container">
+ <div class="page-header">
+ <h1>Your Search</h1>
+ </div>
+
+ <p>We across all data sets to find all records that match:</p>
+
+ <ul>
+ {% if search_terms %}
+ <li>
+ {% for word in search_terms %}
+ <strong>{{word}}</strong> {% if not loop.last %} or {% endif %}
+ {% endfor %}
+ </li>
+ {% endif %}
+ </ul>
+
+ <p>To study a record, click on its ID below.<br />
+ Check records below and click Add button to add to selection.</p>
+
+ <div class="tabbable"> <!-- Only required for left/right tabs -->
+ <ul class="nav nav-tabs">
+ <li class="active"> <a href="#tab1" data-toggle="tab">Phenotype</a></li>
+ <li> <a href="#tab2" data-toggle="tab">mRNA Assay</a></li>
+ <li> <a href="#tab3" data-toggle="tab">Genotype</a></li>
+ </ul>
+ <div class="tab-content">
+ <div class="tab-pane active" id="tab1">
+ <table class="table table-hover">
+ <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>
+ <th>Description</th>
+ <th>LRS</th>
+ <th>Year</th>
+ <th>Authors</th>
+ </tr>
+ </thead>
+ <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>
+ <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>
+ </td>
+ <td>{{ result['authors'] }}</td>
+ {% endfor %}
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ <div class="tab-pane" id="tab2">
+ <table class="table table-hover">
+ <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 %}
+ <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>
+ </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 %}
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ <div class="tab-pane" id="tab3">
+ <table class="table table-hover">
+ <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.mrna_assay %}
+ <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>
+ </td>
+ <td>{{ result['species'] }}</td>
+ <td>{{ result['group_name'] }}</td>
+ <td>{{ result['dataset_name'] }}</td>
+ <td>{{ result['chr'] }} : {{ result['mb'] }}</td>
+ {% endfor %}
+ </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>-->
+
+ </div>
+
+<!-- End of body -->
+
+{% endblock %}