R/pattern_extraction.R
generate_blueprint_cn_profiles.RdThis function generates copy number (CN) profiles for clones based on their events and a genome-wide window vector. It initializes baseline CN profiles for paternal and maternal haplotypes and updates them according to the events (e.g., copy number changes, whole genome duplications) associated with each clone. The function handles both whole chromosome events and specific region events.
generate_blueprint_cn_profiles(
clone_events,
genome_window_vector,
segment_info
)A named list of data frames, where each data frame contains events for a clone:
event_type: Type of event (e.g., "WGD" for whole genome duplication)
region_name: Region identifier or chromosome name
CN_change: Copy number change value
haplotype: "maternal" or "paternal"
A character vector of window identifiers in format "chr_start_end"
A data frame containing segment information:
region_name: Region identifier
chrom: Chromosome name
start: Start position
end: End position
A list with two elements ("maternal" and "paternal"), each containing a data frame where:
Rows represent clones
Columns represent genomic windows
Values represent copy numbers
The function processes events in these steps:
Initializes baseline copy numbers (1 for all regions)
For each clone and its events:
Handles WGD by doubling all copy numbers
Processes chromosome-wide events if region matches "chr0-9XY+"
Updates specific regions based on segment information
Applies copy number changes progressively
Maintains separate profiles for maternal and paternal haplotypes
Copy numbers cannot go below 0
WGD events affect all regions simultaneously
Chromosome-wide events are detected by regex pattern
if (FALSE) { # \dontrun{
clone_events <- list(
clone1 = data.frame(
event_type = c("CN", "WGD"),
region_name = c("chr1_p", "genome"),
CN_change = c(1, 0),
haplotype = c("maternal", "maternal")
),
clone2 = data.frame(...)
)
genome_windows <- c("chr1_0_1000000", "chr1_1000000_2000000")
segments <- data.frame(
region_name = "chr1_p",
chrom = "chr1",
start = 0,
end = 1000000
)
profiles <- generate_blueprint_cn_profiles(clone_events, genome_windows, segments)
} # }