anndata2ri#

Converter between Python’s AnnData and R’s SingleCellExperiment.

SingleCellExperiment

AnnData

assay(d, 'X')

d.X

assay(d, 'counts')

d.layers['counts']

colData(d)

d.obs

rowData(d)

d.var

metadata(d)

d.uns

reducedDim(d, 'PCA')

d.obsm['X_pca']

reducedDim(d, 'DM')

d.obsm['X_diffmap']

anndata2ri.converter = <rpy2.robjects.conversion.Converter object>#

A Converter for anndata.

Includes rpy2.robjects.numpy2ri, rpy2.robjects.pandas2ri, and scipy2ri.

anndata2ri.set_ipython_converter(ipython=None, converter=None)#

Set the default converter for rmagic in IPython.

Parameters:
ipython InteractiveShell | None (default: None)

The IPython instance to set the converter for. If not specified, the current IPython instance is used.

converter conversion | None (default: None)

The converter to use. If not specified, converter is used.

anndata2ri.scipy2ri#

Convert scipy.sparse matrices between Python and R.

For a detailed comparison between the two languages’ sparse matrix environment, see issue #8.

Here’s an overview over the matching classes (note that dtype=float32 is also supported):

R

Python

dgCMatrix

csc_matrix(dtype=float64)

lgCMatrix/ngCMatrix

csc_matrix(dtype=bool)

dgRMatrix

csr_matrix(dtype=float64)

lgRMatrix/ngRMatrix

csr_matrix(dtype=bool)

dgTMatrix

coo_matrix(dtype=float64)

lgTMatrix/ngTMatrix

coo_matrix(dtype=bool)

ddiMatrix

dia_matrix(dtype=float64)

ldiMatrix

dia_matrix(dtype=bool)

anndata2ri.scipy2ri.converter = <rpy2.robjects.conversion.Converter object>#

The Converter for scipy.sparse.

Includes rpy2.robjects.numpy2ri.

anndata2ri.scipy2ri.supported_r_matrix_classes(types=frozenset({'d', 'l', 'n'}), storage=frozenset({'C', 'R', 'T', 'di'}))#

Get supported classes, possibly limiting data types or storage types.

Parameters:
types Iterable[Literal['d', 'l', 'n']] | Literal['d', 'l', 'n'] (default: frozenset({'n', 'l', 'd'}))

Data type character(s) from supported_r_matrix_types

storage Iterable[Literal['C', 'R', 'T', 'di']] | Literal['C', 'R', 'T', 'di'] (default: frozenset({'R', 'T', 'di', 'C'}))

Storage mode(s) from supported_r_matrix_storage

Returns:

frozenset[str] – All supported classes with those characters

anndata2ri.scipy2ri.supported_r_matrix_storage = frozenset({'C', 'R', 'T', 'di'})#

The Matrix storage types supported by this module; Column-sparse, Row-Sparse, Triplets, and DIagonal.

anndata2ri.scipy2ri.supported_r_matrix_types = frozenset({'d', 'l', 'n'})#

The Matrix data types supported by this module; Double, Logical, and patterN.