Created
November 5, 2021 19:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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