R/check_topology.R

Defines functions check_topology

Documented in check_topology

#' Check if the topology is valid.
#'
#' Check if the argument is of the same type as a predicted topology,
#' as can be created with \link{predict_topology}.
#' Will \link{stop} if not.
#' @inheritParams default_params_doc
#' @return Nothing. Will \link{stop} with a helpful error message if
#' the topology is invalid.
#' @examples
#' if (is_pureseqtm_installed()) {
#'   fasta_filename <- get_example_filename("1bhaA.fasta")
#'   topology <- predict_topology(fasta_filename)
#'   check_topology(topology)
#' }
#' @author Richèl J.C. Bilderbeek
#' @export
check_topology <- function(topology) {
  if (!tibble::is_tibble(topology)) {
    stop("'topology' must be a tibble")
  }
  expected_names <- c("name", "topology")
  if (length(names(topology)) != length(expected_names)) {
    stop("'topology' must have the correct number of columns")
  }

  if (!all(names(topology) %in% expected_names)) {
    stop("'topology' must have columns 'name' and 'topology'")
  }
}

Try the pureseqtmr package in your browser

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

pureseqtmr documentation built on April 6, 2023, 5:20 p.m.