diff --git a/conekt/controllers/heatmap.py b/conekt/controllers/heatmap.py index d93c8a7..97cff80 100644 --- a/conekt/controllers/heatmap.py +++ b/conekt/controllers/heatmap.py @@ -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 @@ -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/') diff --git a/conekt/forms/heatmap.py b/conekt/forms/heatmap.py index 4d20d3f..9dd8be9 100644 --- a/conekt/forms/heatmap.py +++ b/conekt/forms/heatmap.py @@ -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')] \ No newline at end of file diff --git a/conekt/templates/expression_heatmap.html b/conekt/templates/expression_heatmap.html index 6aeb65e..d559128 100644 --- a/conekt/templates/expression_heatmap.html +++ b/conekt/templates/expression_heatmap.html @@ -127,28 +127,55 @@

Heatmap

Creates an expression heatmap (table with shaded cells) for a selected set of genes.

-
-
Select genes
-
-
-
-
- {{ form.csrf_token }} - {{form.species_id(class_="form-control") }}
- {{form.probes(class_="form-control") }}
- {{form.options(class_="form-control") }}
-
- {% if example and example.probes %} - - {% endif %} - -
+
+
+ +
+
+
+
+
+ +
+
+ {{ form.csrf_token }} + {{form.species_id(class_="form-control") }}
+ {{form.probes(class_="form-control") }}
+ {{form.options(class_="form-control") }}
+
+ {% if example and example.probes %} + + {% endif %} + +
+
+
+ +
+
+
+
+
+
+
+ {{ form2.csrf_token }} + {{form2.probes(class_="form-control") }}
+ {{form2.options(class_="form-control") }}
+
+ +
+
+
+
- +
-
-
+
+
Help