Function to permutate a given input SpatialExperiment object(s) by rotating the x,y coordinates around the midrange point.
This function assumes that the input is provided as a SpatialExperiment
object or a list of SpatialExperiment objects.
When the input is a list of SpatialExperiment objects,
all SpatialExperiment objects will be rotated around a common midrange
point computed based on combined x,y coordinates.
Arguments
- input
SpatialExperimentorlist: Input data represented as aSpatialExperimentorlistofSpatialExperiment. EachSpatialExperimentis assumed to have anassayslot containing feature (genes) x observation (cells) matrix asdgCmatrixormatrixand aspatialCoordsslot containing spatial x,y coordinates of observations as matrix array. Further, x,y coordinates are assumed to be stored in column 1 and 2 ofspatialCoords, and column names ofspatialCoordsare assumed to be "x" and "y", respectively.- n_perm
integer: Number of permutations. Default = 1. This number is used to compute the angles at which the input is rotated at.- verbose
logical: Whether to display verbose output or warning. Default is FALSE.
Value
If the input was given as SpatialExperiment, the output is returned
as a list of n_perm SpatialExperiment objects. Each SpatialExperiment
object has an updated spatialCoords slot containing the spatial x,y coordinates
rotated at a corresponding angle. assay and colData slots are inherited.
Further, names() of the output indicates the angles at which the input
is rotated at. If the input was given as list of SpatialExperiment,
the output is returned as a new list of length(input) * n_perm
SpatialExperiment objects. Each SpatialExperiment object has an
updated spatialCoords slot containing the spatial x,y coordinates rotated
at a corresponding angle. assay and colData slots are inherited.
Further, names() of the output indicates the dataset names from names(input)
and the angles at which the input is rotated at.
Examples
data("merfish_mousePOA")
# create a list of 3 permutated datasets rotated at 0 (original), 120, and 240 degrees
# this output can directly be fed into rasterizeGeneExpression or rasterizeCellType
# functions to rasterize all 3 permutations at once with the same pixel coordinates
spe_list <- permutateByRotation(merfish_mousePOA, n_perm = 3)
# create a list of 5 permutated datasets rotated at 0 (original), 72, 144, 216, 288 degrees
spe_list <- permutateByRotation(merfish_mousePOA, n_perm = 5)