Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created June 4, 2019 13:54
Show Gist options
  • Save joelnitta/53786e4647ce05643df7291f2953310c to your computer and use it in GitHub Desktop.
Save joelnitta/53786e4647ce05643df7291f2953310c to your computer and use it in GitHub Desktop.
Concatenate a list of aligned genes
#' Concatenate a list of aligned genes
#'
#' @param dna_list List of matrices of class DNAbin
#'
#' @return Matrix of class DNAbin
#'
#' @examples
#' data(woodmouse)
#' gene_1 <- woodmouse[,1:100]
#' gene_2 <- woodmouse[,101:200]
#' woodmouse_genes <- list(gene_1, gene_2)
#' concatenate_genes(woodmouse_genes)
concatenate_genes <- function (dna_list) {
require(apex)
assertthat::assert_that(is.list(dna_list))
assertthat::assert_that(all(lapply(dna_list, class) == "DNAbin"),
msg = "All elements of dna_list must be of class DNAbin")
assertthat::assert_that(all(sapply(dna_list, is.matrix)),
msg = "All elements of dna_list must be matrices")
dna_multi <- new("multidna", dna_list)
apex::concatenate(dna_multi)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment