calc_similarity: Calculate repertoire similarity

View source: R/calc-similarity.R

calc_similarityR Documentation

Calculate repertoire similarity

Description

Calculate repertoire similarity

Usage

calc_similarity(
  input,
  data_col,
  cluster_col,
  method = abdiv::jaccard,
  chain = NULL,
  chain_col = global$chain_col,
  prefix = NULL,
  return_mat = FALSE,
  sep = global$sep
)

Arguments

input

Object 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 values to use for calculating pairwise similarity between clusters, e.g. 'clonotype_id'

cluster_col

meta.data column containing cluster IDs to use for calculating repertoire overlap

method

Method to use for comparing clusters, possible values include:

  • 'count', count the number of clonotypes overlapping between each cluster

  • A function that takes two numeric vectors containing counts for each unique value in data_col, e.g. abdiv::jaccard()

chain

Chain to use for comparing clusters. To perform calculations using a single chain, the column passed to the data_col argument must contain per-chain data such as CDR3 sequences. Set to NULL to include all chains.

chain_col

meta.data column containing chains for each cell

prefix

Prefix to add to new columns

return_mat

Return a matrix with similarity values. If set to FALSE, results will be added to the input object.

sep

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

Value

Single cell object or data.frame with similarity values

See Also

plot_similarity(), calc_mds(), plot_mds()

Examples

# Calculate repertoire overlap
res <- calc_similarity(
  vdj_sce,
  data_col    = "clonotype_id",
  cluster_col = "orig.ident",
  method      = abdiv::jaccard
)

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

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

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

# Return a matrix instead of adding the results to the input object
calc_similarity(
  vdj_sce,
  data_col    = "clonotype_id",
  cluster_col = "orig.ident",
  return_mat  = TRUE
)


rnabioco/djvdj documentation built on Oct. 24, 2023, 7:33 p.m.