Skip to contents

to_SingleCellExperiment() converts an AnnData object to a SingleCellExperiment object.

Usage

to_SingleCellExperiment(
  adata,
  assays_mapping = NULL,
  colData_mapping = NULL,
  rowData_mapping = NULL,
  reduction_mapping = NULL,
  colPairs_mapping = NULL,
  rowPairs_mapping = NULL,
  metadata_mapping = NULL
)

Arguments

adata

an AnnData object, e.g., InMemoryAnnData

assays_mapping

A named list mapping layers in adata to assay names in the created SingleCellExperiment object. The names of the list should be the names of the assays in the resulting SingleCellExperiment object, and the values should be the names of the layers in adata, and should include the X matrix as well. If X is not in the list, it will be added as counts or data.

colData_mapping

a named list mapping obs in adata to colData in the created SingleCellExperiment object. The names of the list should be the names of the colData columns in the resulting SingleCellExperiment object. The values of the list should be the names of the obs columns in adata.

rowData_mapping

a named list mapping var names in adata to rowData in the created SingleCellExperiment object. The names of the list should be the names of the rowData columns in the resulting SingleCellExperiment object. The values of the list should be the names of the var columns in adata.

reduction_mapping

a named list mapping reduction names in adata to reduction names in the created SingleCellExperiment object. The names of the list should be the names of the reducedDims in the resulting SingleCellExperiment object. The values of the list should also be a named list with the following keys:

  • obsm: the name of the obsm slot in adata

  • varm: the name of the varm slot in adata

  • uns: the name of the uns slot in adata

colPairs_mapping

a named list mapping obsp names in adata to colPairs names in the created SingleCellExperiment object. The names of the list should be the names of the colPairs in the resulting SingleCellExperiment object. The values of the list should be the names of the obsp in adata.

rowPairs_mapping

a named list mapping varp names in adata to rowPairs names in the created SingleCellExperiment object. The names of the list should be the names of the rowPairs in the resulting SingleCellExperiment object. The values of the list should be the names of the varp in adata.

metadata_mapping

a named list mapping uns names in adata to metadata names in the created SingleCellExperiment object. The names of the list should be the names of the metadata in the resulting SingleCellExperiment object. The values of the list should be the names of the uns in adata.

Value

to_SingleCellExperiment() returns a SingleCellExperiment representing the content of adata.

Examples

if (interactive()) {
  ## useful when interacting with the SingleCellExperiment !
  library(SingleCellExperiment)
}
ad <- AnnData(
  X = matrix(1:5, 3L, 5L),
  layers = list(
    A = matrix(5:1, 3L, 5L),
    B = matrix(letters[1:5], 3L, 5L)
  ),
  obs = data.frame(row.names = LETTERS[1:3], cell = 1:3),
  var = data.frame(row.names = letters[1:5], gene = 1:5)
)

## construct a SingleCellExperiment from an AnnData object
sce <- to_SingleCellExperiment(ad)
sce
#> class: SingleCellExperiment 
#> dim: 5 3 
#> metadata(0):
#> assays(3): counts A B
#> rownames(5): a b c d e
#> rowData names(1): gene
#> colnames(3): A B C
#> colData names(1): cell
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):