Simulates 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
)

Arguments

genome_sequence

A nested list containing reference genome sequences:

  • First level: haplotypes (maternal/paternal)

  • Second level: chromosomes

  • Each chromosome contains nucleotide sequence

seg_list

A nested list containing segment information for each clone and haplotype, including coordinates and copy number changes.

mutation_info

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

nt_transition_matrix

A 5x5 matrix containing nucleotide transition probabilities

tree

An igraph object representing the phylogenetic tree structure

Value

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

Details

The function processes mutations in two categories:

  1. 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

  2. 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