Skip to contents

Converts a SingleCellExperiment::SingleCellExperiment to an anndataR::ReticulateAnnData object backed by a Python anndata.AnnData. The main matrix (X) is a scipy.sparse.csc_matrix built without densifying the data; see sce_assay_to_scipy_csc() for zero-copy semantics and lifetime caveats.

The returned object behaves as an anndataR AnnData: it can be passed to scanpy functions, written to HDF5/.h5ad, or inspected with the standard $ accessor.

Usage

sce_to_reticulate_anndata(x, assay = "counts", ...)

Arguments

x

A SingleCellExperiment::SingleCellExperiment.

assay

A single string: the assay to place in X (default "counts").

...

Additional arguments forwarded to sce_to_anndata().

Value

An anndataR::ReticulateAnnData R6 object backed by a Python anndata.AnnData.

Examples

if (FALSE) { # \dontrun{
library(SingleCellExperiment)
library(Matrix)

counts <- rsparsematrix(200, 50, density = 0.1, repr = "C")
sce <- SingleCellExperiment(assays = list(counts = counts))

rada <- sce_to_reticulate_anndata(sce)
print(rada)      # shows n_obs x n_vars

# Access the underlying Python object
py_adata <- rada$py_anndata()
cat("Shape:", reticulate::py_str(py_adata$shape), "\n")
cat("X is sparse:", reticulate::py_bool(
  reticulate::import("scipy.sparse")$issparse(py_adata$X)
), "\n")
} # }