visualization¶
Matplotlib-based visualization of phylogenetic trees.
tree_vis
¶
Species and gene tree visualization.
assign_species_colors(tree: Tree) -> dict
¶
Assign a unique color to each (extant) species in a species tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The species tree with uniquely labeled (non-loss) leaves. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the labels of the extant species as keys and the assigned colors as values. |
Source code in asymmetree/visualization/tree_vis.py
assign_gene_colors(tree: Tree, species_colors: dict | None = None) -> dict
¶
Assign a color to each (extant) gene in a gene tree according to its species.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The gene tree whose (non-loss) leaves have the 'reconc' attribute, i.e, the information to which species they belong. |
required |
species_colors
|
dict | None
|
A dictionary containing the values of the 'color' attribute appearing in the tree as keys and assigned colors as values. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the labels of the extant genes as keys and the assigned colors as values. |
Source code in asymmetree/visualization/tree_vis.py
assign_colors(species_tree: Tree, gene_tree: Tree) -> tuple[dict, dict]
¶
Assign a color to each (extant) species and gene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
species_tree
|
Tree
|
The species tree with uniquely labeled (non-loss) leaves. |
required |
gene_tree
|
Tree
|
The gene tree whose (non-loss) leaves have the 'reconc' attribute, i.e, the information to which species they belong, that furthermore appear as labels of the (non-loss) leaves in the species tree. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A |
dict
|
A |
Source code in asymmetree/visualization/tree_vis.py
visualize(tree: Tree, *, backend: Literal['matplotlib', 'plotly'] = 'matplotlib', path: str | os.PathLike | None = None, show: bool = False, edge_length_mode: Literal['attr', 'uniform', 'even', 'rank'] = 'attr', edge_length_attr: str = 'dist', layout_mode: Literal['horizontal', 'vertical', 'circular'] = 'horizontal', node_rank_mode: Literal['mean', 'first', 'last', 'node'] = 'mean', tree_style: TreeStyle | None = None, color_dict: dict | None = None, species_info: bool = False, distance_axis: bool = False, scale_symbols: float = 1.0, fontsize: str | float | int = 'medium', save_as: str | os.PathLike | None = None, **renderer_kwargs: Any) -> tuple[Figure, Axes] | PlotlyFigure
¶
Render a tree.
This function calls the plot_tree function in tralda for rendering the tree according to the
specified backend and options.
If no tree_style is provided, the default AsymmeTree style is used:
- Leaf colors are determined by the color_dict if provided.
- Node symbols are determined by the event type:
- Leaf nodes are represented by a circle with a dot inside.
- Speciation events are represented by a circle.
- Duplication events are represented by a square.
- Loss events are represented by a cap.
- Transfer events are represented by a triangle.
- Gene conversion events are represented by a star.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
Tree
|
The tree to render. |
required |
backend
|
Literal['matplotlib', 'plotly']
|
|
'matplotlib'
|
path
|
str | PathLike | None
|
If given, save the resulting figure to this path. For the matplotlib backend the
format is inferred from the file extension by
:meth: |
None
|
show
|
bool
|
If |
False
|
edge_length_mode
|
Literal['attr', 'uniform', 'even', 'rank']
|
How edge lengths are determined. See tralda documentation for details. |
'attr'
|
edge_length_attr
|
str
|
Node attribute read as edge length in |
'dist'
|
layout_mode
|
Literal['horizontal', 'vertical', 'circular']
|
Tree orientation. See tralda documentation for details. |
'horizontal'
|
node_rank_mode
|
Literal['mean', 'first', 'last', 'node']
|
How the rank of internal nodes is derived from their children. See tralda documentation for details. |
'mean'
|
tree_style
|
TreeStyle | None
|
Styling configuration. When |
None
|
color_dict
|
dict | None
|
For the default style function, a dictionary containing as values the assigned color for each label of the (non-loss) leaves. The default is None, in which case all leaves are colored white. |
None
|
species_info
|
bool
|
If True, append the reconciliation information (the 'reconc' attribute) to the label of each (non-loss) leaf for which it is available. |
False
|
distance_axis
|
bool
|
If True, show an x-axis with the accumulated edge lengths from the root.
Only supported for the matplotlib backend with |
False
|
scale_symbols
|
float
|
Adjust the size of the event type symbols. |
1.0
|
fontsize
|
str | float | int
|
Adjust the size of the text. |
'medium'
|
save_as
|
str | PathLike | None
|
Deprecated alias for |
None
|
**renderer_kwargs
|
Any
|
Additional keyword arguments forwarded to the renderer constructor
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes] | Figure
|
|
Source code in asymmetree/visualization/tree_vis.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |