R/get_n_taxa.R

Defines functions get_n_taxa

Documented in get_n_taxa

#' Extract the number of taxa from a file
#' @param filename name of a FASTA file
#' @return the number of taxa
#' @author Richèl J.C. Bilderbeek
#' @examples
#' check_empty_beautier_folder()
#'
#' fasta_filename <- get_beautier_path("test_output_5.fas")
#' # 5
#' get_n_taxa(fasta_filename)
#'
#' check_empty_beautier_folder()
#' @export
get_n_taxa <- function(filename) {
  check_string(filename)

  if (!file.exists(filename)) {
    stop("filename must exist.")
  }
  tryCatch(
    {
      return(length(seqinr::read.fasta(filename)))
    },
    error = function(e) {
      stop(
        "'filename' must be a valid FASTA file: ", e$message
      )
    }
  )
  invisible(filename)
}

Try the beautier package in your browser

Any scripts or data that you put into this service are public.

beautier documentation built on Nov. 2, 2023, 5:08 p.m.