theislab / zellkonverter

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

Support access to `raw` slot #53

Closed csoneson closed 3 years ago

csoneson commented 3 years ago

(As discussed briefly in the Bioc slack). It would be cool if it was possible to include e.g. adata.raw.X as an assay in the SingleCellExperiment (e.g., when the X matrix in the retrieved AnnData object contains normalized values, but you still want that counts assay). It looks like the raw slot is not a valid AnnData object in itself, so it can't be provided directly to AnnData2SCE():

> class(res)
[1] "anndata._core.anndata.AnnData" "python.builtin.object"        

> AnnData2SCE(res$raw)
Error in py_get_attr_impl(x, name, silent) : 
  AttributeError: 'Raw' object has no attribute 'layers'

However, accessing the matrix directly works

> class(res$raw$X)
[1] "dgRMatrix"
attr(,"package")
[1] "Matrix"
lazappi commented 3 years ago

Any thoughts on where raw should go in the SingleCellExperiment? It doesn't necessarily have the same dimensions as X or layers so it can't always be stored as an assay. Maybe altExp is a better fit?

csoneson commented 3 years ago

That would make sense to me - I think the idea of the two (altExp and raw) is also similar, right? An additional "object" of more or less the same type stuck inside the main object :)

lazappi commented 3 years ago

👍🏻 Need to double check exactly what can be in raw but in theory I think that will work.

LTLA commented 3 years ago

As long as it has the same number of columns, you can stick it in an altExp.

The other option would be to store it as a seed in a subsetted DelayedArray, so you can easily get the raw matrix via seed().

lazappi commented 3 years ago

This should be working now in devel, you will just need to set raw = TRUE in readH5AD() or AnnData2SCE(). If you test it and run into any issues let us know.

csoneson commented 3 years ago

Thank you! I'll give it a try and let you know if I run into problems.