SpatialExperiment-methods: Methods for spatial attributes

SpatialExperiment-methodsR Documentation

Methods for spatial attributes

Description

The SpatialExperiment class provides a family of methods to get and set spatial data attributes in SpatialExperiment objects. Spatial attributes include spatialCoords, imgData, and scaleFactors, as well as methods to rotate and mirror SpatialExperiment objects and their spatial coordinates.

Usage

## S4 method for signature 'SpatialExperiment'
spatialData(x)

## S4 replacement method for signature 'SpatialExperiment,DFrame'
spatialData(x) <- value

## S4 replacement method for signature 'SpatialExperiment,NULL'
spatialData(x) <- value

## S4 method for signature 'SpatialExperiment'
spatialDataNames(x)

## S4 replacement method for signature 'SpatialExperiment,character'
spatialDataNames(x) <- value

## S4 replacement method for signature 'SpatialExperiment,NULL'
spatialDataNames(x) <- value

## S4 method for signature 'SpatialExperiment'
spatialCoords(x)

## S4 replacement method for signature 'SpatialExperiment,matrix'
spatialCoords(x) <- value

## S4 replacement method for signature 'SpatialExperiment,NULL'
spatialCoords(x) <- value

## S4 method for signature 'SpatialExperiment'
spatialCoordsNames(x)

## S4 replacement method for signature 'SpatialExperiment,character'
spatialCoordsNames(x) <- value

## S4 replacement method for signature 'SpatialExperiment,NULL'
spatialCoordsNames(x) <- value

## S4 method for signature 'SpatialExperiment'
scaleFactors(x, sample_id = TRUE, image_id = TRUE)

## S4 method for signature 'SpatialExperiment'
x$name

## S4 method for signature 'SpatialExperiment'
imgData(x)

## S4 replacement method for signature 'SpatialExperiment,DataFrame'
imgData(x) <- value

## S4 replacement method for signature 'SpatialExperiment,NULL'
imgData(x) <- value

Arguments

x

A SpatialExperiment object.

value

Replacement value for replacement methods.

sample_id

Logical value or character vector specifying sample identifier(s) for scaleFactors. Default = TRUE (all samples).

image_id

Logical value or character vector specifying image identifier(s) for scaleFactors. Default = TRUE (all images).

name

The name of the colData column to extract.

Details

Additional details for each type of data attribute are provided below.

Note: spatialData and spatialDataNames (previously used to store a subset of columns from colData) have been deprecated. All columns should be stored in either spatialCoords (numeric matrix containing spatial coordinates) or colData (all other columns). The spatialData/spatialDataNames functionality has been retained for backward compatibility but may be removed in the future.

See rotateCoords, mirrorCoords, rotateObject, or mirrorObject for details on methods to rotate and mirror SpatialExperiment objects and their spatialCoords.

Value

Return value varies depending on method, as described below.

spatialData and spatialCoords methods

spatialData(x) <- value:

The spatialData setter expects a DataFrame. If the input does not contain an in_tissue column, this will be included with a default value of 1.

spatialCoords(x):

Getter for numeric matrix of spatial coordinates.

spatialCoords(x) <- value:

Setter for numeric matrix of spatial coordinates.

spatialDataNames and spatialCoordsNames methods

spatialDataNames(x):

Returns the names of the colData associated with the spatial information, which are stored in the int_metadata.

spatialDataNames(x) <- value:

Setter to replace column names in the spatialData DataFrame.

spatialCoordsNames(x):

Returns the defined names of the spatial coordinates (e.g. c("x", "y")).

spatialCoordsNames(x) <- value:

Setter to define the names of the spatial coordinate columns.

imgData methods

imgData(x):

Getter to return the imgData DataFrame.

imgData(x) <- value:

Setter to provide a DataFrame object as imgData of the SpatialExperiment object.

Other methods

scaleFactors(x, sample_id, image_id):

Getter to return the scale factors associated with the sample_id(s) and image_id(s) provided. This is related to the stored image(s) in the SpatialExperiment imgData structure. See argument descriptions for further details.

Examples

example(SpatialExperiment)

# spatialCoords returns a numeric matrix
head(spatialCoords(spe))

# change spatial coordinate names
spatialCoordsNames(spe)
spatialCoordsNames(spe) <- c("x", "y")
head(spatialCoords(spe))

# imgData and scale factors
imgData(spe)
scaleFactors(spe)

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

drighelli/SpatialExperiment documentation built on June 30, 2024, 9:12 p.m.