SpatialExperiment-combine: Combining SpatialExperiment objects

SpatialExperiment-combineR Documentation

Combining SpatialExperiment objects

Description

The SpatialExperiment class provides modified methods to combine multiple SpatialExperiment objects by column, for example from multiple samples. These methods ensure that all data fields remain synchronized when samples are added or removed.

Usage

## S4 method for signature 'SpatialExperiment'
cbind(..., deparse.level = 1)

Arguments

...

a list of SpatialExperiment objects

deparse.level

refer to ?rbind

Value

a combined SpatialExperiment object

Combining

The ... argument is assumed to contain one or more SpatialExperiment objects.

cbind(..., deparse.level=1):

Returns a SpatialExperiment where all objects in ... are combined column-wise, i.e., columns in successive objects are appended to the first object.

Each SpatialExperiment object in ... must have the same colData (with the same spatialCoords). If multiple objects use the same sample_id, the method will proceed by assigning unique sample_ids.

Additionally, the method combines imgData by row using rbind.

Refer to ?"cbind,SingleCellExperiment-method" for details on how metadata and other inherited attributes are combined in the output object.

Refer to ?cbind for the interpretation of deparse.level.

Author(s)

Dario Righelli

Examples

example(SpatialExperiment)

# merging with duplicated 'sample_id's
# will automatically assign unique identifiers
spe1 <- spe2 <- spe
spe3 <- cbind(spe1, spe2)
unique(spe3$sample_id)

# assign unique sample identifiers
spe1 <- spe2 <- spe
spe1$sample_id <- paste(spe1$sample_id, "sample1", sep = ".")
spe2$sample_id <- paste(spe2$sample_id, "sample2", sep = ".")

# combine into single object
spe <- cbind(spe1, spe2)

# view joint 'imgData'
imgData(spe)

# tabulate number of spots mapped to tissue
cd <- colData(spe)
table(
  in_tissue = cd$in_tissue, 
  sample_id = cd$sample_id)

drighelli/VisiumExperiment documentation built on June 30, 2024, 10:55 a.m.