R/segment_relevant_functions.R
create_initial_seg_list.RdCreates initial genomic segments for both maternal and paternal haplotypes from a chromosome arm table. Handles coordinate system conversion (0-based to 1-based) and initializes tracking metadata for each segment.
create_initial_seg_list(chr_arm_table)A list with two elements ("maternal" and "paternal"), each containing a data frame of segments with the following columns:
All original columns from chr_arm_table
haplotype: "maternal" or "paternal"
ref_start: Reference start position
ref_end: Reference end position
ori_start: Original start position
ori_end: Original end position
copy_index: Set to 1 for initial segments
seg_id: Segment identifier (format: <region_name>_1)
CN_change: Copy number change (initialized to 0)
seg_source_edge: Set to "before_root"
seg_source_event: Set to "base"
The function performs the following operations:
Checks and converts coordinates from 0-based to 1-based if necessary
Creates two copies of the input table (maternal and paternal)
Adds metadata columns for tracking segment evolution
Uses dplyr for efficient data manipulation
Assumes input coordinates are either 0-based or 1-based. Automatically converts 0-based coordinates to 1-based.
if (FALSE) { # \dontrun{
chr_arms <- data.frame(
chrom = c("chr1", "chr1"),
start = c(0, 1000000),
end = c(1000000, 2000000),
region_name = c("chr1p", "chr1q")
)
segments <- create_initial_seg_list(chr_arms)
} # }