Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor loses mainExpName and altExpNames from SCE #161

Open
LiNk-NY opened this issue Dec 9, 2024 · 0 comments
Open

constructor loses mainExpName and altExpNames from SCE #161

LiNk-NY opened this issue Dec 9, 2024 · 0 comments

Comments

@LiNk-NY
Copy link
Contributor

LiNk-NY commented Dec 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant