transferMetadata: Transfer Multiple Metadata Columns Between Two Seurat Objects

View source: R/Seurat.Utils.Metadata.R

transferMetadataR Documentation

Transfer Multiple Metadata Columns Between Two Seurat Objects

Description

Transfers specified metadata columns from one Seurat object to another, with options for verbose output and overwriting existing columns. Checks for cell overlap and reports percentages of matching and unique cells.

Usage

transferMetadata(
  from,
  to,
  colnames_from,
  colnames_to = colnames_from,
  overwrite = FALSE,
  plotUMAP = TRUE,
  strict = TRUE,
  verbose = TRUE,
  ...
)

Arguments

from

The source Seurat object from which metadata will be transferred.

to

The destination Seurat object to which metadata will be added.

colnames_from

Vector of names for the columns in the source object's metadata to transfer.

colnames_to

Vector of names for the columns in the destination object's metadata. Defaults to the same names as colnames_from. Must be the same length as colnames_from unless it is the same as colnames_from.

overwrite

Logical, indicating whether to overwrite the column in the destination object if it already exists. Defaults to FALSE.

plotUMAP

Logical, indicating whether to plot UMAPs of the destination object with the new identity.

strict

Logical, indicating whether to fail if the destination object have cells not found in the source object.

verbose

Logical, indicating whether to print details about the transfer, including the number and percentage of matching cells between objects, and unique cells in each object.

...

Additional arguments to be passed to transferMetadata.

Details

This function is useful for merging related data from separate Seurat objects, ensuring that relevant metadata is consistent across datasets. The function checks for the existence of the specified columns in the source object and whether the columns can be overwritten in the destination object. It also reports on cell overlap between the two objects, which can be useful for understanding the relationship between datasets.

Value

Returns the destination Seurat object (to) with the new metadata columns added.

Examples

# Assuming `object1` and `object2` are Seurat objects, and you want to transfer
# metadata columns named 'patientID' and 'treatmentGroup' from `object1` to `object2`:
object2 <- transferMetadata(
  from = object1, to = object2,
  colnames_from = c("patientID", "treatmentGroup")
)


vertesy/Seurat.utils documentation built on Dec. 4, 2024, 5:20 p.m.