Skip to content

Instantly share code, notes, and snippets.

@joelnitta
Created June 4, 2019 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelnitta/6f30a7c0f1c83d78c76a5469e935d56f to your computer and use it in GitHub Desktop.
Save joelnitta/6f30a7c0f1c83d78c76a5469e935d56f to your computer and use it in GitHub Desktop.
convert DNAbin to DNAstring set
# Convert ape::DNAbin format to Biostrings::DNAStringSet format,
# optionally removing gaps
DNAbin_to_DNAstringset <- function (seqs, remove_gaps = TRUE) {
if(isTRUE(remove_gaps)) {
seqs %>% as.list() %>% as.character %>%
lapply(.,paste0,collapse="") %>%
lapply( function (x) gsub("-", "", x)) %>%
unlist %>% Biostrings::DNAStringSet()
} else {
seqs %>% as.list() %>% as.character %>%
lapply(.,paste0,collapse="") %>%
unlist %>% Biostrings::DNAStringSet()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment