Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
example for custom heatmap
  • Loading branch information
proost committed Dec 6, 2017
1 parent c118fc6 commit e9727dd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
29 changes: 25 additions & 4 deletions conekt/controllers/heatmap.py
Expand Up @@ -6,6 +6,7 @@
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.condition_tissue import ConditionTissue
from conekt.models.relationships.sequence_cluster import SequenceCoexpressionClusterAssociation
from conekt.models.sequences import Sequence
from conekt.models.trees import Tree
Expand Down Expand Up @@ -56,6 +57,7 @@ def heatmap_main():
form2 = HeatmapComparableForm(request.form)
form2.populate_options()

# Fetch data for normal example, get five profiles from a species
profiles = ExpressionProfile.query.filter(ExpressionProfile.sequence_id is not None).order_by(ExpressionProfile.species_id).limit(5).all()

example = {
Expand All @@ -68,10 +70,29 @@ def heatmap_main():
example['species_id'] = profiles[0].species_id
example['probes'] = ' '.join([p.sequence.name for p in profiles])

return render_template("expression_heatmap.html", form=form, form2=form2, example=example)
# Fetch data for comparative profile
condition_tissue = ConditionTissue.query.filter(ConditionTissue.in_tree == 1).all()
species_ids = [ct.species_id for ct in condition_tissue]
comparative_profiles = []

for s_id in species_ids[:3]:
profiles = ExpressionProfile.query.filter(ExpressionProfile.sequence_id is not None).filter(
ExpressionProfile.species_id == s_id).limit(3).all()
for p in profiles:
comparative_profiles.append(p.sequence.name)

# Fetch data for second example
example2 = {
'comparable_probes': ' '.join(comparative_profiles) if len(comparative_profiles) > 0 else None,
'comparable_options': 'rnorm'
}

return render_template("expression_heatmap.html", form=form, form2=form2,
example=example,
example2=example2)


@heatmap.route('/results/default', methods=['POST'] )
@heatmap.route('/results/default', methods=['POST'])
def heatmap_custom_default():
form = HeatmapForm(request.form)
form.populate_species()
Expand Down Expand Up @@ -111,9 +132,9 @@ def heatmap_custom_comparable():
form = HeatmapComparableForm(request.form)
form.populate_options()

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

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

if len(terms) == 0:
flash("No genes selected!", "warning")
Expand Down
6 changes: 3 additions & 3 deletions conekt/forms/heatmap.py
Expand Up @@ -19,9 +19,9 @@ def populate_options(self):


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

options = SelectField('options')
comparable_options = SelectField('options')

def populate_options(self):
self.options.choices = [('raw', 'Raw'), ('rnorm', 'Row-normalized')]
self.comparable_options.choices = [('raw', 'Raw'), ('rnorm', 'Row-normalized')]
21 changes: 18 additions & 3 deletions conekt/templates/expression_heatmap.html
Expand Up @@ -162,9 +162,12 @@ <h1>Heatmap</h1>
<div class="row">
<div class="col-xs-12">
{{ form2.csrf_token }}
{{form2.probes(class_="form-control") }}<br />
{{form2.options(class_="form-control") }}<br />
{{form2.comparable_probes(class_="form-control") }}<br />
{{form2.comparable_options(class_="form-control") }}<br />
<div class="pull-right">
{% if example2 and example2.comparable_probes %}
<button class="btn btn-default" id="load_example2">Load example</button>
{% endif %}
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#loaderModal">Generate heatmap</button>
</div>
</div>
Expand Down Expand Up @@ -286,14 +289,26 @@ <h1>Heatmap</h1>
$(function() {
$('#load_example').click(function (ev) {
ev.preventDefault();
$('#zlog').prop('checked', true);
{% for key, value in example.items() %}
$('#{{key}}').val("{{value}}");
{% endfor %}
});
});
</script>
{% endif %}

{% if example2 and example2.comparable_probes %}
<script>
$(function() {
$('#load_example2').click(function (ev) {
ev.preventDefault();
{% for key, value in example2.items() %}
$('#{{key}}').val("{{value}}");
{% endfor %}
});
});
</script>
{% endif %}
{% endif %}

{% endblock %}

0 comments on commit e9727dd

Please sign in to comment.