R/kmr_length_fasta.R

Defines functions kmr_length_fasta

Documented in kmr_length_fasta

#' kmr_length_fasta
#'
#' Get the length of a sequnce in a fasta formatted file.
#'
#' @param fasta path to a file
#'
#' @return integer length of the sequence in the file
#' @import Biostrings
#' @export
#' @family kmer_help
#'
#' @examples
#' fasta <- system.file("testdata/phix174.fasta", package = "kmerize")
#'
#' kmr_length_fasta(fasta)
kmr_length_fasta <- function(fasta = NULL) {
  msg <- "Need to provide a valid path to a fasta file."
  if (is.null(fasta)) stop(msg)
  if (!file.exists(fasta)) stop(msg)

  flen <- Biostrings::readDNAStringSet(fasta) %>% width()

  return(flen)
}
c5sire/kmerize documentation built on June 7, 2020, 9:26 p.m.