Skip to content

TreeViz Class

TreeViz

TreeViz(
    tree_data: str | Path | Tree,
    *,
    format: str = "newick",
    outer: bool = True,
    align_leaf_label: bool = True,
    ignore_branch_length: bool = False,
    leaf_label_size: float = 12,
    leaf_label_rmargin: float = 2.0,
    reverse: bool = False,
    ladderize: bool = False,
    line_kws: dict[str, Any] | None = None,
    align_line_kws: dict[str, Any] | None = None,
    label_formatter: Callable[[str], str] | None = None,
    track: Track
)

Phylogenetic Tree Visualization Class

Interface for changing tree properties and adding tree annotations in a track

PARAMETER DESCRIPTION
tree_data

Tree data (File|File URL|Tree Object|Tree String)

TYPE: str | Path | Tree

format

Tree format (newick|phyloxml|nexus|nexml|cdao)

TYPE: str DEFAULT: 'newick'

outer

If True, plot tree on outer side. If False, plot tree on inner side.

TYPE: bool DEFAULT: True

align_leaf_label

If True, align leaf label.

TYPE: bool DEFAULT: True

ignore_branch_length

If True, ignore branch length for plotting tree.

TYPE: bool DEFAULT: False

leaf_label_size

Leaf label size

TYPE: float DEFAULT: 12

leaf_label_rmargin

Leaf label radius margin

TYPE: float DEFAULT: 2.0

reverse

If True, reverse tree

TYPE: bool DEFAULT: False

ladderize

If True, ladderize tree

TYPE: bool DEFAULT: False

line_kws

Patch properties (e.g. dict(color="red", lw=1, ls="dashed", ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

TYPE: dict[str, Any] | None DEFAULT: None

align_line_kws

Patch properties (e.g. dict(lw=1, ls="dotted", alpha=1.0, ...)) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

TYPE: dict[str, Any] | None DEFAULT: None

label_formatter

User-defined label text format function to change plot label text content. For example, if you want to change underscore of the label to space, set lambda t: t.replace("_", " ").

TYPE: Callable[[str], str] | None DEFAULT: None

track

Track for tree visualization

TYPE: Track

track property

track: Track

Track for tree visualization

tree property

tree: Tree

BioPython's Tree Object

leaf_num cached property

leaf_num: int

Leaf number

leaf_labels cached property

leaf_labels: list[str]

Leaf labels

innode_labels cached property

innode_labels: list[str]

Internal node labels

all_node_labels cached property

all_node_labels: list[str]

All node labels

max_tree_depth cached property

max_tree_depth: float

Max tree depth (root -> leaf max branch length)

name2xr cached property

name2xr: dict[str, tuple[float, float]]

Tree node name & node xr coordinate dict

name2rect cached property

name2rect: dict[str, Rectangle]

Tree node name & rectangle dict

load_tree staticmethod

load_tree(data: str | Path | Tree, format: str) -> Tree

Load tree data

PARAMETER DESCRIPTION
data

Tree data

TYPE: str | Path | Tree

format

Tree format

TYPE: str

RETURNS DESCRIPTION
tree

Tree object

TYPE: Tree

search_target_node_name

search_target_node_name(query: str | list[str] | tuple[str]) -> str

Search target node name from query

PARAMETER DESCRIPTION
query

Search query node name(s). If multiple node names are set, MRCA(Most Recent Common Ancester) node is set.

TYPE: str | list[str] | tuple[str]

RETURNS DESCRIPTION
target_node_name

Target node name

TYPE: str

get_target_xlim

get_target_xlim(query: str | list[str] | tuple[str]) -> tuple[float, float]

Get target node x limit by query

PARAMETER DESCRIPTION
query

Search query node name(s) for getting x limit. If multiple node names are set, MRCA(Most Recent Common Ancester) node is set.

TYPE: str | list[str] | tuple[str]

RETURNS DESCRIPTION
xlim

X limit tuple

TYPE: tuple[float, float]

show_confidence

show_confidence(
    *,
    size: float = 8,
    orientation: str = "vertical",
    label_formatter: Callable[[float], str] | None = None,
    **kwargs
) -> None

Show confidence value on each internal node of the phylogenetic tree

PARAMETER DESCRIPTION
size

Text size

TYPE: float DEFAULT: 8

orientation

Text orientation (horizontal or vertical)

TYPE: str DEFAULT: 'vertical'

label_formatter

User-defined function for label format.

TYPE: Callable[[float], str] | None DEFAULT: None

**kwargs

TYPE: dict DEFAULT: {}

highlight

highlight(
    query: str | list[str] | tuple[str], *, color: str, alpha: float = 0.5, **kwargs
) -> None

Plot highlight for target node

PARAMETER DESCRIPTION
query

Search query node name(s) for highlight. If multiple node names are set, MRCA(Most Recent Common Ancester) node is set.

TYPE: str | list[str] | tuple[str]

color

Highlight color

TYPE: str

alpha

Highlight color alpha(transparancy) value

TYPE: float DEFAULT: 0.5

**kwargs

Patch properties (e.g. ec="blue", lw=1.0, ...) https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html

TYPE: dict DEFAULT: {}

marker

marker(
    query: str | list[str] | tuple[str],
    *,
    marker: str = "o",
    size: int = 6,
    descendent: bool = True,
    **kwargs
) -> None

Plot marker on target node(s)

PARAMETER DESCRIPTION
query

Search query node name(s) for plotting marker. If multiple node names are set, MRCA(Most Recent Common Ancester) node is set.

TYPE: str | list[str] | tuple[str]

marker

Marker type (e.g. o, s, D, P, *, x, d, ^, v, <, >) https://matplotlib.org/stable/api/markers_api.html

TYPE: str DEFAULT: 'o'

size

Marker size

TYPE: int DEFAULT: 6

descendent

If True, plot markers on target node's descendent as well.

TYPE: bool DEFAULT: True

**kwargs

Axes.scatter properties (e.g. fc="lime", ec="black", lw=0.5, ...) https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.scatter.html

TYPE: dict DEFAULT: {}

set_node_label_props

set_node_label_props(target_node_label: str, **kwargs) -> None

Set tree node label properties

PARAMETER DESCRIPTION
target_node_label

Target node label name

TYPE: str

kwargs

Text properties (e.g. color="red", size=15, ...) https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html

TYPE: dict DEFAULT: {}

set_node_line_props

set_node_line_props(
    query: str | list[str] | tuple[str],
    *,
    descendent: bool = True,
    apply_label_color: bool = False,
    **kwargs
) -> None

Set tree node line properties

PARAMETER DESCRIPTION
query

Search query node name(s) for coloring tree node line. If multiple node names are set, MRCA(Most Recent Common Ancester) node is set.

TYPE: str | list[str] | tuple[str]

descendent

If True, set properties on target node's descendent as well.

TYPE: bool DEFAULT: True

apply_label_color

If True & descendent=True & kwargs contain color keyword, apply node line color to node label color as well.

TYPE: bool DEFAULT: False

**kwargs

Patch properties (e.g. color="blue", lw=2.0, ls="dashed", ...) https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.plot.html

TYPE: dict DEFAULT: {}