Skip to content

Commit

Permalink
Changed the position of available fields table, made it populate from…
Browse files Browse the repository at this point in the history
… a direct query, added a notes file to pull from, moved the request handlers to api/handlers.
  • Loading branch information
cyrus0824 committed Jun 12, 2015
1 parent dd0a7a6 commit 9b7bae1
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 68 deletions.
12 changes: 5 additions & 7 deletions docs/_static/myvariant_doc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
jQuery(document).ready(function() {
if( jQuery(' .indexed-field-table ').length ) {
jQuery.ajax({
url: "http://myvariant.info/v1/indexed_fields",
url: "http://myvariant.info/v1/fields",
dataType: "JSONP",
jsonpCallback: "callback",
type: "GET",
success: function(data) {
jQuery.each(data, function(field, d) {
if(d.indexed) {
jQuery('.indexed-field-table > tbody:last').append('<tr><td>' + field + '</td><td>&#x2714</td><td><span class="italic">' + d.type + '</span></td><td>' + d.example + '</td>');
}
else {
jQuery('.indexed-field-table > tbody:last').append('<tr><td>' + field + '</td><td>&nbsp</td><td><span class="italic">' + d.type + '</span></td><td>' + d.example + '</td>');
}
var notes = indexed = '&nbsp;';
if(d.notes) {notes=d.notes;}
if(d.indexed) {indexed='&#x2714';}
jQuery('.indexed-field-table > tbody:last').append('<tr><td>' + field + '</td><td>' + indexed + '</td><td><span class="italic">' + d.type + '</span></td><td>' + notes + '</td>');
});
jQuery('.indexed-field-table').DataTable({
"iDisplayLength": 50,
Expand Down
39 changes: 39 additions & 0 deletions docs/doc/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,45 @@ is essentially a collection of fields (attributes) and their values:
The example above omits many of the available fields. For a full example,
check out `this example variant <http://myvariant.info/v1/variant/chr1:g.35367G%3EA>`_, or try the `interactive API page <http://myvariant.info/v1/api>`_.

.. _available_fields:

Available fields
----------------

The table below lists all of the possible fields that could be in a variant object, as well as all of their parents (for nested fields). If the field is indexed, it may also be directly queried, e.g.

::

q=dbnsfp.polyphen2.hdiv.score:>0.99


All fields can be used with _exists_ or _missing_ filters, e.g.

::

q=_exists_:dbsnp AND _exists_:cosmic
q=_missing_:wellderly

or as inputs to the fields parameter, e.g.

::

q=_exists_:dbsnp&fields=dbsnp.rsid,dbsnp.vartype


.. raw:: html

<table class='indexed-field-table stripe'>
<thead>
<tr>
<th>Field</th>
<th>Indexed</th>
<th>Type</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
</tbody>
</table>

<div id="spacer" style="height:300px"></div>
4 changes: 2 additions & 2 deletions docs/doc/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ URL

http://myvariant.info/v1/variant/<variant_id>

"*\<variant_id\>*" is an HGVS name based variant id using genomic location based on hg19 human genome assembly..

Examples
""""""""
::
Expand All @@ -59,8 +61,6 @@ Examples
http://myvariant.info/v1/variant/chr16:g.28883241A>G
http://myvariant.info/v1/variant/chr3:g.49721532G>A

"*\<variant_id\>*" is an HGVS name based variant id using genomic location based on hg19 human genome assembly..


To learn more
"""""""""""""
Expand Down
22 changes: 4 additions & 18 deletions docs/doc/variant_query_service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,17 @@ Fielded queries
q=dbsnp.vartype:snp


.. _available_fields:

Available fields
^^^^^^^^^^^^^^^^

.. raw:: html

<table class='indexed-field-table stripe'>
<thead>
<tr>
<th>Field</th>
<th>Indexed</th>
<th>Type</th>
<th>Example</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
For a list of available fields, see :ref:`here <available_fields>`.


Wildcard queries
""""""""""""""""
Wildcard character "*" or "?" is supported in either simple queries or fielded queries::

q=

.. note:: Wildcard character can not be the first character. It will be ignored.

Expand Down Expand Up @@ -266,7 +252,7 @@ q
scopes
""""""
Optional, specify one or more fields (separated by comma) as the search "scopes", e.g., "scopes=dbsnp.rsid", "scopes=dbsnp.rsid,dbnsfp.genename". The available "fields" can be passed to "**scopes**" parameter are
:ref:`listed above <available_fields>`. Default:
:ref:`listed here <available_fields>`. Default:

fields
""""""
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Documentation
:maxdepth: 3

Try it live on interactive API page <http://myvariant.info/v1/api>
doc/quick_start
doc/data
doc/variant_query_service
doc/variant_annotation_service
Expand Down
5 changes: 5 additions & 0 deletions src/www/api/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ def query_interval(self, chr, gstart, gend, **kwargs):
_query["query"]["bool"]["should"].append(_q)
return self._es.search(index=self._index, doc_type=self._doc_type, body=_query, **kwargs)

def query_fields(self, **kwargs):
# query the metadata to get the available fields for a variant object
r = self._es.indices.get(index=self._index)
return r[list(r.keys())[0]]['mappings']['variant']['properties']


class ESQueryBuilder:
def __init__(self, **query_options):
Expand Down
63 changes: 61 additions & 2 deletions src/www/api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from www.helper import BaseHandler
from .es import ESQuery
from utils.common import split_ids
import config


class VariantHandler(BaseHandler):
Expand Down Expand Up @@ -140,8 +141,66 @@ def post(self):
'value': len(q) if q else 0})


class MetaDataHandler(BaseHandler):
disable_caching = True

def get(self):
# For now, just return a hardcoded object, later we'll actually query the ES db for this information
self.return_json({
"stats": {
'total': 286219908,
'evs': 1977300,
'cadd': 163690986,
'wellderly': 21240519,
'dbnsfp': 78045379,
'snpedia': 5907,
'clinvar': 85789,
'docm': 1119,
'mutdb': 420221,
'cosmic': 1024498,
'dbsnp': 110234210,
'emv': 12066,
'gwassnps': 15243
},
"timestamp": "2015-04-15T11:39:48.309000"
})


class FieldsHandler(BaseHandler):
esq = ESQuery()

def get(self):
notes = json.load(open(config.FIELD_NOTES_PATH, 'r'))
es_mapping = self.esq.query_fields()

def get_indexed_properties_in_dict(d, prefix):
r = {}
for (k, v) in d.items():
r[prefix + '.' + k] = {}
r[prefix + '.' + k]['indexed'] = False
if 'type' in v:
r[prefix + '.' + k]['type'] = v['type']
if ('index' not in v) or ('index' in v and v['index'] != 'no'):
# indexed field
r[prefix + '.' + k]['indexed'] = True
else:
r[prefix + '.' + k]['type'] = 'object'
r.update(get_indexed_properties_in_dict(v['properties'], prefix + '.' + k))
return r

r = {}
for (k, v) in get_indexed_properties_in_dict(es_mapping, '').items():
k1 = k.lstrip('.')
r[k1] = v
if k1 in notes:
r[k1]['notes'] = notes[k1]
self.return_json(r)


APP_LIST = [
(r"/variant/(.+)/?", VariantHandler), # for gene get request
(r"/variant/?$", VariantHandler), # for gene post request
(r"/variant/(.+)/?", VariantHandler), # for variant get request
(r"/variant/?$", VariantHandler), # for variant post request
(r"/query/?", QueryHandler),
(r"/metadata", MetaDataHandler), # for metadata requests
(r"/fields", FieldsHandler), # for available field information
]
4 changes: 4 additions & 0 deletions src/www/context/myvariant_field_table_notes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cadd":"From the <a href='cadd.gs.washington.edu' target='_blank'>CADD</a> database.",
"dbsnp":"From the <a href='www.ncbi.nlm.nih.gov/SNP/' target='_blank'>dbSNP</a> database."
}
41 changes: 2 additions & 39 deletions src/www/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
import os.path
#import subprocess
import json
#import json

import tornado.httpserver
import tornado.ioloop
Expand All @@ -25,7 +25,7 @@
#from config import INCLUDE_DOCS

from www.api.es import ESQuery
from www.helper import add_apps, BaseHandler
from www.helper import add_apps
from www.api.handlers import APP_LIST as api_app_list
from www.beacon.handlers import APP_LIST as beacon_app_list

Expand All @@ -46,15 +46,6 @@
options.address = '0.0.0.0'


class IndexedFieldsHandler(BaseHandler):
def get(self):
try:
with open('context/myvariant_indexed_fields.json', 'r') as json_file:
self.return_json(json.load(json_file))
except FileNotFoundError:
self.return_json({})


class StatusCheckHandler(tornado.web.RequestHandler):
''' Handles requests to check the status of the server. '''
def head(self):
Expand All @@ -72,37 +63,9 @@ def get(self):
self.render(os.path.join(STATIC_PATH, 'index.html'))


class MetaDataHandler(BaseHandler):
disable_caching = True

def get(self):
# For now, just return a hardcoded object, later we'll actually query the ES db for this information
self.return_json({
"stats": {
'total': 286219908,
'evs': 1977300,
'cadd': 163690986,
'wellderly': 21240519,
'dbnsfp': 78045379,
'snpedia': 5907,
'clinvar': 85789,
'docm': 1119,
'mutdb': 420221,
'cosmic': 1024498,
'dbsnp': 110234210,
'emv': 12066,
'gwassnps': 15243
},
"timestamp": "2015-04-15T11:39:48.309000"
})


APP_LIST = [
(r"/", MainHandler),
(r"/metadata", MetaDataHandler),
(r"/v1/metadata", MetaDataHandler),
(r"/status", StatusCheckHandler),
(r"/v1/indexed_fields", IndexedFieldsHandler),
]

APP_LIST += add_apps('api', api_app_list)
Expand Down

0 comments on commit 9b7bae1

Please sign in to comment.