This function generates an edge event table by combining information from an event table and a tree structure. It creates a table that summarizes events associated with each edge in the tree, including event labels and the number of events per edge.

create_edge_event_table(
  event_table,
  tree,
  anno_cols = c("haplotype_abbr", "region_name", "CN_change")
)

Arguments

event_table

A data frame containing copy number events with columns:

  • parent: Parent node ID

  • child: Child node ID

  • haplotype: Haplotype information ("maternal" or "paternal")

  • region_name: Region identifier

  • CN_change: Copy number change value

  • Additional annotation columns as specified in anno_cols

tree

A phylogenetic tree object that can be converted to an edge list using as_edgelist()

anno_cols

A character vector specifying which columns to use for creating event labels. Default is c("haplotype_abbr", "region_name", "CN_change")

Value

A data frame summarizing events for each edge in the tree. The returned data frame includes the following columns:

  • edge_name: A unique identifier for each edge, constructed as parent_child.

  • edge_label: A concatenated string of event labels for the edge, separated by newline characters.

  • n_events: The number of events associated with the edge.

Details

The function performs these steps:

  1. Converts tree to edge list format

  2. Creates abbreviated haplotype labels (M/P)

  3. Combines annotation columns into event names

  4. Groups events by edge

  5. Creates multi-line labels for edges with multiple events

  6. Orders results to match tree structure

Note

Event labels are formatted as "HAPLOTYPE:REGION:CN_CHANGE" by default. Multiple events on the same edge are separated by newlines.

Examples

if (FALSE) { # \dontrun{
events <- data.frame(
  parent = c("A", "A"),
  child = c("B", "C"),
  haplotype = c("maternal", "paternal"),
  region_name = c("chr1p", "chr2q"),
  CN_change = c(1, -1)
)
tree <- your_tree_object  # Replace with actual tree
edge_events <- create_edge_event_table(events, tree)
} # }