Creates 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)

Arguments

chr_arm_table

A data frame containing chromosome arm information with columns:

  • chrom: Chromosome name

  • start: Start position

  • end: End position

  • region_name: Identifier for the chromosome arm

Value

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"

Details

The function performs the following operations:

  1. Checks and converts coordinates from 0-based to 1-based if necessary

  2. Creates two copies of the input table (maternal and paternal)

  3. Adds metadata columns for tracking segment evolution

  4. Uses dplyr for efficient data manipulation

Note

Assumes input coordinates are either 0-based or 1-based. Automatically converts 0-based coordinates to 1-based.

Examples

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)
} # }