R/generate_sets.R

Defines functions generate_sliding

Documented in generate_sliding

#' Generate list of character sets to visualize
#' @description  Generate a dataframe of start and stop values. These will determine what character sets from the total phylogenetic matrix will appear in each visualization
#' @param phy_mat Name of the phylogenetic matrix from which character sets will be sampled
#' @param start_char Integer indicating where in the data set to begin generating character sets
#' @param stop_char Integer indicating where in the data set to stop generating character sets
#' @param steps Integer indicating how many characters will be in each set
#' @return df Dataframe of slices from the original phylogenetic matrix to be visualized.
#' @importFrom utils tail head

#' @examples
#' sample_df <- generate_sliding(bears, 1, 10, 2)
#' @export

generate_sliding <- function(phy_mat, start_char, stop_char, steps){
  maximum_len <- length(phy_mat[[1]])

  starts <- seq(start_char, stop_char)
  stops <- starts + steps

  starts_name <- "starting_val"
  stops_name <- "stop_val"
  step_name <- "step_val"


  if ((tail(stops, n=1) >= maximum_len) == TRUE){
    stops <- head(stops, -1)
    starts <- head(starts, -1)
    sample_df <- data.frame(starts, stops, steps)
    names(sample_df) <- c(starts_name,stops_name, step_name)
    } else {
    sample_df <- data.frame(starts, stops, steps)
    names(sample_df) <- c(starts_name,stops_name, step_name)
  }
  return(sample_df)
}
wrightaprilm/treesiftr documentation built on July 15, 2019, 11:19 a.m.