library(scKirby)

Intro

ingest_data() runs three main steps:

  1. Read: Automatically infers the file/object type and loads it (sub-function: read_data()).
  2. Convert: Converts it to the desired file/object type (sub-function: to_<format>).
  3. Save: Saves the converted file/object (sub-function: save_data()).

Examples

seurat <- example_obj("seurat")
h5seurat <- example_obj("h5seurat")
sce <- example_obj("sce")
se <- example_obj("se")
h5 <- example_obj("h5")
cds <- example_obj("cds")
ctd <- example_obj("ctd")
adat <- example_obj("anndata")
library(Seurat)
loom <- example_obj("loom")

Ingest expression matrix

As SingleCellExperiment

sce2 <- ingest_data(obj = seurat, 
                    output_type = "SingleCellExperiment")

As Seurat

seurat <- ingest_data(obj=seurat@assays$RNA@counts, 
                      output_type = "Seurat") 

Ingest list

scKirby can ingest a named list (i.e. list(exp=..., annot=...)) with the following items:

This happens to be the format that the example data in EWCE uses, but any user-supplied data will work.

As SingleCellExperiment

sce <- ingest_data(obj=ctd)

As Seurat

seurat.2 <- ingest_data(obj = ctd, 
                        output_type = "seurat")

Ingest Seurat

As SingleCellExperiment

In-memory

sce.2 <- ingest_data(obj=seurat)

Ingest H5Seurat

On-disk

seurat.2 <- ingest_data(obj = h5seurat, 
                        output_class = "seurat")

Ingest HDF5 SingleCellExperiment

As SingleCellExperiment

## Read in the sce object directly
h5.2 <- ingest_data(obj=h5)

## Read it from disk
sce_dir <- dirname(se_filepath(h5.2))
h5.3 <- ingest_data(obj=sce_dir)

As Seurat

## Read in the sce object directly
h5.4 <- ingest_data(obj = h5,
                    output_type = "Seurat") 

Ingest CellDataSet

seurat.2 <- ingest_data(obj=cds,
                        output_type = "Seurat") 

Ingest AnnData

As SingleCellExperiment

# ### Set condaenv= to the name of a conda env you've made 
# reticulate::use_condaenv(condaenv = "echoR") 
## In memory
sce.2 <- ingest_data(obj=adat)

## On disk
path <- save_data(obj = adat,
                 filetype = "anndata")
sce.3 <- ingest_data(obj = path)

As Seurat

seurat.2 <- ingest_data(obj=adat, 
                      output_type = "Seurat")

Ingest loom

From loomR package

As SingleCellExperiment

## In memory 
sce2 <- ingest_data(obj=loom) 

## From disk 
sce3 <- ingest_data(obj=loom$filename)

As Seurat

## In memory 
seurat2 <- ingest_data(obj=loom, 
                       output_type = "Seurat") 

## From disk
print(loom$filename)
seurat3 <- ingest_data(obj=loom$filename,
                       output_type = "Seurat")

Cleanup

Remove example files

try({ file.remove("./pbmc_small.h5Seurat", showWarnings=FALSE) })
try({ unlink("./pbmc_small_h5/", recursive = TRUE) })
try({ file.remove("./pbmc_small.h5ad") })
try({ file.remove("./pbmc_small.loom")  })

Session Info

utils::sessionInfo()




bschilder/scKirby documentation built on April 22, 2024, 12:13 a.m.