R/growth_stage.R

#' Simulate cell splitting over n generations
#'
#' Takes in a gland of n cells, allow cell splitting to occur and, discard half
#' and repeat process a set number of times.
#'
#' @param gland A gland object
#' @param n number of generations
#' @param side character vector of length n with values "left" and "right"
#' denoting if the left or right side is chosen when splitting occur.
#'
#' @return a gland object
#' @export
#'
#' @examples
#' gland <- gland_create(sample(c(0, 1), 10, TRUE), n_iter = 4)
#'
#' growth_stage(gland, 30)
growth_stage <- function(gland, n, side = rep("left", n)) {
  for (i in seq_len(n)) {
    if (side[i] == "left") {
      ids <- seq_len(nrow(gland$cells) / 2)
    } else {
      ids <- seq_len(nrow(gland$cells) / 2) + nrow(gland$cells) / 2
    }
    half <- gland$cells[ids, ]
    gland$cells <- cell_split(half, gland$mutation_chance)
  }
  gland
}
EmilHvitfeldt/cell documentation built on May 5, 2019, 7:03 p.m.