R/createRangeGate.R

Defines functions createRangeGate

Documented in createRangeGate

#' Create range gate
#'
#' Creates a range gate.
#'
#' @param experimentId The ID of the experiment to which to add the gate, or a
#'   \code{byName} expression.
#' @param xChannel The name of the channel to which the gate applies.
#' @param name The name of the gate.
#' @param x1 The first x coordinate (after the channel's scale has been applied).
#' @param x2 The second x coordinate (after the channel's scale has been applied).
#' @param y Position of the horizontal line between the vertical lines, in the
#'   range 0 to 1.
#' @param label Position of the label. Defaults to the midpoint of the gate.
#' @param gid Group ID of the gate, used for tailoring. If this is not specified,
#'   then a new Group ID will be created.
#' @param parentPopulationId ID of the parent population or a \code{byName}
#'   expression. Use \code{UNGATED} for the "ungated" population. Only used if
#'   \code{createPopulation} is \code{TRUE}.
#' @param tailoredPerFile Whether or not this gate is tailored per FCS file.
#' @param fcsFileId ID of FCS file or a \code{byName} expression, if tailored
#'   per file. Use \code{NULL} for the global gate in a tailored gate group.
#' @param locked Prevents modification of the gate via the web interface.
#' @param createPopulation Automatically create corresponding population.
#'   Specify \code{parentPopulationId} if set to \code{TRUE}.
#' @export
#' @examples
#' \dontrun{
#' createRangeGate(experimentId, "FSC-A", "my gate", 12.502, 95.102)
#' }
createRangeGate <- function(experimentId, xChannel, name,
                            x1, x2, y = 0.5,
                            label = c(mean(c(x1, x2)), y),
                            gid = generateId(),
                            parentPopulationId = NULL,
                            tailoredPerFile = FALSE, fcsFileId = NULL,
                            locked = FALSE, createPopulation = is.null(fcsFileId)) {
  body <- list(
    model = list(
      locked = jsonlite::unbox(locked),
      range = list(
        x1 = jsonlite::unbox(x1),
        x2 = jsonlite::unbox(x2),
        y = jsonlite::unbox(y)
      ),
      label = label
    ),
    xChannel = jsonlite::unbox(xChannel),
    type = jsonlite::unbox("RangeGate")
  )

  commonGateCreate(
    body, gid, experimentId, parentPopulationId,
    tailoredPerFile, fcsFileId, createPopulation,
    name = name
  )
}
primitybio/cellengine-r-toolkit documentation built on Oct. 19, 2024, 1:17 a.m.