Convert objects (Seurat & LIGER) to anndata objects

as.anndata(x, ...)

# S3 method for Seurat
as.anndata(
  x,
  file_path,
  file_name,
  assay = NULL,
  main_layer = "data",
  other_layers = "counts",
  transer_dimreduc = TRUE,
  verbose = TRUE,
  ...
)

# S3 method for liger
as.anndata(
  x,
  file_path,
  file_name,
  transfer_norm.data = FALSE,
  reduction_label = NULL,
  add_barcode_names = FALSE,
  barcode_prefix = TRUE,
  barcode_cell_id_delimiter = "_",
  verbose = TRUE,
  ...
)

Arguments

x

Seurat or LIGER object

...

Arguments passed to other methods

file_path

directory file path and/or file name prefix. Defaults to current wd.

file_name

file name.

assay

Assay containing data to use, (default is object default assay).

main_layer

the layer of data to become default layer in anndata object (default is "data").

other_layers

other data layers to transfer to anndata object (default is "counts").

transer_dimreduc

logical, whether to transfer dimensionality reduction coordinates from Seurat to anndata object (default is TRUE).

verbose

logical, whether to print status messages during object conversion (default is TRUE).

transfer_norm.data

logical, whether to transfer the norm.data in addition to raw.data, default is FALSE.

reduction_label

What to label the visualization dimensionality reduction. LIGER does not store name of technique and therefore needs to be set manually.

add_barcode_names

logical, whether to add dataset names to the cell barcodes when merging object data, default is FALSE.

barcode_prefix

logical, if add_barcode_names = TRUE should the names be added as prefix to current cell barcodes/names or a suffix (default is TRUE; prefix).

barcode_cell_id_delimiter

The delimiter to use when adding dataset id to barcode prefix/suffix. Default is "_".

Value

an anndata object generated from x, saved at path provided.

References

Seurat version modified and enhanced version of sceasy::seurat2anndata (sceasy package: https://github.com/cellgeni/sceasy; License: GPL-3. Function has additional checks and supports Seurat V3 and V5 object structure.

LIGER version inspired by sceasy::seurat2anndata modified and updated to apply to LIGER objects (sceasy package: https://github.com/cellgeni/sceasy; License: GPL-3.

Examples

if (FALSE) {
as.anndata(x = seurat_object, file_path = "/folder_name", file_name = "anndata_converted.h5ad")
}

if (FALSE) {
as.anndata(x = liger_object, file_path = "/folder_name", file_name = "anndata_converted.h5ad")
}