#' Gets pairwise distances from the sequence data of a Point mutation simulation
#' @param seq_data A data frame that contains a list of sequences for each time
#' @return A data frame with the pairwise distances between the sequences for each time step
#' @export
pairwise_distances <- function(seq_data)
{
num_jumps <- length(seq_data$time)
num_sequences <- length(seq_data$sequences[[num_jumps]])
num_seq_pairs <- (num_sequences * (num_sequences-1))/2
size <- num_seq_pairs * num_jumps
pair_data <- data.frame(time = rep(NA_integer_, size),
seq1 = rep(NA_integer_, size),
seq2 = rep(NA_integer_, size),
seq_dist = rep(NA, size))
assign_row <- function(time_index, seq_data, num_seq_pairs)
{
new_rows <- dist_to_data_frame(stringdist_ape(seq_data$sequences[[time_index]]))
assign_row_inner <- function(seq_index, new_rows, time_index)
{
row_index <- (time_index-1) * num_seq_pairs + seq_index
new_row <- list(time_index,
new_rows$seq1[seq_index], new_rows$seq2[seq_index],
new_rows$dist_1_2[seq_index])
pair_data[row_index, ] <<- new_row
}
purrr::map(1:num_seq_pairs, assign_row_inner, new_rows, time_index)
}
purrr::map(1:num_jumps, assign_row, seq_data, num_seq_pairs)
return(pair_data)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.