R/snv_relevant_functions.R
sim_clonal_mutation_nt.RdSimulates nucleotide changes for mutations in a clonal evolutionary tree, handling both regular and recurrent mutations. Takes into account chromosome segment information and possible loss events.
sim_clonal_mutation_nt(
genome_sequence,
seg_list,
mutation_info,
nt_transition_matrix,
tree
)A nested list containing reference genome sequences:
First level: haplotypes (maternal/paternal)
Second level: chromosomes
Each chromosome contains nucleotide sequence
A nested list containing segment information for each clone and haplotype, including coordinates and copy number changes.
A data frame containing mutation locations with columns:
clone - Clone name where mutation occurs
haplotype - Maternal or paternal copy
chrom - Chromosome name
pos - Position on chromosome
A 5x5 matrix containing nucleotide transition probabilities
An igraph object representing the phylogenetic tree structure
An updated mutation_info data frame with additional columns:
seg_id - Segment identifier where mutation occurs
ref_pos - Position in reference coordinates
original_nt - Original nucleotide
alternative_nt - Mutated nucleotide
The function processes mutations in two categories:
Regular mutations (first occurrence at a position):
Identifies segment containing the mutation
Handles lost segments (marked with 'N')
Samples alternative nucleotide based on transition matrix
Recurrent mutations (at previously mutated positions):
Finds previous mutation in ancestor clones
Uses previous alternative as new original nucleotide
Samples new alternative based on transition matrix