R/genome_relevant_functions.R
introduce_snv.RdIntroduce single nucleotide variants (SNVs) into a genome sequence by processing mutations grouped by haplotype and chromosome.
introduce_snv(genome, mut_table, verbose = TRUE)A nested list containing genome sequences:
First level: haplotypes (maternal/paternal)
Second level: chromosomes with nucleotide sequences
A data frame containing mutation information with columns:
haplotype - Maternal or paternal copy
chrom - Chromosome name
pos - Position where mutation occurs
alternative_nt - Alternative nucleotide to introduce
A list containing:
genome - Modified genome with introduced SNVs
The function:
Groups mutations by haplotype and chromosome for efficient processing
Processes each group of mutations in a vectorized operation
Maintains the original genome structure while updating sequences
Note: Uses vectorized operations through replaceLetterAt for efficient mutation introduction
replaceLetterAt
if (FALSE) { # \dontrun{
# Example mutation table
mutations <- data.frame(
haplotype = "maternal",
chrom = "chr1",
pos = 100,
alternative_nt = "A"
)
modified <- introduce_snv(genome, mutations)
} # }