theislab / zellkonverter

Conversion between scRNA-seq objects
https://theislab.github.io/zellkonverter/
Other
149 stars 27 forks source link

SpatialExperiment with writeH5AD function #56

Closed davidecrs closed 2 years ago

davidecrs commented 3 years ago

Hi,

I know SpatialExperiment class extends the SingleCellExperiment, so I tried to use the writeH5AD function with a SpatialExperiment object. I made up the following function to get the spatialCoords in the colData.

spe_to_h5ad <- function(spe, file){
    stopifnot(all(rownames(colData(spe)) == rownames(spatialCoords(spe))))
    colData(spe) <- cbind(colData(spe), spatialCoords(spe))
    writeH5AD(spe, file)
}

spe_to_h5ad(spe, file = "spe_anndata.h5ad")

When I run the code, the console shows only the following message and completes the writing of the file on disk.

... storing 'sample_id' as categorical ... storing 'symbol' as categorical

It seems to work because I was able to load the h5ad file in python with all the information that I need, which are the count matrix and the coordinates.

I want to ask you if it is correct to use the writeH5AD function on a SpatialExperiment object, even if it should take in input a SingleCellExperiment. Also, there are no error messages.

Best regards, Davide

LTLA commented 3 years ago

It's fine, it should just slice the SPE into its SCE subset and toss away the spatial-relevant parts of the structure.

davidecrs commented 3 years ago

Hi @LTLA ,

Perfect, thank you.

Best regards, Davide

lazappi commented 3 years ago

We might think about supporting the spatial-specific parts at some stage but I'm not sure how much SpatialExperiment is used yet and there's still a lot of movement around this on the Python side.