Skip to content

Commit

Permalink
Merge pull request #106 from ElDeveloper/webfleshout-the-revenge
Browse files Browse the repository at this point in the history
Add data type and commands selection
  • Loading branch information
antgonza committed Jun 19, 2014
2 parents bcf4a24 + a657183 commit 6b25366
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 9 deletions.
48 changes: 47 additions & 1 deletion qiita_pet/handlers/analysis_handlers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from tornado.web import authenticated
from collections import defaultdict

from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_db.user import User
from qiita_db.analysis import Analysis
from qiita_db.study import Study
from qiita_db.data import ProcessedData
from qiita_db.metadata_template import SampleTemplate
# login code modified from https://gist.github.com/guillaumevincent/4771570


Expand Down Expand Up @@ -31,4 +34,47 @@ def post(self):
analysis = Analysis.create(User(user), name, description)

self.render('select_studies.html', user=user, aid=analysis.id,
studies=studies)
studies=studies)


class SelectCommandsHandler(BaseHandler):
"""Select commands to be executed"""
@authenticated
def post(self):
analysis_id = self.get_argument('analysis-id')
study_args = self.get_arguments('studies')
split = [x.split("#") for x in study_args]

# build dictionary of studies and datatypes selected
# as well a set of unique datatypes selected
study_dts = defaultdict(list)
data_types = set()
for study_id, data_type in split:
study_dts[study_id].append(data_type)
data_types.add(data_type)

# sort the elements to have 16S be the first tho show on the tabs
data_types = sorted(list(data_types))

# FIXME: Pull out from the database, see #111
commands = {'16S': ['Alpha Diversity', 'Beta Diversity',
'Summarize Taxa'],
'18S': ['Alpha Diversity', 'Beta Diversity',
'Summarize Taxa'],
'Metabolomic': ['Summarize Taxa']}

self.render('select_commands.html', user=self.get_current_user(),
commands=commands, data_types=data_types, aid=analysis_id)

analysis = Analysis(analysis_id)

for study_id in study_dts:
study = Study(study_id)
processed_data = {ProcessedData(pid).data_type: pid for pid in
study.processed_data}

sample_ids = SampleTemplate(study.id).keys()
for data_type in study_dts[study.id]:
samples = [(processed_data[data_type], sid) for sid in
sample_ids]
analysis.add_samples(samples)
2 changes: 1 addition & 1 deletion qiita_pet/templates/404.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%extends base.html%}
{%extends sitebase.html%}
{%block content%}
<h1>404: Page not found!</h1>
{%end%}
48 changes: 48 additions & 0 deletions qiita_pet/templates/select_commands.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends sitebase.html %}
{% autoescape None %}

{%block head%}
<script>
$(function () {
$('#data-types-tabs a:first').tab('show')
})
</script>
{%end%}

{%block content %}

<h1>Select Commands</h1>

<ul class="nav nav-tabs" id="data-types-tabs">
{% for data_type in data_types %}
<li><a href="#{{ data_type }}" data-toggle="tab">{{ data_type }}</a></li>
{% end %}
</ul>

<form role="form" action="/analysis/wait/" method="post">
<input type="hidden" name="analysis-id" value="{{aid}}">
<div class="tab-content" style="height:300px">
{% for data_type in data_types %}
<div class="tab-pane" id="{{ data_type }}">
<table class="table">
<tr>
<th style="width:20px;"></th>
<th>Command</th>
</tr>
{% for command in commands[data_type] %}
<tr>
<td style="width:20px;">
<input id="{{data_type}}#{{command}}" type="checkbox" name="commands" value="{{data_type}}#{{command}}">
</td>
<td>
<label style="font-weight:normal;" for="{{data_type}}#{{command}}">{{command}}</label>
</td>
</tr>
{% end %}
</table>
</div>
{% end %}
</div>
<button type="submit" class="btn btn-default">Start Processing</button>
</form>
{% end %}
15 changes: 10 additions & 5 deletions qiita_pet/templates/select_studies.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ <h1>Studies</h1>
<input type="hidden" name="analysis-id" value="{{aid}}">
<table class="table table-hover">
<tr>
<th> </th>
<th>Data Types</th>
<th>Study Name</th>
<th>Description</th>
</tr>
{% for study in studies %}
<tr>
<td><input type="checkbox" name="studies" value="{{study.id}}"></td>
<td>{{study.title}}</td>
<td>{{study.info["study_description"]}}</td>
<td>
{% for data_type in study.data_types %}
<input type="checkbox" name="studies" value="{{study.id}}#{{data_type}}">{{data_type}}
<br />
{% end %}
</td>
<td style="vertical-align:middle;">{{study.title}}</td>
<td style="vertical-align:middle;">{{study.info["study_description"]}}</td>
</tr>
{% end %}
</table>
<button type="submit" class="btn btn-default">Select studies</button>
</form>
</div>

{% end %}
{% end %}
5 changes: 3 additions & 2 deletions qiita_pet/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from qiita_pet.handlers.auth_handlers import (
AuthCreateHandler, AuthLoginHandler, AuthLogoutHandler, AuthVerifyHandler)
from qiita_pet.handlers.analysis_handlers import (
CreateAnalysisHandler, SelectStudiesHandler)
CreateAnalysisHandler, SelectStudiesHandler, SelectCommandsHandler)

define("port", default=8888, help="run on the given port", type=int)

Expand All @@ -42,6 +42,7 @@ def __init__(self):
{"path": STATIC_PATH}),
(r"/analysis/1", CreateAnalysisHandler),
(r"/analysis/2", SelectStudiesHandler),
(r"/analysis/3", SelectCommandsHandler),
(r"/mockup/", MockupHandler),
# 404 PAGE MUST BE LAST IN THIS LIST!
(r".*", NoPageHandler)
Expand All @@ -63,4 +64,4 @@ def main():
tornado.ioloop.IOLoop.instance().start()

if __name__ == "__main__":
main()
main()

0 comments on commit 6b25366

Please sign in to comment.