diff --git a/webapp/views/locus.py b/webapp/views/locus.py index a3e27fd94..eefa4755d 100644 --- a/webapp/views/locus.py +++ b/webapp/views/locus.py @@ -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): @@ -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]}""" - 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 diff --git a/webapp/views/utils.py b/webapp/views/utils.py index a3dca2ca7..0a94d816a 100644 --- a/webapp/views/utils.py +++ b/webapp/views/utils.py @@ -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]}""" + 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 diff --git a/webapp/views/views.py b/webapp/views/views.py index 6a5ed5026..f615e6019 100644 --- a/webapp/views/views.py +++ b/webapp/views/views.py @@ -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):