
Add clinical or sample metadata from a data frame to a Seurat object
AddClinicalMeta.RdMatches 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.datawhose values are matched againstdf.key. Typically a donor or sample identifier such as"donor.id".- df.key
Character. Column in
dfcontaining the IDs to match. Must have unique values (one row per donor/sample).- columns
Character vector of column names in
dfto copy.NULL(default) copies every column exceptdf.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 inmeta.dataare skipped with a warning. SetTRUEto replace them.
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"))
} # }