-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hi,
I have a suggestion for an additional check within the SpatialFeatureExperiment constructor.
When the spatialCoords parameter is supplied (as a collection of sf polygons) - the cell order is assumed to match that of the colData and counts assay data - even if the polygons are named.
It might be good to throw an error if there are rownames in the sf polygon object, AND those names don't match the order of the ColData / counts cells. I think this is more consistent with the current SCE handling with cell names?
Or if that isn't feasible, make it explict in the doco that orders must match.
Right now, it will happily construct the object as long as the length matches, and assign centroids by the input order.
(I was building some gridded polygons, and ended up with some weird non-contiguous 'patchworked' annotations grouped by fov. I have sinced matched the order and it works).
Relevant Code
Within this part of the SpatialFeatureExperiment constructor function
https://github.com/pachterlab/SpatialFeatureExperiment/blob/main/R/SFE-class.R
# This line calculates the centroids, but strips out all rownames.
spe_coords <- st_coordinates(st_centroid(st_geometry(colGeometries[[1]])))
# Then they are immediately chucked into the SpatialExperiment object
spe <- SpatialExperiment(
assays = assays, colData = colData,
rowData = rowData, sample_id = sample_id,
spatialCoords = spe_coords,
spatialCoordsNames = NULL, ...
)
Otherwise, thanks. I'm enjoying using this packages for my spatial analyses, the whole bioconductor SE tree is nicely familiar and intuitive.
Sarah.