Incorporates single nucleotide variants (SNVs) into a genome sequence, handling both regular mutations and recurrent mutations at the same genomic position.

introduce_snv_sc(input_genome, sc_mut_table_with_nt)

Arguments

input_genome

List containing genome sequences to be modified

sc_mut_table_with_nt

Data frame containing mutation details with columns: haplotype, chrom, pos, original_nt, alternative_nt, time

Value

A list containing the modified genome sequences with all mutations incorporated

Details

This function introduces mutations into a genome sequence with special handling for recurrent mutations (multiple mutations at the same genomic position):

  1. Identifies recurrent mutations by detecting duplicated positions across haplotype, chromosome, and position

  2. Processes non-recurrent mutations first using the insert_mutations() helper function

  3. For recurrent mutations:

    • Groups mutations by their genomic coordinates

    • For each position with multiple mutations, creates a consolidated mutation that applies the cumulative effect (using the original nucleotide from the first mutation and the alternative nucleotide from the last mutation in the timeline)

    • Applies these consolidated recurrent mutations to the genome

This approach ensures that the final genome correctly represents the cumulative effect of sequential mutations at the same position, rather than applying each mutation independently which could lead to incorrect results.