Transforms cell lineage information into a format suitable for phylogenetic tree visualization by creating edge and node tables with appropriate attributes.

prepare_tree_data(cell_info)

Arguments

cell_info

Data frame containing cell lineage information with columns: clone, parent, birth_time, death_time, cell_index

Value

A list containing two data frames:

  • edges: Data frame with columns parent, child, edge_label, edge_length, and child_clone

  • nodes: Data frame with columns name, clone_type, and death_time

Details

This function processes cell lineage data to create a tree structure representation:

  1. Replaces NA parents with "root_node" to establish a common ancestor

  2. Assigns theoretical death times to living cells (cells with NA death_time)

  3. Calculates edge lengths as the time between birth and death of each cell

  4. Creates an edge table that defines connections between cells

  5. Creates a node table with information about each cell and the root

The resulting data structure is compatible with tree visualization packages such as ggtree and can be used to create cell lineage visualizations.

See also

simulate_sc_dynamics, plot_cell_tree

Examples

# Example usage:
cell_info <- data.frame(
  parent = c(NA, 1, 1, 2),
  cell_index = c(1, 2, 3, 4),
  birth_time = c(0, 1, 1, 2),
  death_time = c(5, 3, NA, 4),
  clone = c("Clone1", "Clone1", "Clone2", "Clone2")
)

tree_data <- prepare_tree_data(cell_info)
#> Warning: restarting interrupted promise evaluation
#> Warning: internal error -3 in R_decompress1
#> Error: lazy-load database '/Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/cancerSimCraft/R/cancerSimCraft.rdb' is corrupt
print(tree_data$edges)  # Edge table
#> Error: object 'tree_data' not found
print(tree_data$nodes)  # Node table
#> Error: object 'tree_data' not found