Skip to main content

High-level description

This file contains utility functions for plotting phylogenetic trees locally using libraries like Matplotlib and Plotly. It provides functions for placing tree nodes and branches on a coordinate system, generating color strips for annotations, and creating indel heatmaps.

Code Structure

The code consists of several independent utility functions that can be used for plotting phylogenetic trees. These functions include: degrees_to_radians, polar_to_cartesian, polars_to_cartesians, place_tree, place_colorstrip, generate_random_color, get_random_indel_colors, get_indel_colors, hex_to_rgb, rgb_to_hex, and prepare_alleletable.

References

This file references the CassiopeiaTree class from cassiopeia.data and the convert_alleletable_to_lineage_profile function from cassiopeia.preprocess.utilities.

Symbols

degrees_to_radians

Description

Converts an angle from degrees to radians.

Inputs

Outputs

polar_to_cartesian

Description

Converts polar coordinates (angle and radius) to Cartesian coordinates (x and y).

Inputs

Outputs

polars_to_cartesians

Description

Converts a list of polar coordinates to a list of Cartesian coordinates.

Inputs

Outputs

place_tree

Description

Computes the coordinates of nodes and branches in a CassiopeiaTree for visualization. It supports both rectangular and polar coordinate systems and offers options for customizing the tree layout.

Inputs

Outputs

Internal Logic

The function first places the leaves of the tree, then iteratively places internal nodes based on the positions of their children. It supports both rectangular and polar coordinate systems and offers options for customizing the tree layout, such as extending branches, angling branches, and adding a synthetic root node.

place_colorstrip

Description

Computes the coordinates of boxes for a color strip annotation, which can be used to visualize categorical or continuous data alongside the tree.

Inputs

Outputs

generate_random_color

Description

Generates a random RGB color within specified ranges for each color channel.

Inputs

Outputs

get_random_indel_colors

Description

Assigns random HSV colors to each unique indel in a lineage profile.

Inputs

Outputs

get_indel_colors

Description

Maps indels to HSV colors based on their prior probabilities, with rarer indels receiving brighter colors.

Inputs

Outputs

hex_to_rgb

Description

Converts a hexadecimal color code to an RGB tuple.

Inputs

Outputs

rgb_to_hex

Description

Converts an RGB tuple to a hexadecimal color code.

Inputs

Outputs

prepare_alleletable

Description

Prepares an allele table for plotting by generating indel colors and creating a lineage profile.

Inputs

Outputs

Internal Logic

The function first converts the allele table to a lineage profile using the convert_alleletable_to_lineage_profile function. Then, it generates indel colors either randomly or based on prior probabilities, depending on whether indel_priors is provided.