#' Mutates a nucleotide according to some model
#' Takes a character and returns a character
#' @param nucleotide The input nucleotide which is to be mutated
#' @param cumulative_matrix The cumulative matrix for a transition matrix coressponding
#' to the model that we are mutating the nucleotide by
#' @param r_num A random number between 0 and 1, which is used to determine what mutation occurs
#' @return The nucleotide after the random mutation
point_mutation_nucleotide <- function(nucleotide, r_num, cumulative_matrix)
{
return(NUCLEOTIDES[1+sum(cumulative_matrix[nucleotide, ] <= r_num)])
}
#' Mutates an entire subsequence according to a given transition matrix model
#' Takes a character vector and returns a character vector
#' @param sequence A nucleic acid sequence, one that is to be mutated
#' @param cumulative_matrix The cumulative matrix for a transition matrix coressponding
#' to the model that we are mutating the nucleotide by
#' @return The mutated sequence after point mutations on the entire sequence
#' @export
point_mutation_sequence <- function(sequence, cumulative_matrix)
{
rand_list <- runif(length(sequence)) # the seed for the random mutations
return(unlist(purrr::map2(sequence, rand_list, point_mutation_nucleotide, cumulative_matrix)))
}
#' Mutates a list of sequences according to some transition matrix and timestep
#' Takes a list of character vectors and returns a list character vector
#' @param sequences A list of DNA sequences
#' @param get_transition_matrix The transition matrix coressponding to the model we are using
#' for point mutations
#' @param timestep Over what period we are mutating the sequences by
#' @return The mutated sequences
#' @export
point_mutation_sequences <- function(sequences, get_transition_matrix, timestep)
{
cumulative_matrix <- cumulate_matrix(get_transition_matrix(timestep))
return(lapply(sequences, point_mutation_sequence, cumulative_matrix))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.