Skip to content

Instantly share code, notes, and snippets.

@tomsing1
Created November 5, 2021 19:12
Show Gist options
  • Save tomsing1/ac35d6bba2062e33aa0558d373420d42 to your computer and use it in GitHub Desktop.
Save tomsing1/ac35d6bba2062e33aa0558d373420d42 to your computer and use it in GitHub Desktop.
Writing and reading h5ad files from R using the zellkonverter Bioconductor R package
libraries = c("zellkonverter", "SingleCellExperiment")
for (lib in libraries) {
suppressPackageStartupMessages(library(lib, character.only = TRUE,
quietly = TRUE))
}
# dummy SingleCellExperiment
ncells <- 100
u <- matrix(rpois(20000, 5), ncol = ncells)
v <- log2(u + 1)
pca <- matrix(runif(ncells*5), ncells)
tsne <- matrix(rnorm(ncells*2), ncells)
sce <- SingleCellExperiment(assays = list(counts = u, logcounts = v),
reducedDims = SimpleList(PCA = pca, tSNE = tsne))
sce
out_path <- tempfile(fileext = ".h5ad")
# When first run, this will instantiate a conda environment for zellkonverter
writeH5AD(sce, file = out_path, verbose = TRUE)
readH5AD(out_path, verbose = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment