-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathwrite_h5ad.Rd
More file actions
113 lines (99 loc) · 3.14 KB
/
write_h5ad.Rd
File metadata and controls
113 lines (99 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/write_h5ad.R
\name{write_h5ad}
\alias{write_h5ad}
\title{Write H5AD}
\usage{
write_h5ad(
object,
path,
compression = c("none", "gzip", "lzf"),
mode = c("w-", "r", "r+", "a", "w", "x"),
...
)
}
\arguments{
\item{object}{The object to write, either a
\code{\link[SingleCellExperiment:SingleCellExperiment]{SingleCellExperiment::SingleCellExperiment}} or a
\code{\link[SeuratObject:Seurat-class]{SeuratObject::Seurat}} object}
\item{path}{Path of the file to write to}
\item{compression}{The compression algorithm to use when writing the HDF5
file. Can be one of \code{"none"}, \code{"gzip"} or \code{"lzf"}. Defaults to \code{"none"}.}
\item{mode}{The mode to open the HDF5 file.
\itemize{
\item \code{a} creates a new file or opens an existing one for read/write
\item \verb{r+} opens an existing file for read/write
\item \code{w} creates a file, truncating any existing ones
\item \verb{w-}/\code{x} are synonyms creating a file and failing if it already exists
}}
\item{...}{Additional arguments passed to \code{\link[=as_AnnData]{as_AnnData()}}}
}
\value{
\code{path} invisibly
}
\description{
Write an H5AD file
}
\details{
\subsection{Compression}{
Compression is currently not supported for Boolean arrays, they will be
written uncompressed.
}
\subsection{\code{NULL} values}{
For compatibility with changes in Python \strong{anndata} 0.12.0, \code{NULL} values
in \code{uns} are written to H5AD files as a \code{NULL} dataset (instead of not being
written at all). To disable this behaviour, set
\code{option(anndataR.write_null = FALSE)}. This may be required to allow the file
to be read by older versions of Python \strong{anndata}.
}
}
\examples{
adata <- AnnData(
X = matrix(1:5, 3L, 5L),
layers = list(
A = matrix(5:1, 3L, 5L),
B = matrix(letters[1:5], 3L, 5L)
),
obs = data.frame(row.names = LETTERS[1:3], cell = 1:3),
var = data.frame(row.names = letters[1:5], gene = 1:5)
)
h5ad_file <- tempfile(fileext = ".h5ad")
adata$write_h5ad(h5ad_file)
# Write a SingleCellExperiment as an H5AD
if (requireNamespace("SingleCellExperiment", quietly = TRUE)) {
ncells <- 100
counts <- matrix(rpois(20000, 5), ncol = ncells)
logcounts <- log2(counts + 1)
pca <- matrix(runif(ncells * 5), ncells)
tsne <- matrix(rnorm(ncells * 2), ncells)
sce <- SingleCellExperiment::SingleCellExperiment(
assays = list(counts = counts, logcounts = logcounts),
reducedDims = list(PCA = pca, tSNE = tsne)
)
adata <- as_AnnData(sce)
h5ad_file <- tempfile(fileext = ".h5ad")
adata$write_h5ad(h5ad_file)
}
# Write a Seurat as a H5AD
if (requireNamespace("Seurat", quietly = TRUE)) {
library(Seurat)
counts <- matrix(1:15, 5L, 3L)
dimnames(counts) <- list(
LETTERS[1:5],
letters[1:3]
)
cell.metadata <- data.frame(
row.names = letters[1:3],
cell = 1:3
)
obj <- CreateSeuratObject(counts, meta.data = cell.metadata)
gene.metadata <- data.frame(
row.names = LETTERS[1:5],
gene = 1:5
)
obj[["RNA"]] <- AddMetaData(GetAssay(obj), gene.metadata)
adata <- as_AnnData(obj)
h5ad_file <- tempfile(fileext = ".h5ad")
adata$write_h5ad(h5ad_file)
}
}