Skip to contents

Matches a column in seurat_object@meta.data (typically a donor or sample ID) against a key column in df, then copies the requested columns onto every cell that carries the matching ID. This is the data-frame counterpart of AssignCellTypes: instead of mapping cluster IDs to labels you supply a table and columns are broadcast to all cells sharing each ID.

Usage

AddClinicalMeta(
  seurat_object,
  df,
  by,
  df.key,
  columns = NULL,
  prefix = NULL,
  overwrite = FALSE
)

Arguments

seurat_object

A Seurat object.

df

A data frame containing clinical or sample-level metadata.

by

Character. Column in seurat_object@meta.data whose values are matched against df.key. Typically a donor or sample identifier such as "donor.id".

df.key

Character. Column in df containing the IDs to match. Must have unique values (one row per donor/sample).

columns

Character vector of column names in df to copy. NULL (default) copies every column except df.key.

prefix

Character or NULL. Optional string prepended to every new column name (e.g. "clin." gives "clin.Age").

overwrite

Logical. If FALSE (default), columns that already exist in meta.data are skipped with a warning. Set TRUE to replace them.

Value

The Seurat object with the requested columns added to meta.data.

Examples

if (FALSE) { # \dontrun{
clinical <- data.frame(
  PatientID = c("P01", "P02", "P03"),
  Age       = c(52L, 67L, 44L),
  Stage     = c("II", "III", "I"),
  Histology = c("GBM", "GBM", "LGG")
)

SeuratObj <- AddClinicalMeta(SeuratObj, clinical,
                             by      = "donor.id",
                             df.key  = "PatientID",
                             columns = c("Age", "Stage", "Histology"))
} # }