#' Calculate the GC content of multiple sequences
#'
#' @param seq A vector of DNA sequence strings
#'
#' @return A numeric vector of the GC percentages
#' @export
#'
#' @examples
#' gc_content("GATATCG")
#' gc_content(c("GATATCG","agttagtcgatgc"))
gc_content <- function(seq) {
assertthat::assert_that(is.character(seq))
seq <- toupper(seq)
if (any(stringr::str_detect(seq,"[^GATC]"))) {
base::warning("Non GATC characters found in sequences")
}
stringr::str_replace_all(seq,"[^GC]","") -> just_gc
return(100*(base::nchar(just_gc)/base::nchar(seq)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.