#' Calculates the GC content of a set of DNA sequences
#'
#' @param seq A character vector of DNA Sequences
#'
#' @return A numeric vector of GC percentages
#' @export
#'
#' @examples
#' gc_content("GATATCG")
#' gc_content(c("GATATCG","agttagtcgatgc"))
gc_content <- function(seq) {
assertthat::assert_that(is.character(seq))
seq <- base::toupper(seq)
if (any(stringr::str_detect(seq,"[^GATCN]"))) {
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.