From e9727dd7f86be8fe98eb2633a4b4b6b548ed054e Mon Sep 17 00:00:00 2001 From: sepro Date: Wed, 6 Dec 2017 10:20:46 +0100 Subject: [PATCH] example for custom heatmap --- conekt/controllers/heatmap.py | 29 ++++++++++++++++++++---- conekt/forms/heatmap.py | 6 ++--- conekt/templates/expression_heatmap.html | 21 ++++++++++++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/conekt/controllers/heatmap.py b/conekt/controllers/heatmap.py index 2e073c6..2489663 100644 --- a/conekt/controllers/heatmap.py +++ b/conekt/controllers/heatmap.py @@ -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 @@ -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 = { @@ -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() @@ -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") diff --git a/conekt/forms/heatmap.py b/conekt/forms/heatmap.py index 9dd8be9..ea54d6a 100644 --- a/conekt/forms/heatmap.py +++ b/conekt/forms/heatmap.py @@ -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')] \ No newline at end of file + self.comparable_options.choices = [('raw', 'Raw'), ('rnorm', 'Row-normalized')] diff --git a/conekt/templates/expression_heatmap.html b/conekt/templates/expression_heatmap.html index 7ed55bc..ee35f7f 100644 --- a/conekt/templates/expression_heatmap.html +++ b/conekt/templates/expression_heatmap.html @@ -162,9 +162,12 @@

Heatmap

{{ form2.csrf_token }} - {{form2.probes(class_="form-control") }}
- {{form2.options(class_="form-control") }}
+ {{form2.comparable_probes(class_="form-control") }}
+ {{form2.comparable_options(class_="form-control") }}
+ {% if example2 and example2.comparable_probes %} + + {% endif %}
@@ -286,7 +289,6 @@

Heatmap

$(function() { $('#load_example').click(function (ev) { ev.preventDefault(); - $('#zlog').prop('checked', true); {% for key, value in example.items() %} $('#{{key}}').val("{{value}}"); {% endfor %} @@ -294,6 +296,19 @@

Heatmap

}); {% endif %} + +{% if example2 and example2.comparable_probes %} + +{% endif %} {% endif %} {% endblock %} \ No newline at end of file