-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hi Dario, @drighelli
I am using the Xenium example dataset from 10X to generate a SpatialExperiment object. I first create a SingleCellExperiment object and then pass it to the constructor.
Below I have two SpatialExperiment constructor calls. The first call does not capture all the information from the sce object. The second call is a workaround to include this information explicitly.
The expected behavior is that the SpatialExperiment constructor provide a very similar SPE (if not identical) to the latter when provided with a SingleCellExperiment object.
Unfortunately, it seems that the mainExpName, rowData, and altExpNames (and possibly the reducedDimNames) are lost when an SCE is provided to the constructor.
I think the information should be kept as is as much as possible.
Note that as(sce, "SpatialExperiment") does a good job at keeping the information in the object.
Best regards,
Marcel
## BiocManager::install("waldronlab/XeniumIO")
suppressPackageStartupMessages({
library(XeniumIO)
library(SpatialExperiment)
})
zipfile <- paste0(
"https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenDemo/",
"Xenium_Prime_MultiCellSeg_Mouse_Ileum_tiny_outs.zip"
)
destfile <- XeniumIO:::.cache_url_file(zipfile)
outfold <- file.path(
tempdir(), tools::file_path_sans_ext(basename(zipfile))
)
if (!dir.exists(outfold))
dir.create(outfold, recursive = TRUE)
unzip(
zipfile = destfile, exdir = outfold, overwrite = FALSE
)
con <- TENxXenium(xeniumOut = outfold)
sce <- import(con@resources)
metadata <- import(con@metadata)
coldata <- import(con@colData)
SpatialExperiment(
sce,
sample_id = con@sampleId,
colData = as(coldata, "DataFrame"),
spatialCoordsNames = con@coordNames,
metadata = list(
experiment.xenium = metadata,
polygons = import(con@boundaries)
)
)
#> class: SpatialExperiment
#> dim: 8 36
#> metadata(2): experiment.xenium polygons
#> assays(1): ''
#> rownames(8): DeprecatedCodeword_0321 DeprecatedCodeword_6781 ...
#> DeprecatedCodeword_16059 DeprecatedCodeword_18533
#> rowData names(0):
#> colnames(36): aaamobki-1 aaclkaod-1 ... olbjkpjc-1 omjmdimk-1
#> colData names(13): cell_id transcript_counts ... segmentation_method
#> sample_id
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> spatialCoords names(2) : x_centroid y_centroid
#> imgData names(0):
## mainExpName and altExpNames are lost when SCE sent to constructor
SpatialExperiment(
assays = list(assay(sce)),
rowData = rowData(sce),
mainExpName = mainExpName(sce),
altExps = altExps(sce),
sample_id = con@sampleId,
colData = as(coldata, "DataFrame"),
spatialCoordsNames = con@coordNames,
metadata = list(
experiment.xenium = metadata,
polygons = import(con@boundaries)
)
)
#> class: SpatialExperiment
#> dim: 8 36
#> metadata(2): experiment.xenium polygons
#> assays(1): ''
#> rownames(8): DeprecatedCodeword_0321 DeprecatedCodeword_6781 ...
#> DeprecatedCodeword_16059 DeprecatedCodeword_18533
#> rowData names(3): ID Symbol Type
#> colnames(36): aaamobki-1 aaclkaod-1 ... olbjkpjc-1 omjmdimk-1
#> colData names(13): cell_id transcript_counts ... segmentation_method
#> sample_id
#> reducedDimNames(0):
#> mainExpName: Deprecated Codeword
#> altExpNames(5): Gene Expression Genomic Control Negative Control
#> Codeword Negative Control Probe Unassigned Codeword
#> spatialCoords names(2) : x_centroid y_centroid
#> imgData names(0):Created on 2024-12-09 with reprex v2.1.1