Skip to content

Commit

Permalink
Fix PlotHeatmap view.
Browse files Browse the repository at this point in the history
  • Loading branch information
njohner committed Mar 20, 2024
1 parent 1a34ba7 commit d80e4ae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
25 changes: 2 additions & 23 deletions webapp/views/locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
format_orthogroup, format_pfam,
format_refseqid_to_ncbi, format_swissprot_entry,
format_taxid_to_ncbi, genomic_region_df_to_js,
locusx_genomic_region, my_locals, optional2status)
locusx_genomic_region, make_div, my_locals,
optional2status)


def tab_general(db, seqid):
Expand Down Expand Up @@ -606,28 +607,6 @@ def show_homology_info(self):
return self.n_homologues > 1


def make_div(figure_or_data, include_plotlyjs=False, show_link=False,
div_id=None):
from plotly import offline
div = offline.plot(
figure_or_data,
include_plotlyjs=include_plotlyjs,
show_link=show_link,
output_type="div",
)
if ".then(function ()" in div:
div = """{div.partition(".then(function ()")[0]}</script>"""
if div_id:
import re

try:
existing_id = re.findall(r'id="(.*?)"|$', div)[0]
div = div.replace(existing_id, div_id)
except IndexError:
pass
return div


def tab_lengths(n_homologues, annotations):
import plotly.figure_factory as ff

Expand Down
22 changes: 22 additions & 0 deletions webapp/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,25 @@ def genomic_region_df_to_js(df, start, end, name=None):
if name is not None:
genome_name = f"name: {to_s(name)}, "
return f"{{{genome_name} start: {start}, end: {end}, features: {features_str}}}"


def make_div(figure_or_data, include_plotlyjs=False, show_link=False,
div_id=None):
from plotly import offline
div = offline.plot(
figure_or_data,
include_plotlyjs=include_plotlyjs,
show_link=show_link,
output_type="div",
)
if ".then(function ()" in div:
div = """{div.partition(".then(function ()")[0]}</script>"""
if div_id:
import re

try:
existing_id = re.findall(r'id="(.*?)"|$', div)[0]
div = div.replace(existing_id, div_id)
except IndexError:
pass
return div
2 changes: 1 addition & 1 deletion webapp/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from views.utils import (format_cog, format_gene, format_ko, format_locus,
format_orthogroup, format_pfam,
genomic_region_df_to_js, locusx_genomic_region,
my_locals, page2title, to_s)
make_div, my_locals, page2title, to_s)


def id_generator(size=6, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):
Expand Down

0 comments on commit d80e4ae

Please sign in to comment.