R/snv_relevant_functions.R
simulate_single_nt_change.RdSimulates the specific nucleotide change for a single mutation based on genomic context, handling both regular and recurrent mutations, as well as mutations in lost segments.
simulate_single_nt_change(
single_mutation,
seg_list,
genome_sequence,
nt_transition_matrix,
recurrent = FALSE,
original_nt = NA
)Data frame row containing information about a single mutation
List structure containing segment information for genome regions
List of DNA sequences representing the reference genome
Matrix specifying nucleotide transition probabilities
Logical indicating whether this is a recurrent mutation (default: FALSE)
Character specifying the original nucleotide for recurrent mutations (required when recurrent = TRUE, default: NA)
The updated single_mutation row with additional fields:
seg_id: Segment identifier for the mutation
ref_pos: Reference position within the segment
original_nt: Original nucleotide at the mutation site
alternative_nt: Mutated nucleotide
processed: Set to TRUE indicating the mutation has been processed
This function simulates nucleotide-level details for a single mutation by:
Identifying the genomic segment containing the mutation
Determining if the segment has been lost through deletion or other structural variants
For mutations in lost segments:
Setting both original and alternative nucleotides to "N"
For mutations in non-lost segments:
For regular mutations: Looking up the original nucleotide from the reference genome and sampling an alternative nucleotide based on the transition matrix
For recurrent mutations: Using the provided original nucleotide and sampling an alternative nucleotide based on the transition matrix
The function requires the helper function get_segment_info() to map the mutation coordinates to the appropriate genomic segment.