cassiopeia.pl.Tree3D#
- class cassiopeia.pl.Tree3D(tree, labels=None, offset=1.0, downscale=1.0, cmap=None, attribute_key='spatial')[source]#
Create a 3D projection of a tree onto a 2D surface.
This class provides various wrappers around Pyvista, which is used for 3D rendering.
Example
# When labels aren’t available, they can be synthetically created by # using labels_from_coordinates, as so. The tree must contain spatial # coordinates in the cell meta. labels = cas.pl.labels_from_coordinates(tree)
tree3d = cas.pl.Tree3D(tree, labels) tree3d.add_image(img) # img is a np.array with the same shape as labels tree3d.plot()
- Parameters:
- tree
CassiopeiaTree
The Cassiopeia tree to plot. The leaf names must be string-casted integers.
- labels
Optional
[ndarray
] (default:None
) Optional numpy array containing cell labels on a 2D surface. This array must contain all the cells in the tree, but as integers. In None, the labels will be generated synthetically using labels_from_coordinates.
- offset
float
(default:1.0
) Offset to give to tree and subclone shading. This option exists because in some cases if the tree and subclone shading is placed at the same height as the image, weird clipping happens.
- downscale
float
(default:1.0
) Downscale all images by this amount. This option is recommended for more responsive visualization.
- cmap
Optional
[List
[str
]] (default:None
) Colormap to use. Defaults to the Godsnot color palette, as defined at scverse/scanpy
- attribute_key
str
(default:'spatial'
) Attribute key to use as the integer labels for each leaf node. A column with the name {attribute_key}_label will be looked up in the cell meta.
- tree
Methods
- create_grid()[source]#
Helper function to create a Pyvista ImageData object with the appropriate shape.
- Return type:
ImageData
- place_nodes(root, leaves)[source]#
Place a subset of nodes in xyz coordinates.
- Only nodes in the path between root and each node in leaves are
placed.
- Parameters:
- Return type:
- Returns:
- A Numpy array of N x 3, where N is the total number of nodes in the
tree. Nodes that were not placed will have np.nan as its three coordinates. Each row is indexed to each node according to self.node_index.
- place_branches(root, coordinates)[source]#
Place a subset of branches in xyz coordinates.
Only nodes in the path between root and each node that have valid coordinates in coordinates are placed.
- Parameters:
- Return type:
- Returns:
- Dictionary of branch tuples (node1, node2) as keys and branch
coordinates as a Numpy arrays as values.
- render_node(coords, radius)[source]#
Helper function to create a Pyvista object representing a node.
- render_branch(branch_coords, radius)[source]#
Helper function to create a Pyvista object representing a branch.
- Parameters:
- coords
XYZ coordinates as a 2-dimensional Numpy array
- radius
float
Radius of tube
- Return type:
Tube
- Returns:
Pyvista object representing a branch.
- set_subclone_sigma(sigma)[source]#
Set subclone shade blur strength.
- Parameters:
- sigma
float
Blur strength
- sigma
- set_height(height)[source]#
Set the height of the tree.
The height is defined as the number of branches from the root.
- Parameters:
- height
Cutoff height as an integer
- set_node_picking(flag)[source]#
Helper function to setup node selection.
- Parameters:
- flag
bool
True to enable node selection, False otherwise.
- flag
- set_root(root)[source]#
Helper function to set the root of the tree.
- Parameters:
- root
str
Desired root node
- root
- select_node(node)[source]#
Helper function to select a node.
When a node is selected, its children nodes and branches are highlighted, including subclone shading. All other elements are dimmed out.
- Parameters:
- node
str
Selected node
- node
- update_texts()[source]#
Update displayed text.
The following text is updated. * The current root * The current time * The selected node (if one is selected)
- add_height_key_events()[source]#
Add key events such that pressing numbers from 1 through 9 controls the tree height.