R/event_relevant_functions.R
create_edge_event_table.RdThis 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")
)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
A phylogenetic tree object that can be converted to an edge list using as_edgelist()
A character vector specifying which columns to use for creating event labels. Default is c("haplotype_abbr", "region_name", "CN_change")
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.
The function performs these steps:
Converts tree to edge list format
Creates abbreviated haplotype labels (M/P)
Combines annotation columns into event names
Groups events by edge
Creates multi-line labels for edges with multiple events
Orders results to match tree structure
Event labels are formatted as "HAPLOTYPE:REGION:CN_CHANGE" by default. Multiple events on the same edge are separated by newlines.