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.activate()#

Activate conversion for supported objects.

This includes AnnData objects as well as Array objects and pandas.DataFrames via rpy2.robjects.numpy2ri and rpy2.robjects.pandas2ri.

Does nothing if this is the active converter.

Return type:

None

anndata2ri.deactivate()#

Deactivate the conversion described above if it is active.

Return type:

None

anndata2ri.py2rpy(obj)#

Convert Python objects to R interface objects.

Supports: :rtype: Sexp

anndata2ri.rpy2py(obj)#

Convert R interface objects to Python objects.

Supports: :rtype: AnnData | DataFrame

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

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.activate()#

Activate conversion between sparse matrices from Scipy and R’s Matrix package.

Does nothing if this is the active conversion.

Return type:

None

anndata2ri.scipy2ri.deactivate()#

Deactivate the conversion described above if it is active.

Return type:

None

anndata2ri.scipy2ri.py2rpy(obj)#

Convert scipy sparse matrices objects to R sparse matrices.

Supports:

Return type:

Sexp

csc_matrix (dtype in {float32, float64, bool}) →

dgCMatrix or lgCMatrix

csr_matrix (dtype in {float32, float64, bool}) →

dgRMatrix or lgRMatrix

coo_matrix (dtype in {float32, float64, bool}) →

dgTMatrix or lgTMatrix

dia_matrix (dtype in {float32, float64, bool}) →

ddiMatrix or ldiMatrix

anndata2ri.scipy2ri.rpy2py(obj)#

Convert R sparse matrices to scipy sparse matrices.

Supports:

Return type:

spmatrix

dgCMatrix, lgCMatrix, or ngCMatrix

csc_matrix (dtype float64 or bool)

dgRMatrix, lgRMatrix, or ngRMatrix

csr_matrix (dtype float64 or bool)

dgTMatrix, lgTMatrix, or ngTMatrix

coo_matrix (dtype float64 or bool)

ddiMatrix or ldiMatrix

dia_matrix (dtype float64 or bool)

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

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

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_classes(types=frozenset({'d', 'l', 'n'}), storage=frozenset({'C', 'R', 'T', 'di'}))#

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

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

Data type character(s) from supported_r_matrix_types

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

Storage mode(s) from supported_r_matrix_storage

Return type:

frozenset[str]

Returns:

All supported classes with those characters