#' make_seqs_multinom_mod
#'
#' By Coghlan (2011)
#'
#' @param inputsequence inputsequence
#' @param X X
#'
#' @export
make_seqs_multinom_mod <- function(inputsequence, X)
{
# Change the input sequence into a vector of letters
#library(seqinr) # This function requires the SeqinR package.
inputsequencevector <- seqinr::s2c(inputsequence)
# Find the frequencies of the letters in the input sequence "inputsequencevector":
mylength <- length(inputsequencevector)
mytable <- table(inputsequencevector)
# Find the names of the letters in the sequence
letters <- rownames(mytable)
numletters <- length(letters)
probabilities <- numeric() # Make a vector to store the probabilities of letters
for (i in 1:numletters)
{
letter <- letters[i]
count <- mytable[[i]]
probabilities[i] <- count/mylength
}
# Make X random sequences using the multinomial model with probabilities "probabilities"
seqs <- numeric(X)
for (j in 1:X)
{
seq <- sample(letters, mylength, replace=TRUE, prob=probabilities) # Sample with replacement
seq <- seqinr::c2s(seq)
seqs[j] <- seq
}
# Return the vector of random sequences
return(seqs)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.