Skip to content

Commit

Permalink
custom comparative heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Nov 30, 2017
1 parent 3faa8f9 commit 9e7d62c
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 52 deletions.
94 changes: 61 additions & 33 deletions conekt/controllers/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from conekt import cache
from conekt.forms.heatmap import HeatmapForm
from conekt.forms.heatmap import HeatmapForm, HeatmapComparableForm
from conekt.models.expression.coexpression_clusters import CoexpressionCluster
from conekt.models.expression.profiles import ExpressionProfile
from conekt.models.relationships.sequence_cluster import SequenceCoexpressionClusterAssociation
Expand Down Expand Up @@ -53,47 +53,75 @@ def heatmap_main():
form.populate_species()
form.populate_options()

if request.method == 'POST':
terms = request.form.get('probes').split()
species_id = request.form.get('species_id')
form2 = HeatmapComparableForm(request.form)
form2.populate_options()

option = request.form.get('options')
profiles = ExpressionProfile.query.filter(ExpressionProfile.sequence_id is not None).order_by(ExpressionProfile.species_id).limit(5).all()

probes = terms
example = {
'species_id': None,
'probes': None,
'options': 'zlog'
}

if len(profiles) > 0:
example['species_id'] = profiles[0].species_id
example['probes'] = ' '.join([p.sequence.name for p in profiles])

# also do search by gene ID
sequences = Sequence.query.filter(Sequence.name.in_(terms)).all()
return render_template("expression_heatmap.html", form=form, form2=form2, example=example)

for s in sequences:
for ep in s.expression_profiles:
probes.append(ep.probe)

# make probe list unique
probes = list(set(probes))
# TODO check if certain probes were not found and warn the user
current_heatmap = ExpressionProfile.get_heatmap(species_id, probes,
zlog=(option == 'zlog'),
raw=(option == 'raw'))
@heatmap.route('/results/default', methods=['POST'] )
def heatmap_custom_normal():
form = HeatmapForm(request.form)
form.populate_species()
form.populate_options()

return render_template("expression_heatmap.html", order=current_heatmap['order'],
profiles=current_heatmap['heatmap_data'],
form=form,
zlog=1 if option == 'zlog' else 0,
raw=1 if option == 'raw' else 0)
else:
profiles = ExpressionProfile.query.filter(ExpressionProfile.sequence_id is not None).order_by(ExpressionProfile.species_id).limit(5).all()
terms = request.form.get('probes').split()
species_id = request.form.get('species_id')

example = {
'species_id': None,
'probes': None,
'options': 'zlog'
}
option = request.form.get('options')

if len(profiles) > 0:
example['species_id'] = profiles[0].species_id
example['probes'] = ' '.join([p.sequence.name for p in profiles])
probes = terms

return render_template("expression_heatmap.html", form=form, example=example)
# also do search by gene ID
sequences = Sequence.query.filter(Sequence.name.in_(terms)).all()

for s in sequences:
for ep in s.expression_profiles:
probes.append(ep.probe)

# make probe list unique
probes = list(set(probes))
# TODO check if certain probes were not found and warn the user
current_heatmap = ExpressionProfile.get_heatmap(species_id, probes,
zlog=(option == 'zlog'),
raw=(option == 'raw'))

return render_template("expression_heatmap.html", order=current_heatmap['order'],
profiles=current_heatmap['heatmap_data'],
zlog=1 if option == 'zlog' else 0,
raw=1 if option == 'raw' else 0)


@heatmap.route('/results/comparable', methods=['POST'] )
def heatmap_custom_comparable():
form = HeatmapComparableForm(request.form)
form.populate_options()

terms = request.form.get('probes').split()

option = request.form.get('options')

sequences = Sequence.query.filter(Sequence.name.in_(terms)).all()
sequence_ids = [s.id for s in sequences]

current_heatmap = CrossSpeciesExpressionProfile().get_heatmap(*sequence_ids, option=option)

return render_template("expression_heatmap.html", order=current_heatmap['order'],
profiles=current_heatmap['heatmap_data'],
zlog=1 if option == 'zlog' else 0,
raw=1 if option == 'raw' else 0)


@heatmap.route('/comparative/tree/<int:tree_id>')
Expand Down
8 changes: 8 additions & 0 deletions conekt/forms/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ def populate_species(self):
def populate_options(self):
self.options.choices = [('raw', 'Raw'), ('zlog', 'zLog-ransformed'), ('rnorm', 'Row-normalized')]


class HeatmapComparableForm(FlaskForm):
probes = TextAreaField('probes', [InputRequired()])

options = SelectField('options')

def populate_options(self):
self.options.choices = [('raw', 'Raw'), ('rnorm', 'Row-normalized')]
65 changes: 46 additions & 19 deletions conekt/templates/expression_heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,55 @@ <h1>Heatmap</h1>
<p>Creates an expression heatmap (table with shaded cells) for a selected set of genes.</p>
<div class="row">
<div class="col-md-8 col-sm-6 col-xs-12">
<div class="panel panel-primary">
<div class="panel-heading"><strong>Select genes</strong></div>
<div class="panel-body">
<form method="POST" action="{{ url_for('heatmap.heatmap_main') }}" role="form">
<div class="row">
<div class="col-xs-12">
{{ form.csrf_token }}
{{form.species_id(class_="form-control") }}<br />
{{form.probes(class_="form-control") }}<br />
{{form.options(class_="form-control") }}<br />
<div class="pull-right">
{% if example and example.probes %}
<button class="btn btn-default" id="load_example">Load example</button>
{% endif %}
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#loaderModal">Generate heatmap</button>
</div>
<div class="panel with-nav-tabs panel-default">
<div class="panel-heading">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1default" data-toggle="tab">Normal</a></li>
<li><a href="#tab2default" data-toggle="tab">Comparative</a></li>
</ul>
</div>
<div>
<div class="tab-content">
<div class="tab-pane fade in active" id="tab1default">
<div class="panel-body">
<form method="POST" action="{{ url_for('heatmap.heatmap_custom_normal') }}" role="form">
<div class="row">
<div class="col-xs-12">
{{ form.csrf_token }}
{{form.species_id(class_="form-control") }}<br />
{{form.probes(class_="form-control") }}<br />
{{form.options(class_="form-control") }}<br />
<div class="pull-right">
{% if example and example.probes %}
<button class="btn btn-default" id="load_example">Load example</button>
{% endif %}
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#loaderModal">Generate heatmap</button>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="tab-pane fade in" id="tab2default">
<div class="panel-body">
<form method="POST" action="{{ url_for('heatmap.heatmap_custom_comparable') }}" role="form">
<div class="row">
<div class="col-xs-12">
{{ form2.csrf_token }}
{{form2.probes(class_="form-control") }}<br />
{{form2.options(class_="form-control") }}<br />
<div class="pull-right">
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#loaderModal">Generate heatmap</button>
</div>
</div>
</div>
</form>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading"><strong>Help</strong></div>
Expand Down

0 comments on commit 9e7d62c

Please sign in to comment.