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 vector mapping layers in adata to assay names in the created SingleCellExperiment object. The names of the vector 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 can 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 vector mapping obs in adata to colData in the created SingleCellExperiment object. The names of the vector should be the names of the colData columns in the resulting SingleCellExperiment object. The values should be the names of the obs columns in adata.

rowData_mapping

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

reduction_mapping

A named vector or list mapping reduction names in adata to reduction names in the created SingleCellExperiment object. For the simpler named vector format, the names should be the names of the reducedDims in the resulting SingleCellExperiment object, and the values should be the names of the obsm in adata.

For more advanced mapping, use the list format where each item has the following keys:

  • obsm: the name of the obsm slot in adata

  • varm: the name of the varm slot in adata (optional)

  • uns: the name of the uns slot in adata (optional)

If 'varm' or 'uns' is given, a SingleCellExperiment::LinearEmbeddingMatrix will be created for that item with adata$varm[[varm]] passed to the featureLoadings argument and adata$uns[[uns]] passed as metadata

colPairs_mapping

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

rowPairs_mapping

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

metadata_mapping

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

Value

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

Details

If an unnamed vector is provided to a mapping argument the values will be used as names

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):