We provide this tutorial for preparing h5ad file.

1 Initialization

First import Seurat, SeuratDisk, SingleCellExperiment, reticulate, scseasy and some other packages we will be using for preparing h5ad file.

options(warn=-1)
library(Seurat)
library(SeuratData)
library(SeuratDisk)
library(SingleCellExperiment)
library(sceasy)
reticulate::use_condaenv("episcanpy", required = TRUE)
library(reticulate)

2 Seurat to h5ad file

2.1 Create a Seurat object

Next, we will demonstrate the information required for a Seurat object by downloading the single-cell ATAC seq data of pbmc10k and utilizing it to generate a seurat object.

list.files('./example/')
## [1] "atac_v1_pbmc_10k_filtered_peak_bc_matrix.h5"

Load the atac peaks

peak_dir <- './example/atac_v1_pbmc_10k_filtered_peak_bc_matrix.h5'
peaks <- Read10X_h5(peak_dir)
dim(peaks)
## [1] 89796  8728
atac_pbmc <- CreateSeuratObject(counts = peaks, assay = "ATAC", project = "scEpiTools_tutorial")
atac_pbmc
## An object of class Seurat 
## 89796 features across 8728 samples within 1 assay 
## Active assay: ATAC (89796 features, 0 variable features)

2.2 Convert Seurat object to h5ad file

Users should first save their Seurat object in the h5Seurat format and then use SeuratDisk to convert it into an h5ad file. Subsequently, both the h5Seurat and h5ad files can be submitted as input files to the Episcanpy and scEpiEnsemble kernels of scEpiTools.

SaveH5Seurat(atac_pbmc, filename = "pbmc10k.h5Seurat", overwrite = TRUE, verbose = F)
## Creating h5Seurat file for version 3.1.5.9900
Convert("pbmc10k.h5Seurat", dest = "h5ad", assay='ATAC')
## Validating h5Seurat file
## Adding data from ATAC as X
## Adding counts from ATAC as raw
## Transfering meta.data to obs

2.3 Submit to scEpiTools

We submitted this h5ad file to the EpiScanpy kernel, and users can obtain the analysis results of this example directly using the task ID 2023082910295087.

3 SingleCellExperiment to h5ad file

3.1 Create a SingleCellExperiment (sce) object

We use the same pbmc10k peaks data as in the previous step to construct an initial Seurat object.

example_sce <- SingleCellExperiment(
    assays = list(counts = peaks), 
)
example_sce
## class: SingleCellExperiment 
## dim: 89796 8728 
## metadata(0):
## assays(1): counts
## rownames(89796): chr1:565107-565550 chr1:569174-569639 ...
##   chrY:59001782-59002175 chrY:59017143-59017246
## rowData names(0):
## colnames(8728): AAACGAAAGAGCGAAA-1 AAACGAAAGAGTTTGA-1 ...
##   TTTGTGTTCTACTTTG-1 TTTGTGTTCTTGTGCC-1
## colData names(0):
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
example_sce@assays
## An object of class "SimpleAssays"
## Slot "data":
## List of length 1
## names(1): counts

3.2 Convert Sce object to h5ad file

Users can directly store the sce object as an h5ad file using the sceasy package. Similarly, you can also store the Seurat object as an h5ad file.

sceasy::convertFormat(example_sce, from="sce", to="anndata", outFile='Sce_pbmc10k.h5ad')
## AnnData object with n_obs × n_vars = 8728 × 89796
##     obs: 'name'
##     var: 'name'

3.3 Submit to scEpiTools

We submitted this h5ad file to the EpiScanpy kernel, and users can obtain the analysis results of this example directly using the task ID 2023082911005412.