Random_Cells_Downsample: Randomly downsample by identity

View source: R/Object_Utilities.R

Random_Cells_DownsampleR Documentation

Randomly downsample by identity

Description

Get a randomly downsampled set of cell barcodes with even numbers of cells for each identity class. Can return either as a list (1 entry per identity class) or vector of barcodes.

Usage

Random_Cells_Downsample(
  seurat_object,
  num_cells,
  group.by = NULL,
  return_list = FALSE,
  allow_lower = FALSE,
  seed = 123
)

Arguments

seurat_object

Seurat object

num_cells

number of cells per ident to use in down-sampling. This value must be less than or equal to the size of ident with fewest cells. Alternatively, can set to "min" which will use the maximum number of barcodes based on size of smallest group.

group.by

The ident to use to group cells. Default is NULL which use current active.ident. .

return_list

logical, whether or not to return the results as list instead of vector, default is FALSE.

allow_lower

logical, if number of cells in identity is lower than num_cells keep the maximum number of cells, default is FALSE. If FALSE will report error message if num_cells is too high, if TRUE will subset cells with more than num_cells to that value and those with less than num_cells will not be downsampled.

seed

random seed to use for downsampling. Default is 123.

Value

either a vector or list of cell barcodes

Examples

library(Seurat)

# return vector of barcodes
random_cells <- Random_Cells_Downsample(seurat_object = pbmc_small, num_cells = 10)
head(random_cells)

# return list
random_cells_list <- Random_Cells_Downsample(seurat_object = pbmc_small, return_list = TRUE,
num_cells = 10)
head(random_cells_list)

# return max total number of cells (setting `num_cells = "min`)
random_cells_max <- Random_Cells_Downsample(seurat_object = pbmc_small, num_cells = "min")


samuel-marsh/scCustomize documentation built on Dec. 20, 2024, 7:41 a.m.