Skip to content

Commit

Permalink
Plot error message to screen when rendering inconsistent reconciliati…
Browse files Browse the repository at this point in the history
…on (#249)
  • Loading branch information
ssantichaivekin authored Feb 15, 2022
1 parent 28114a1 commit 8ac9be8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions empress/recon_vis/recon_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from empress.recon_vis import recon, tree, utils, plot_tools, render_settings

from typing import Union, Dict
import textwrap
import math
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -35,15 +36,16 @@ def render(host_dict: dict,
host_tree, parasite_tree, consistency_type = utils.build_trees_with_temporal_order(host_dict, parasite_dict, recon_dict)
recon_obj = utils.dict_to_reconciliation(recon_dict, event_frequencies)

# Checks to see if the trees(or reconciliation) are empty
if host_tree is None or parasite_tree is None or recon_obj is None:
return None

fig = plot_tools.FigureWrapper(render_settings.TREE_TITLE, axes)

if show_legend:
_create_legend(fig, consistency_type)

# Checks to see if the trees(or reconciliation) are empty
if host_tree is None or parasite_tree is None or recon_obj is None:
_print_inconsistent_text(fig, node_font_size)
return fig

font_size = node_font_size

root = parasite_tree.root_node
Expand All @@ -66,6 +68,24 @@ def render(host_dict: dict,

return fig

def _print_inconsistent_text(fig: plot_tools.FigureWrapper, fontsize: float):
errormsg = textwrap.dedent("""\
The reconciliation that empress is trying to plot
is temporally incosistent.
Empress employs a fast reconciliation algorithm
that sometimes produce time travels in the
reconciliation. This happens a lot with larger
trees, especially ones that do not have obvious
reconciliations. Our drawing algorithm currently
does not support drawing time travels, so you are
seeing this error message.
""")
fig.axis.text(0, 0, errormsg,
horizontalalignment="center",
verticalalignment="center"
)


def _create_legend(fig: plot_tools.FigureWrapper, consistency_type: str):
"""
Expand Down

0 comments on commit 8ac9be8

Please sign in to comment.