calc_frequency: Calculate frequency of cell groups present in object

View source: R/calc-frequency.R

calc_frequencyR Documentation

Calculate frequency of cell groups present in object

Description

Calculate the frequency of each cell label present in the provided meta.data column. This is useful for comparing the proportion of cells belonging to different samples, cell types, clonotypes, isotypes, etc.

Usage

calc_frequency(
  input,
  data_col,
  cluster_col = NULL,
  prefix = paste0(data_col, "_"),
  return_df = FALSE,
  per_chain = FALSE,
  chain = NULL,
  chain_col = global$chain_col,
  sep = global$sep
)

Arguments

input

Single cell object or data.frame containing V(D)J data. If a data.frame is provided, the cell barcodes should be stored as row names.

data_col

meta.data column containing cell labels to use for calculating frequency. To calculate clonotype frequencies, provide the column containing clonotype IDs, to calculate isotype frequencies provide the column containing cell isotypes. By default the clonotype_id is used for calculations.

cluster_col

meta.data column containing cluster IDs to use for grouping cells when calculating clonotype abundance

prefix

Prefix to add to new columns

return_df

Return results as a data.frame. If set to FALSE, results will be added to the input object.

per_chain

If TRUE the frequency of each per-chain value will be calculated. If FALSE per-chain data will not be parsed and the values present in data_col will be used as is.

chain

Chain(s) to use for calculating frequency. Set to NULL to include all chains.

chain_col

meta.data column(s) containing chains for each cell

sep

Separator used for storing per-chain V(D)J data for each cell

Value

Single cell object or data.frame with clonotype frequencies

See Also

plot_frequency(), plot_clone_frequency()

Examples

# Calculate clonotype abundance using all cells
res <- calc_frequency(
  vdj_sce,
  data_col = "clonotype_id"
)

head(slot(res, "colData"), 1)

# Group cells based on meta.data column before calculating abundance
res <- calc_frequency(
  vdj_sce,
  data_col = "clonotype_id",
  cluster_col = "orig.ident"
)

head(slot(res, "colData"), 1)

# Add a prefix to the new columns
# this is useful if multiple abundance calculations are stored in the
# meta.data
res <- calc_frequency(
  vdj_sce,
  data_col = "clonotype_id",
  prefix = "bcr_"
)

head(slot(res, "colData"), 1)

# Return a data.frame instead of adding the results to the input object
res <- calc_frequency(
  vdj_sce,
  data_col = "clonotype_id",
  return_df = TRUE
)

head(res, 1)


rnabioco/AVIDtools documentation built on Oct. 28, 2023, 10:23 a.m.