Skip to contents

{anndataR} provides a way to convert between AnnData and Seurat objects. This vignette will provide a detailed look into the mapping between the two objects. The conversion can be done with or without extra user input as to which fields and slots of the respective objects should be converted and put into the other object. Please take into account that lossless conversion is not always possible between AnnData and Seurat objects due to differences in the object structure. Have a look at our known issues section for more information and please inspect the object before and after conversion to make sure that the conversion was successful.

We will first generate a sample dataset to work with:

ad <- generate_dataset(
  n_obs = 10L,
  n_var = 20L,
  x_type = "numeric_matrix",
  layer_types = c("integer_matrix", "numeric_rsparse"),
  obs_types = c("integer", "numeric", "factor"),
  var_types = c("character", "numeric", "logical"),
  obsm_types = c("numeric_matrix", "numeric_csparse"),
  varm_types = c("numeric_matrix", "numeric_csparse"),
  obsp_types = c("numeric_matrix", "numeric_csparse"),
  varp_types = c("integer_matrix", "numeric_matrix"),
  uns_types = c("vec_integer", "vec_character", "df_integer"),
  format = "AnnData"
)

# add PCA reduction
ad$obsm[["X_pca"]] <- matrix(1:50, 10, 5)
ad$varm[["PCs"]] <- matrix(1:100, 20, 5)

ad$obsm[["X_umap"]] <- matrix(1:20, 10, 2)

ad$obsp[["connectivities"]] <- ad$obsp[["numeric_matrix"]]
ad$obsp[["connectivities_sparse"]] <- ad$obsp[["numeric_csparse"]]

Convert AnnData objects to Seurat objects

By default, anndataR will try to guess a reasonable mapping. If you do not want this to happen, and you want nothing of that specific slot to be converted, you can pass an empty list.

We will first detail how anndataR guesses a reasonable mapping. In the section after that, we will detail how you can provide your own mappings.

Implicit mapping

Here, we showcase what happens if you do not provide any mapping information for the conversion.

seurat_obj <- as_Seurat(ad)
seurat_obj
# Error in `as_Seurat()`:
# ! `layers_mapping` must contain an item named "counts" and/or "data"
# ℹ Found names: "X", "integer_matrix", and "numeric_rsparse"

Immediately, we run in the first error: one of the layers in the AnnData object is not named counts or data, so we cannot implicitly determine which layer should be copied to the counts or data slot of the Seurat object. We can either provide our own mapping, or rename the layer in the AnnData object. In this case we will rename the layer, so we can see the rest of the implicit mapping. We will go more into detail on how to provide your own mapping in the next section.

ad$layers[["counts"]] <- ad$layers[["integer_matrix"]]
seurat_obj <- ad$as_Seurat()
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
seurat_obj
#> An object of class Seurat 
#> 20 features across 10 samples within 1 assay 
#> Active assay: RNA (20 features, 0 variable features)
#>  4 layers present: counts, integer_matrix, numeric_rsparse, X
#>  4 dimensional reductions calculated: numeric_matrix, numeric_csparse, X_pca, X_umap

In the following subsections, we detail how each of these implicit conversions work. If we explicitly don’t want to convert a certain slot, we can pass an empty list.

assay_name

An anndata object can only have one assay, while a Seurat object can have multiple assays. If you want to work with multiple assays, you can use (https://mudata.readthedocs.io/en/latest/)[MuData] objects.

The assay_name parameter will only determine what the name of the assay in the Seurat object will be. By default, this will be “RNA”.

ad$as_Seurat(
  assay_name = "Other_assay",
  object_metadata_mapping = FALSE,
  layers_mapping = c(counts = NA),
  assay_metadata_mapping = FALSE,
  reduction_mapping = FALSE,
  graph_mapping = FALSE,
  misc_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment
#> An object of class Seurat 
#> 20 features across 10 samples within 1 assay 
#> Active assay: Other_assay (20 features, 0 variable features)
#>  2 layers present: counts, X

object_metadata_mapping

Seurat allows for metadata to be stored on the object level, corresponding to cell (or observation) level metadata. This corresponds with the obs slot in the AnnData object.

If no information is provided, anndataR will try to convert the whole obs slot. You can see that Seurat adds some columns by default (orig.ident, nCount_RNA, nFeature_RNA).

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  layers_mapping = c(counts = NA),
  assay_metadata_mapping = FALSE,
  reduction_mapping = FALSE,
  graph_mapping = FALSE,
  misc_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
seurat_object[[]]
#>           orig.ident nCount_RNA nFeature_RNA integer numeric factor
#> cell1  SeuratProject        200           20       0     0.5 Value1
#> cell2  SeuratProject        600           20       1     1.5 Value2
#> cell3  SeuratProject       1000           20       2     2.5 Value1
#> cell4  SeuratProject       1400           20       3     3.5 Value2
#> cell5  SeuratProject       1800           20       4     4.5 Value1
#> cell6  SeuratProject       2200           20       5     5.5 Value2
#> cell7  SeuratProject       2600           20       6     6.5 Value1
#> cell8  SeuratProject       3000           20       7     7.5 Value2
#> cell9  SeuratProject       3400           20       8     8.5 Value1
#> cell10 SeuratProject       3800           20       9     9.5 Value2

layers_mapping and x_mapping

Seurat allows for multiple layers to be stored in the object. This corresponds with the layers slot in the AnnData object. If no mapping is provided, all layers of the AnnData object will be copied by name. The X slot will also be copied by name.

There must be a layer called counts and/or data in the final Seurat object. If no AnnData layers are named counts or data, you must provide a mapping for either counts or data in the layers_mapping argument or provide a mapping for the X slot with the x_mapping argument.

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  object_metadata_mapping = FALSE,
  assay_metadata_mapping = FALSE,
  reduction_mapping = FALSE,
  graph_mapping = FALSE,
  misc_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment
Layers(seurat_object[["RNA"]])
#> [1] "counts"          "integer_matrix"  "numeric_rsparse" "X"

assay_metadata_mapping

Besides metadata on the object level, Seurat also stores metadata on the assay level. This corresponds to gene (or variable or feature) level metadata. This corresponds with the var slot in the AnnData object.

If no information is provided, anndataR will try to convert the whole var slot.

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  object_metadata_mapping = FALSE,
  layers_mapping = c(counts = NA),
  reduction_mapping = FALSE,
  graph_mapping = FALSE,
  misc_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment
seurat_object[["RNA"]][[]]
#>        character numeric logical
#> gene1    value_0     0.5    TRUE
#> gene2    value_1     1.5    TRUE
#> gene3    value_2     2.5   FALSE
#> gene4    value_3     3.5    TRUE
#> gene5    value_4     4.5    TRUE
#> gene6    value_5     5.5   FALSE
#> gene7    value_6     6.5    TRUE
#> gene8    value_7     7.5    TRUE
#> gene9    value_8     8.5    TRUE
#> gene10   value_9     9.5   FALSE
#> gene11  value_10    10.5   FALSE
#> gene12  value_11    11.5    TRUE
#> gene13  value_12    12.5    TRUE
#> gene14  value_13    13.5    TRUE
#> gene15  value_14    14.5    TRUE
#> gene16  value_15    15.5   FALSE
#> gene17  value_16    16.5    TRUE
#> gene18  value_17    17.5    TRUE
#> gene19  value_18    18.5   FALSE
#> gene20  value_19    19.5   FALSE

reduction_mapping

Reductions are a bit more complicated. Some reductions have a standard way of being saved in an AnnData object, some don’t. We assume that a PCA will always be stored as X_pca in the obsm slot, with the loadings as PCs in the varm slot. For other reductions, we will assume that they will start with X_ in the obsm slot, with the characters after the X_ being the name of the reduction. Elements in the obsm slot not starting with X_ will not be converted.

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  object_metadata_mapping = c(),
  layers_mapping = c(counts = NA),
  assay_metadata_mapping = c(),
  graph_mapping = c(),
  misc_mapping = c()
)
#> Warning: The `object_metadata_mapping` argument is empty, setting it to
#> FALSE
#> Warning: The `assay_metadata_mapping` argument is empty, setting it to
#> FALSE
#> Warning: The `graph_mapping` argument is empty, setting it to
#> FALSE
#> Warning: The `misc_mapping` argument is empty, setting it to
#> FALSE
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment
Reductions(seurat_object)
#> [1] "numeric_matrix"  "numeric_csparse" "X_pca"           "X_umap"

graph_mapping

Graphs of cells are stored in the obsp slot in the AnnData object. If a graph is stored with the name connectivities, we will store it as nn in the Seurat object. Graphs starting with connectivities_{name} will be stored as name in the Seurat object. Other graphs will not be converted.

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  object_metadata_mapping = FALSE,
  layers_mapping = c(counts = NA),
  assay_metadata_mapping = FALSE,
  reduction_mapping = FALSE,
  misc_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment

Graphs(seurat_object)
#> [1] "RNA_numeric_matrix"        "RNA_numeric_csparse"      
#> [3] "RNA_connectivities"        "RNA_connectivities_sparse"

misc_mapping

The misc slot in the Seurat object is used to store any other information that does not fit in the other slots. By default, it will copy the uns slot from the AnnData object.

seurat_object <- ad$as_Seurat(
  assay_name = "RNA",
  object_metadata_mapping = FALSE,
  layers_mapping = c(counts = NA),
  assay_metadata_mapping = FALSE,
  reduction_mapping = FALSE,
  graph_mapping = FALSE
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: [[<- defined for objects of type "S4" only for subclasses of
#> environment
Misc(seurat_object)
#> $vec_integer
#>  [1] 0 1 2 3 4 5 6 7 8 9
#> 
#> $vec_character
#>  [1] "value_0" "value_1" "value_2" "value_3" "value_4" "value_5" "value_6"
#>  [8] "value_7" "value_8" "value_9"
#> 
#> $df_integer
#> $df_integer$integer
#>  [1] 0 1 2 3 4 5 6 7 8 9

Explicit mapping

assay_name

As stated in the section on implicit mapping, an anndata object can only have one assay, while a Seurat object can have multiple assays. The name you pass here will only determine what the assay is called in the Seurat object. By default, it is “RNA”.

seurat_obj <- ad$as_Seurat(
  assay_name = "Other_assay"
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
Assays(seurat_obj)
#> [1] "Other_assay"

layers_mapping and x_mapping

We can explicitly provide a layers mapping. The names of the named list refer to what the layer will be called in the Seurat object. The values refer to what the layers are called in the anndata object. A value of NA refers to the X slot of the AnnData object.

You can also explicitly provide a mapping for the X slot of the AnnData object, but then you must not provide a mapping for the slot in layers_mapping.

You must provide at least a layer called counts or data in the mapping.

seurat_obj <- ad$as_Seurat(
  x_mapping = "counts",
  layers_mapping = c(layer1 = "integer_matrix", other_layer2 = "numeric_rsparse")
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
Layers(seurat_obj, assay = "RNA")
#> [1] "counts"       "layer1"       "other_layer2"

object_metadata_mapping

You can provide a mapping for object-level metadata in Seurat, which corresponds to cell-level metadata, and thus with the obs slot in the AnnData object.

The names of the named list refer to what the metadata will be called in the Seurat object. The values refer to what the columns are called in the obs slot of the anndata object.

seurat_obj <- ad$as_Seurat(
  object_metadata_mapping = c(metadata1 = "integer", metadata2 = "numeric")
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
seurat_obj[[]]
#>           orig.ident nCount_RNA nFeature_RNA metadata1 metadata2
#> cell1  SeuratProject        190           19         0       0.5
#> cell2  SeuratProject        590           20         1       1.5
#> cell3  SeuratProject        990           20         2       2.5
#> cell4  SeuratProject       1390           20         3       3.5
#> cell5  SeuratProject       1790           20         4       4.5
#> cell6  SeuratProject       2190           20         5       5.5
#> cell7  SeuratProject       2590           20         6       6.5
#> cell8  SeuratProject       2990           20         7       7.5
#> cell9  SeuratProject       3390           20         8       8.5
#> cell10 SeuratProject       3790           20         9       9.5

assay_metadata_mapping

You can provide a mapping for assay-level metadata, which corresponds to gene-level metadata, and with the var slot in the AnnData object.

The names of the named list refer to what the metadata will be called in the Seurat object. The values refer to what the metadata is called in the var slot of the anndata object.

seurat_obj <- ad$as_Seurat(
  assay_metadata_mapping = c(metadata1 = "numeric", metadata2 = "logical")
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
seurat_obj[["RNA"]][[]]
#>        metadata1 metadata2
#> gene1        0.5      TRUE
#> gene2        1.5      TRUE
#> gene3        2.5     FALSE
#> gene4        3.5      TRUE
#> gene5        4.5      TRUE
#> gene6        5.5     FALSE
#> gene7        6.5      TRUE
#> gene8        7.5      TRUE
#> gene9        8.5      TRUE
#> gene10       9.5     FALSE
#> gene11      10.5     FALSE
#> gene12      11.5      TRUE
#> gene13      12.5      TRUE
#> gene14      13.5      TRUE
#> gene15      14.5      TRUE
#> gene16      15.5     FALSE
#> gene17      16.5      TRUE
#> gene18      17.5      TRUE
#> gene19      18.5     FALSE
#> gene20      19.5     FALSE

reduction_mapping

You can provide a mapping for the reductions slot. The names of the named list refer to what the reduction will be called. The values must be a named list, containing the keys: key, obsm and maybe varm, if appropriate for the reduction.

seurat_obj <- ad$as_Seurat(
  reduction_mapping = list(
    pca = c(key = "PC", embeddings = "X_pca", loadings = "PCs"),
    umap = c(key = "UMAP", embeddings = "X_umap")
  )
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> Warning: Key "PC" does not match the expected pattern, it has
#> been replaced with "PC_"
#> Warning: Key "UMAP" does not match the expected pattern, it has been replaced with
#> "UMAP_"
Reductions(seurat_obj)
#> [1] "pca"  "umap"

graph_mapping

You can provide a mapping for the graph slot. The names of the named list refer to what the graph will be called in the Seurat object. The values refer to names in the obsp slot of the anndata object. stored in the obsp slot.

seurat_obj <- ad$as_Seurat(
  graph_mapping = c(connectivities = "numeric_matrix", connectivities_sparse = "numeric_csparse")
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
Graphs(seurat_obj)
#> [1] "RNA_connectivities"        "RNA_connectivities_sparse"

misc_mapping

You must provide a named list.

Names of the list correspond to the name the item will be assigned to in the misc of the Seurat object. Items can be a vector with two elements. The first is the name of a slot in the AnnData object (e.g. X, layers, obs, var, obsm, varm, obsp, varp, uns) and the second is the name of the item to transfer from that slot.

seurat_obj <- ad$as_Seurat(
  misc_mapping = c(uns_vec = "vec_integer")
)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
Misc(seurat_obj)
#> $uns_vec
#>  [1] 0 1 2 3 4 5 6 7 8 9

Convert Seurat objects to AnnData objects

Implicit mapping

The reverse, converting Seurat objects to AnnData objects, works in a similar way. There is an implicit conversion, where we attempt a standard conversion, but the user can always provide an explicit mapping.

suppressWarnings({
  counts <- matrix(rbinom(600, 20000, .001), nrow = 20)
  obj <- CreateSeuratObject(counts = counts) |>
    NormalizeData() |>
    FindVariableFeatures() |>
    ScaleData() |>
    RunPCA(npcs = 10L) |>
    FindNeighbors() |>
    RunUMAP(dims = 1:10)
  obj@misc[["data"]] <- "some data"
})
#> Normalizing layer: counts
#> Finding variable features for layer counts
#> Centering and scaling data matrix
#> PC_ 1 
#> Positive:  Feature9, Feature16, Feature12, Feature7, Feature11, Feature8, Feature3, Feature19, Feature20, Feature15 
#> Negative:  Feature5, Feature10, Feature13, Feature4, Feature14, Feature18, Feature6, Feature2, Feature17, Feature1 
#> PC_ 2 
#> Positive:  Feature20, Feature14, Feature18, Feature6, Feature13, Feature19, Feature7, Feature1, Feature4, Feature8 
#> Negative:  Feature17, Feature5, Feature2, Feature10, Feature12, Feature9, Feature3, Feature15, Feature11, Feature16 
#> PC_ 3 
#> Positive:  Feature20, Feature15, Feature1, Feature2, Feature9, Feature4, Feature14, Feature13, Feature12, Feature5 
#> Negative:  Feature6, Feature17, Feature16, Feature18, Feature19, Feature8, Feature11, Feature10, Feature7, Feature3 
#> PC_ 4 
#> Positive:  Feature1, Feature11, Feature18, Feature5, Feature16, Feature3, Feature9, Feature10, Feature4, Feature6 
#> Negative:  Feature19, Feature12, Feature2, Feature15, Feature13, Feature14, Feature7, Feature20, Feature8, Feature17 
#> PC_ 5 
#> Positive:  Feature7, Feature18, Feature10, Feature8, Feature6, Feature15, Feature20, Feature2, Feature5, Feature12 
#> Negative:  Feature16, Feature14, Feature3, Feature4, Feature13, Feature17, Feature19, Feature9, Feature1, Feature11
#> Computing nearest neighbor graph
#> Computing SNN
#> 14:48:10 UMAP embedding parameters a = 0.9922 b = 1.112
#> 14:48:10 Read 30 rows and found 10 numeric columns
#> 14:48:10 Using Annoy for neighbor search, n_neighbors = 30
#> 14:48:10 Building Annoy index with metric = cosine, n_trees = 50
#> 14:48:10 Writing NN index file to temp file /tmp/RtmpvKbVII/file210f3dd48b8a
#> 14:48:10 Searching Annoy index using 1 thread, search_k = 3000
#> 14:48:10 Annoy recall = 100%
#> 14:48:10 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30
#> 14:48:10 Initializing from normalized Laplacian + noise (using RSpectra)
#> 14:48:10 Commencing optimization for 500 epochs, with 866 positive edges
#> 14:48:10 Using rng type: pcg
#> 14:48:11 Optimization finished
ad <- as_AnnData(obj)
ad
#> AnnData object with n_obs × n_vars = 30 × 20
#>     obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA'
#>     var: 'vf_vst_counts_mean', 'vf_vst_counts_variance', 'vf_vst_counts_variance.expected', 'vf_vst_counts_variance.standardized', 'vf_vst_counts_variable', 'vf_vst_counts_rank', 'var.features', 'var.features.rank'
#>     uns: 'data'
#>     obsm: 'pca', 'umap'
#>     varm: 'pca'
#>     layers: 'counts', 'data', 'scale.data'
#>     obsp: 'nn', 'snn'

assay_name

The assay_name argument determines which assay in the Seurat object will be converted to the AnnData object. By default it’s the DefaultAssay.

ad <- as_AnnData(
  obj,
  assay_name = NULL,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)
ad
#> AnnData object with n_obs × n_vars = 30 × 20

x_mapping

By default, no data will be put into the X slot of the AnnData object. If you want to put the data from a Seurat layer, such as counts or data into the X slot, you need to provide a mapping.

ad <- as_AnnData(
  obj,
  assay_name = "RNA",
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)
ad$X
#> NULL

As you can see, by default, no information was copied to the X slot of the AnnData object.

layers_mapping

By default, all layers in the Seurat object will be copied to the AnnData object. This means that the X slot will be NULL (empty).

ad <- as_AnnData(
  obj,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)

names(ad$layers)
#> [1] "counts"     "data"       "scale.data"

obs_mapping

The obs slot is used to store observation-level annotations, such as cell-level metadata. By default, all information in the meta.data slot of the Seurat object is copied to the obs slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)
names(ad$obs)
#> [1] "orig.ident"   "nCount_RNA"   "nFeature_RNA"

var_mapping

The var slot is used to store feature-level annotations, such as gene-level metadata. By default, all information in the meta.data slot of the specified assay of the Seurat object is copied to the var slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)
names(ad$var)
#> [1] "vf_vst_counts_mean"                  "vf_vst_counts_variance"             
#> [3] "vf_vst_counts_variance.expected"     "vf_vst_counts_variance.standardized"
#> [5] "vf_vst_counts_variable"              "vf_vst_counts_rank"                 
#> [7] "var.features"                        "var.features.rank"

obsm_mapping

The obsm slot is used to store multidimensional observation-level annotations, such as dimensionality reductions. By default, it will prefix the name of all Seurat reductions with X_.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)

ad
#> AnnData object with n_obs × n_vars = 30 × 20
#>     obsm: 'pca', 'umap'

varm_mapping

The varm slot is used to store multidimensional feature-level annotations. This is mainly used to store the loadings of dimensionality reductions. By default, all loadings of dimensionality reductions will be copied to the varm slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)

ad$varm
#> $pca
#>                  PC_1          PC_2        PC_3         PC_4        PC_5
#> Feature18 -0.13831405  0.2767499642 -0.18981101  0.278821809  0.34196588
#> Feature17 -0.10834698 -0.3804030540 -0.24032844 -0.064070764 -0.17170085
#> Feature14 -0.15627834  0.3034044214  0.06530596 -0.144152586 -0.32844046
#> Feature3   0.15764252 -0.1162431507 -0.04744793  0.139893986 -0.30691496
#> Feature15  0.05045854 -0.1072529329  0.38139961 -0.195353986  0.14923124
#> Feature7   0.25218664  0.1240325760 -0.09144553 -0.125089084  0.41985641
#> Feature4  -0.22938433  0.0370365899  0.07852043 -0.002001820 -0.26576167
#> Feature19  0.15139047  0.1348308437 -0.18206269 -0.479826978 -0.13795130
#> Feature5  -0.34342780 -0.3477769469 -0.03297579  0.160597461  0.07568737
#> Feature9   0.39284874 -0.1830116862  0.14195954  0.099254569 -0.04051406
#> Feature16  0.27362919 -0.0039496948 -0.22978114  0.155476787 -0.32875388
#> Feature1  -0.01759120  0.1093275548  0.37448492  0.496695065 -0.01852973
#> Feature13 -0.33043607  0.1682668256  0.05526881 -0.152405805 -0.25372228
#> Feature12  0.26834743 -0.2581323495  0.01341079 -0.238498081  0.03881268
#> Feature20  0.06671006  0.3349320426  0.41707863 -0.102652271  0.13474095
#> Feature6  -0.12171196  0.2684223148 -0.43927692 -0.053600650  0.16691063
#> Feature8   0.19855343 -0.0004220781 -0.14176054 -0.081425721  0.18874362
#> Feature10 -0.34179754 -0.2780674784 -0.11692348  0.009108192  0.28575729
#> Feature2  -0.11234940 -0.3165458928  0.26964796 -0.237330461  0.13450575
#> Feature11  0.24776342 -0.0599055745 -0.12509563  0.361489108 -0.01541830
#>                  PC_6          PC_7        PC_8        PC_9        PC_10
#> Feature18 -0.16859923 -0.0003196258  0.13557196 -0.20850811 -0.078249672
#> Feature17  0.12360865  0.3243412347  0.29115317  0.09737236  0.218317533
#> Feature14  0.32489077 -0.0775743493  0.34960557  0.02511713 -0.109834247
#> Feature3  -0.49281098 -0.0567146114  0.15504528  0.32171700  0.096111906
#> Feature15 -0.19771053 -0.4934235703  0.08337324  0.07177542  0.047690520
#> Feature7  -0.27962542  0.0386900269  0.07478509  0.04919212  0.360484375
#> Feature4   0.10000348 -0.2851749185 -0.52983733 -0.31519721  0.220494051
#> Feature19  0.13409650 -0.1864409901  0.26582844 -0.13241259 -0.105127038
#> Feature5   0.10537738 -0.2430641242  0.11323787  0.01729967  0.353432577
#> Feature9   0.06641673  0.1642535677  0.13833729 -0.35434019 -0.190479902
#> Feature16 -0.14582993  0.1303530973 -0.30353213  0.04738605 -0.204092041
#> Feature1   0.12597564  0.1417361468  0.22306140 -0.16934857  0.006865963
#> Feature13 -0.36741070  0.2723746310 -0.18765699  0.02986721  0.078554847
#> Feature12 -0.08661746  0.0085682077 -0.14846077 -0.49119771  0.038759898
#> Feature20  0.06247438  0.2575885883 -0.17833660  0.19576048  0.021230901
#> Feature6  -0.02830741 -0.1616626843 -0.02939449  0.02523821 -0.235475781
#> Feature8   0.47479004  0.2098959640 -0.27516176  0.26457497  0.310693093
#> Feature10 -0.02415249  0.1700874841 -0.11415443 -0.12969858 -0.364006269
#> Feature2   0.01567334  0.0445840936 -0.08510780  0.34093794 -0.451467316
#> Feature11  0.19108163 -0.3995713752 -0.16398252  0.27836851 -0.183566125

obsp_mapping

The obsp slot is used to store pairwise relations between observations. This is mainly used to store the connectivities of a graph. By default, all Seurat graphs are copied to the obsp slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  varp_mapping = FALSE,
  uns_mapping = FALSE
)
ad$obsp
#> $nn
#> 30 x 30 sparse Matrix of class "dgCMatrix"
#>   [[ suppressing 30 column names 'Cell_1', 'Cell_2', 'Cell_3' ... ]]
#>                                                                    
#> Cell_1  1 1 1 1 . 1 1 1 . 1 1 1 . 1 . . 1 . . . 1 . 1 1 1 1 1 1 1 .
#> Cell_2  . 1 1 1 1 1 1 . 1 1 1 1 . 1 . . 1 1 1 . 1 . 1 1 1 . 1 . 1 .
#> Cell_3  1 1 1 . 1 1 . . . 1 1 1 1 1 . . 1 . 1 1 1 . 1 1 1 1 1 . 1 .
#> Cell_4  1 1 . 1 . 1 1 1 . . 1 1 . 1 1 . 1 1 1 . . . 1 1 1 1 1 1 1 .
#> Cell_5  . 1 1 . 1 . 1 . 1 . 1 1 1 1 1 . 1 . 1 1 1 . 1 1 1 1 1 1 . .
#> Cell_6  . 1 1 1 . 1 . 1 . 1 1 1 . 1 1 . . . 1 1 1 . 1 1 1 1 1 1 1 .
#> Cell_7  1 1 1 1 1 . 1 . . 1 1 1 . 1 1 . 1 1 1 . . 1 1 1 . 1 1 . 1 .
#> Cell_8  1 1 . 1 . 1 . 1 1 . 1 1 . . 1 . . 1 1 1 1 . 1 . 1 1 1 1 1 1
#> Cell_9  . 1 . 1 . . . 1 1 . 1 1 1 . 1 . 1 1 . 1 1 1 1 1 1 . 1 1 1 1
#> Cell_10 1 1 1 1 . 1 1 . . 1 1 1 . 1 . 1 . . 1 . 1 . 1 1 1 1 1 1 1 .
#> Cell_11 1 1 1 1 . 1 . . 1 1 1 1 1 1 1 . . . 1 . 1 . 1 1 1 . 1 1 1 .
#> Cell_12 1 1 1 . . 1 1 . . . . 1 . 1 . 1 1 1 1 1 1 1 1 1 1 1 1 . 1 .
#> Cell_13 . 1 1 . 1 1 . . 1 . 1 1 1 . 1 . 1 1 1 1 1 . 1 1 1 . 1 1 1 .
#> Cell_14 . 1 1 1 . 1 1 . . 1 1 1 . 1 . . 1 1 1 1 . . 1 1 1 1 1 . 1 1
#> Cell_15 . 1 . 1 1 1 . . 1 . 1 . . . 1 1 1 1 1 1 1 1 . 1 1 1 1 1 1 .
#> Cell_16 . 1 1 . . 1 . . 1 1 1 1 . 1 1 1 1 . 1 1 1 1 . 1 . 1 1 . 1 1
#> Cell_17 . 1 1 . . . . . 1 . 1 1 1 1 1 . 1 1 . 1 1 1 1 1 1 . 1 1 1 1
#> Cell_18 . 1 1 1 . . 1 1 1 . 1 1 1 1 1 . 1 1 1 1 . . 1 1 1 . 1 . 1 .
#> Cell_19 . 1 1 1 . 1 1 . . . 1 1 . . 1 1 . 1 1 1 . 1 1 1 1 1 1 1 1 .
#> Cell_20 . 1 1 . 1 1 . . . . . 1 1 1 1 1 1 . 1 1 . 1 . 1 1 1 1 1 1 1
#> Cell_21 1 1 1 . . 1 . . 1 . 1 1 1 . 1 1 1 . 1 . 1 1 1 1 1 . 1 1 1 .
#> Cell_22 . 1 1 . . 1 1 . 1 . 1 1 . . 1 1 1 . 1 1 1 1 1 . 1 1 1 1 1 .
#> Cell_23 1 1 1 1 . 1 1 . . 1 1 1 . 1 . . . 1 1 . 1 . 1 1 1 1 1 1 1 .
#> Cell_24 . 1 1 . . 1 . . . 1 1 1 1 1 1 . 1 1 1 1 1 . 1 1 1 . 1 1 1 .
#> Cell_25 . 1 . 1 . 1 . . 1 . 1 1 1 1 . . 1 . 1 1 1 . 1 1 1 1 1 1 1 1
#> Cell_26 . 1 1 1 1 1 1 1 . . . 1 . 1 1 . . 1 1 1 . 1 1 . 1 1 1 1 1 .
#> Cell_27 . 1 1 1 . 1 1 . . . 1 1 . 1 1 . 1 1 1 1 1 . 1 1 1 . 1 1 1 .
#> Cell_28 . 1 . 1 . 1 . . 1 . 1 1 1 . 1 . 1 . 1 1 1 1 1 1 1 1 1 1 1 .
#> Cell_29 1 1 1 1 . 1 1 . 1 . 1 1 1 1 . . 1 1 1 . 1 . 1 1 1 . 1 . 1 .
#> Cell_30 . 1 . 1 . 1 . 1 1 . 1 1 . 1 1 1 1 1 . 1 1 1 . 1 1 . 1 . 1 1
#> 
#> $snn
#> 30 x 30 sparse Matrix of class "dgCMatrix"
#>   [[ suppressing 30 column names 'Cell_1', 'Cell_2', 'Cell_3' ... ]]
#>                                                                              
#> Cell_1  1.0000000 0.6666667 0.6666667 0.7391304 0.5384615 0.7391304 0.6000000
#> Cell_2  0.6666667 1.0000000 0.6666667 0.6000000 0.6000000 0.6000000 0.6666667
#> Cell_3  0.6666667 0.6666667 1.0000000 0.5384615 0.6666667 0.6666667 0.6000000
#> Cell_4  0.7391304 0.6000000 0.5384615 1.0000000 0.5384615 0.6666667 0.6666667
#> Cell_5  0.5384615 0.6000000 0.6666667 0.5384615 1.0000000 0.6000000 0.5384615
#> Cell_6  0.7391304 0.6000000 0.6666667 0.6666667 0.6000000 1.0000000 0.5384615
#> Cell_7  0.6000000 0.6666667 0.6000000 0.6666667 0.5384615 0.5384615 1.0000000
#> Cell_8  0.5384615 0.4814815 0.4814815 0.6666667 0.4814815 0.6666667 0.4285714
#> Cell_9  0.4814815 0.4814815 0.4285714 0.5384615 0.5384615 0.5384615 0.4285714
#> Cell_10 0.8181818 0.6666667 0.6666667 0.6666667 0.5384615 0.7391304 0.6000000
#> Cell_11 0.6666667 0.6666667 0.6666667 0.6000000 0.6000000 0.7391304 0.5384615
#> Cell_12 0.6000000 0.6000000 0.6666667 0.6000000 0.5384615 0.5384615 0.6000000
#> Cell_13 0.4814815 0.6666667 0.6666667 0.5384615 0.7391304 0.6000000 0.4814815
#> Cell_14 0.6666667 0.7391304 0.6666667 0.6666667 0.5384615 0.6666667 0.6666667
#> Cell_15 0.4285714 0.5384615 0.4814815 0.5384615 0.5384615 0.5384615 0.4814815
#> Cell_16 0.4814815 0.5384615 0.6000000 0.4285714 0.5384615 0.6000000 0.5384615
#> Cell_17 0.4814815 0.5384615 0.5384615 0.4814815 0.6666667 0.5384615 0.4814815
#> Cell_18 0.5384615 0.6666667 0.5384615 0.6666667 0.6666667 0.6000000 0.6000000
#> Cell_19 0.5384615 0.5384615 0.4814815 0.6666667 0.5384615 0.6666667 0.6000000
#> Cell_20 0.4285714 0.4285714 0.6000000 0.4814815 0.6000000 0.5384615 0.4814815
#> Cell_21 0.5384615 0.5384615 0.6000000 0.5384615 0.6000000 0.5384615 0.4814815
#> Cell_22 0.5384615 0.5384615 0.5384615 0.5384615 0.6666667 0.6000000 0.4814815
#> Cell_23 0.8181818 0.7391304 0.6666667 0.7391304 0.5384615 0.7391304 0.6666667
#> Cell_24 0.6000000 0.6666667 0.7391304 0.6000000 0.6666667 0.7391304 0.5384615
#> Cell_25 0.6000000 0.6000000 0.6666667 0.6000000 0.6666667 0.6666667 0.4285714
#> Cell_26 0.5384615 0.5384615 0.4814815 0.6666667 0.5384615 0.6666667 0.6000000
#> Cell_27 0.6666667 0.7391304 0.6000000 0.7391304 0.6666667 0.7391304 0.6000000
#> Cell_28 0.5384615 0.5384615 0.6000000 0.6000000 0.6666667 0.6666667 0.4814815
#> Cell_29 0.6666667 0.8181818 0.6666667 0.6666667 0.6000000 0.5384615 0.6000000
#> Cell_30 0.4814815 0.5384615 0.4285714 0.5384615 0.4285714 0.5384615 0.4285714
#>                                                                              
#> Cell_1  0.5384615 0.4814815 0.8181818 0.6666667 0.6000000 0.4814815 0.6666667
#> Cell_2  0.4814815 0.4814815 0.6666667 0.6666667 0.6000000 0.6666667 0.7391304
#> Cell_3  0.4814815 0.4285714 0.6666667 0.6666667 0.6666667 0.6666667 0.6666667
#> Cell_4  0.6666667 0.5384615 0.6666667 0.6000000 0.6000000 0.5384615 0.6666667
#> Cell_5  0.4814815 0.5384615 0.5384615 0.6000000 0.5384615 0.7391304 0.5384615
#> Cell_6  0.6666667 0.5384615 0.7391304 0.7391304 0.5384615 0.6000000 0.6666667
#> Cell_7  0.4285714 0.4285714 0.6000000 0.5384615 0.6000000 0.4814815 0.6666667
#> Cell_8  1.0000000 0.6666667 0.5384615 0.6000000 0.4814815 0.6000000 0.5384615
#> Cell_9  0.6666667 1.0000000 0.3793103 0.5384615 0.4285714 0.6666667 0.4814815
#> Cell_10 0.5384615 0.3793103 1.0000000 0.7391304 0.6666667 0.4814815 0.6666667
#> Cell_11 0.6000000 0.5384615 0.7391304 1.0000000 0.4814815 0.6666667 0.5384615
#> Cell_12 0.4814815 0.4285714 0.6666667 0.4814815 1.0000000 0.5384615 0.6666667
#> Cell_13 0.6000000 0.6666667 0.4814815 0.6666667 0.5384615 1.0000000 0.5384615
#> Cell_14 0.5384615 0.4814815 0.6666667 0.5384615 0.6666667 0.5384615 1.0000000
#> Cell_15 0.6000000 0.6000000 0.4814815 0.4814815 0.5384615 0.6666667 0.4814815
#> Cell_16 0.4814815 0.4814815 0.5384615 0.5384615 0.6000000 0.5384615 0.6000000
#> Cell_17 0.5384615 0.8181818 0.4285714 0.6000000 0.5384615 0.7391304 0.5384615
#> Cell_18 0.5384615 0.6666667 0.4814815 0.6000000 0.5384615 0.6666667 0.6666667
#> Cell_19 0.6000000 0.5384615 0.6666667 0.5384615 0.6666667 0.6000000 0.6666667
#> Cell_20 0.4285714 0.4814815 0.4814815 0.4814815 0.6000000 0.6000000 0.5384615
#> Cell_21 0.5384615 0.6000000 0.6000000 0.7391304 0.6000000 0.7391304 0.4285714
#> Cell_22 0.6000000 0.5384615 0.6000000 0.5384615 0.6666667 0.6666667 0.5384615
#> Cell_23 0.6000000 0.4285714 0.9047619 0.7391304 0.6666667 0.5384615 0.7391304
#> Cell_24 0.5384615 0.6000000 0.6000000 0.7391304 0.6000000 0.8181818 0.6666667
#> Cell_25 0.6666667 0.6666667 0.6000000 0.6666667 0.5384615 0.6666667 0.6666667
#> Cell_26 0.6000000 0.4814815 0.5384615 0.4814815 0.6000000 0.5384615 0.6000000
#> Cell_27 0.6000000 0.6000000 0.6666667 0.6666667 0.6666667 0.7391304 0.7391304
#> Cell_28 0.6666667 0.7391304 0.5384615 0.6666667 0.5384615 0.7391304 0.5384615
#> Cell_29 0.5384615 0.5384615 0.6666667 0.7391304 0.6666667 0.6666667 0.6666667
#> Cell_30 0.6000000 0.7391304 0.4285714 0.4814815 0.5384615 0.5384615 0.5384615
#>                                                                              
#> Cell_1  0.4285714 0.4814815 0.4814815 0.5384615 0.5384615 0.4285714 0.5384615
#> Cell_2  0.5384615 0.5384615 0.5384615 0.6666667 0.5384615 0.4285714 0.5384615
#> Cell_3  0.4814815 0.6000000 0.5384615 0.5384615 0.4814815 0.6000000 0.6000000
#> Cell_4  0.5384615 0.4285714 0.4814815 0.6666667 0.6666667 0.4814815 0.5384615
#> Cell_5  0.5384615 0.5384615 0.6666667 0.6666667 0.5384615 0.6000000 0.6000000
#> Cell_6  0.5384615 0.6000000 0.5384615 0.6000000 0.6666667 0.5384615 0.5384615
#> Cell_7  0.4814815 0.5384615 0.4814815 0.6000000 0.6000000 0.4814815 0.4814815
#> Cell_8  0.6000000 0.4814815 0.5384615 0.5384615 0.6000000 0.4285714 0.5384615
#> Cell_9  0.6000000 0.4814815 0.8181818 0.6666667 0.5384615 0.4814815 0.6000000
#> Cell_10 0.4814815 0.5384615 0.4285714 0.4814815 0.6666667 0.4814815 0.6000000
#> Cell_11 0.4814815 0.5384615 0.6000000 0.6000000 0.5384615 0.4814815 0.7391304
#> Cell_12 0.5384615 0.6000000 0.5384615 0.5384615 0.6666667 0.6000000 0.6000000
#> Cell_13 0.6666667 0.5384615 0.7391304 0.6666667 0.6000000 0.6000000 0.7391304
#> Cell_14 0.4814815 0.6000000 0.5384615 0.6666667 0.6666667 0.5384615 0.4285714
#> Cell_15 1.0000000 0.6000000 0.5384615 0.4814815 0.6666667 0.6000000 0.6000000
#> Cell_16 0.6000000 1.0000000 0.6000000 0.4814815 0.5384615 0.6666667 0.6000000
#> Cell_17 0.5384615 0.6000000 1.0000000 0.6666667 0.5384615 0.6000000 0.6666667
#> Cell_18 0.4814815 0.4814815 0.6666667 1.0000000 0.6000000 0.4814815 0.5384615
#> Cell_19 0.6666667 0.5384615 0.5384615 0.6000000 1.0000000 0.6000000 0.6000000
#> Cell_20 0.6000000 0.6666667 0.6000000 0.4814815 0.6000000 1.0000000 0.6000000
#> Cell_21 0.6000000 0.6000000 0.6666667 0.5384615 0.6000000 0.6000000 1.0000000
#> Cell_22 0.6666667 0.6666667 0.6000000 0.5384615 0.7391304 0.6000000 0.7391304
#> Cell_23 0.4814815 0.4814815 0.4814815 0.5384615 0.6666667 0.4285714 0.5384615
#> Cell_24 0.5384615 0.6000000 0.7391304 0.6666667 0.6000000 0.6000000 0.6666667
#> Cell_25 0.6000000 0.6000000 0.6666667 0.6000000 0.5384615 0.6000000 0.6000000
#> Cell_26 0.5384615 0.4285714 0.4814815 0.6000000 0.7391304 0.6000000 0.4285714
#> Cell_27 0.6000000 0.5384615 0.6666667 0.7391304 0.7391304 0.5384615 0.6000000
#> Cell_28 0.7391304 0.6000000 0.6666667 0.6000000 0.6666667 0.6000000 0.7391304
#> Cell_29 0.4814815 0.4814815 0.6000000 0.7391304 0.5384615 0.4285714 0.6666667
#> Cell_30 0.6666667 0.6666667 0.6666667 0.6000000 0.5384615 0.5384615 0.5384615
#>                                                                              
#> Cell_1  0.5384615 0.8181818 0.6000000 0.6000000 0.5384615 0.6666667 0.5384615
#> Cell_2  0.5384615 0.7391304 0.6666667 0.6000000 0.5384615 0.7391304 0.5384615
#> Cell_3  0.5384615 0.6666667 0.7391304 0.6666667 0.4814815 0.6000000 0.6000000
#> Cell_4  0.5384615 0.7391304 0.6000000 0.6000000 0.6666667 0.7391304 0.6000000
#> Cell_5  0.6666667 0.5384615 0.6666667 0.6666667 0.5384615 0.6666667 0.6666667
#> Cell_6  0.6000000 0.7391304 0.7391304 0.6666667 0.6666667 0.7391304 0.6666667
#> Cell_7  0.4814815 0.6666667 0.5384615 0.4285714 0.6000000 0.6000000 0.4814815
#> Cell_8  0.6000000 0.6000000 0.5384615 0.6666667 0.6000000 0.6000000 0.6666667
#> Cell_9  0.5384615 0.4285714 0.6000000 0.6666667 0.4814815 0.6000000 0.7391304
#> Cell_10 0.6000000 0.9047619 0.6000000 0.6000000 0.5384615 0.6666667 0.5384615
#> Cell_11 0.5384615 0.7391304 0.7391304 0.6666667 0.4814815 0.6666667 0.6666667
#> Cell_12 0.6666667 0.6666667 0.6000000 0.5384615 0.6000000 0.6666667 0.5384615
#> Cell_13 0.6666667 0.5384615 0.8181818 0.6666667 0.5384615 0.7391304 0.7391304
#> Cell_14 0.5384615 0.7391304 0.6666667 0.6666667 0.6000000 0.7391304 0.5384615
#> Cell_15 0.6666667 0.4814815 0.5384615 0.6000000 0.5384615 0.6000000 0.7391304
#> Cell_16 0.6666667 0.4814815 0.6000000 0.6000000 0.4285714 0.5384615 0.6000000
#> Cell_17 0.6000000 0.4814815 0.7391304 0.6666667 0.4814815 0.6666667 0.6666667
#> Cell_18 0.5384615 0.5384615 0.6666667 0.6000000 0.6000000 0.7391304 0.6000000
#> Cell_19 0.7391304 0.6666667 0.6000000 0.5384615 0.7391304 0.7391304 0.6666667
#> Cell_20 0.6000000 0.4285714 0.6000000 0.6000000 0.6000000 0.5384615 0.6000000
#> Cell_21 0.7391304 0.5384615 0.6666667 0.6000000 0.4285714 0.6000000 0.7391304
#> Cell_22 1.0000000 0.5384615 0.6000000 0.6000000 0.6000000 0.6666667 0.7391304
#> Cell_23 0.5384615 1.0000000 0.6666667 0.6000000 0.6000000 0.7391304 0.5384615
#> Cell_24 0.6000000 0.6666667 1.0000000 0.6666667 0.5384615 0.8181818 0.6666667
#> Cell_25 0.6000000 0.6000000 0.6666667 1.0000000 0.4814815 0.6666667 0.8181818
#> Cell_26 0.6000000 0.6000000 0.5384615 0.4814815 1.0000000 0.6666667 0.5384615
#> Cell_27 0.6666667 0.7391304 0.8181818 0.6666667 0.6666667 1.0000000 0.6666667
#> Cell_28 0.7391304 0.5384615 0.6666667 0.8181818 0.5384615 0.6666667 1.0000000
#> Cell_29 0.5384615 0.7391304 0.6666667 0.6666667 0.4814815 0.7391304 0.6000000
#> Cell_30 0.5384615 0.4285714 0.5384615 0.6000000 0.4814815 0.6000000 0.6000000
#>                            
#> Cell_1  0.6666667 0.4814815
#> Cell_2  0.8181818 0.5384615
#> Cell_3  0.6666667 0.4285714
#> Cell_4  0.6666667 0.5384615
#> Cell_5  0.6000000 0.4285714
#> Cell_6  0.5384615 0.5384615
#> Cell_7  0.6000000 0.4285714
#> Cell_8  0.5384615 0.6000000
#> Cell_9  0.5384615 0.7391304
#> Cell_10 0.6666667 0.4285714
#> Cell_11 0.7391304 0.4814815
#> Cell_12 0.6666667 0.5384615
#> Cell_13 0.6666667 0.5384615
#> Cell_14 0.6666667 0.5384615
#> Cell_15 0.4814815 0.6666667
#> Cell_16 0.4814815 0.6666667
#> Cell_17 0.6000000 0.6666667
#> Cell_18 0.7391304 0.6000000
#> Cell_19 0.5384615 0.5384615
#> Cell_20 0.4285714 0.5384615
#> Cell_21 0.6666667 0.5384615
#> Cell_22 0.5384615 0.5384615
#> Cell_23 0.7391304 0.4285714
#> Cell_24 0.6666667 0.5384615
#> Cell_25 0.6666667 0.6000000
#> Cell_26 0.4814815 0.4814815
#> Cell_27 0.7391304 0.6000000
#> Cell_28 0.6000000 0.6000000
#> Cell_29 1.0000000 0.5384615
#> Cell_30 0.5384615 1.0000000

varp_mapping

The varp slot is used to store pairwise relations between features. By default, no information is copied to the varp slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  uns_mapping = FALSE
)
ad$varp
#> NULL

uns_mapping

The uns slot is used for any non-structured miscellaneous data. By default all information in the misc slot of the Seurat object is copied to the uns slot of the AnnData object.

ad <- as_AnnData(
  obj,
  layers_mapping = FALSE,
  obs_mapping = FALSE,
  var_mapping = FALSE,
  obsm_mapping = FALSE,
  varm_mapping = FALSE,
  obsp_mapping = FALSE,
  varp_mapping = FALSE
)
ad$uns
#> $data
#> [1] "some data"

Explicit mapping

It’s also possible to provide an explicit mapping for the conversion from Seurat to AnnData objects. For all of the mappings (layers_mapping, obs_mapping, var_mapping, obsm_mapping, varm_mapping, obsp_mapping, varp_mapping, and uns_mapping), you can provide a named vector where the names are the names in the AnnData object and the values are the names in the Seurat object.

ad <- as_AnnData(
  obj,
  x_mapping = "counts",
  layers_mapping = c(data = "data"),
  obs_mapping = c(metadata1 = "orig.ident", metadata2 = "nCount_RNA"),
  var_mapping = c(metadata_mean = "vf_vst_counts_mean", metadata_variance = "vf_vst_counts_variance"),
  obsm_mapping = c(X_pca = "pca", X_umap = "umap"),
  varm_mapping = c(PCs = "pca"),
  obsp_mapping = c(connectivities = "RNA_nn"),
  uns_mapping = c(extra_data = "data")
)
ad
#> AnnData object with n_obs × n_vars = 30 × 20
#>     obs: 'metadata1', 'metadata2'
#>     var: 'metadata_mean', 'metadata_variance'
#>     uns: 'extra_data'
#>     obsm: 'X_pca', 'X_umap'
#>     varm: 'PCs'
#>     layers: 'data'
#>     obsp: 'connectivities'