View source: R/writeHDF5Array.R
writeHDF5Array | R Documentation |
A function for writing an array-like object to an HDF5 file.
writeHDF5Array(x, filepath=NULL, name=NULL,
H5type=NULL, chunkdim=NULL, level=NULL, as.sparse=NA,
with.dimnames=TRUE, verbose=NA)
x |
The array-like object to write to an HDF5 file. If |
filepath |
|
name |
|
H5type |
The H5 datatype to use for the HDF5 dataset to be written to the HDF5
file is automatically inferred from the type of See A typical use case is to use a datatype that is smaller than the
automatic one in order to reduce the size of the dataset on disk.
For example you could use |
chunkdim |
The dimensions of the chunks to use for writing the data to disk.
By default (i.e. when Set |
level |
The compression level to use for writing the data to disk.
By default, |
as.sparse |
Whether the data in the returned HDF5Array object should be
flagged as sparse or not. If set to IMPORTANT NOTE: This only controls the |
with.dimnames |
Whether the dimnames on Note that |
verbose |
Whether block processing progress should be displayed or not.
If set to |
Please note that, depending on the size of the data to write to disk
and the performance of the disk, writeHDF5Array()
can take a
long time to complete. Use verbose=TRUE
to see its progress.
Use setHDF5DumpFile
and setHDF5DumpName
to
control the location of automatically created HDF5 datasets.
Use setHDF5DumpChunkLength
,
setHDF5DumpChunkShape
, and
setHDF5DumpCompressionLevel
, to control the
physical properties of automatically created HDF5 datasets.
An HDF5Array object pointing to the newly written HDF5 dataset on disk.
When passed a DelayedArray object, writeHDF5Array
realizes it on disk, that is, all the delayed operations carried
by the object are executed on-the-fly while the object is written to disk.
This uses a block-processing strategy so that the full object is not
realized at once in memory. Instead the object is processed block by block
i.e. the blocks are realized in memory and written to disk one at a time.
In other words, writeHDF5Array(x, ...)
is semantically equivalent
to writeHDF5Array(as.array(x), ...)
, except that as.array(x)
is not called because this would realize the full object at once in memory.
See ?DelayedArray
for general information about
DelayedArray objects.
Documentation of the H5 predefined datatypes on the HDF Group's Support Portal: https://portal.hdfgroup.org/display/HDF5/Predefined+Datatypes
HDF5Array objects.
h5writeDimnames
for writing the dimnames of an
HDF5 dataset to disk.
saveHDF5SummarizedExperiment
and
loadHDF5SummarizedExperiment
in this
package (the HDF5Array package) for saving/loading
an HDF5-based SummarizedExperiment
object to/from disk.
HDF5-dump-management to control the location and physical properties of automatically created HDF5 datasets.
h5ls
to list the content of an HDF5 file.
## ---------------------------------------------------------------------
## WRITE AN ORDINARY ARRAY TO AN HDF5 FILE
## ---------------------------------------------------------------------
m0 <- matrix(runif(364, min=-1), nrow=26,
dimnames=list(letters, LETTERS[1:14]))
h5file <- tempfile(fileext=".h5")
M1 <- writeHDF5Array(m0, h5file, name="M1", chunkdim=c(5, 5))
M1
chunkdim(M1)
## By default, writeHDF5Array() writes the dimnames to the HDF5 file:
dimnames(M1) # same as 'dimnames(m0)'
## Use 'with.dimnames=FALSE' to not write the dimnames to the file:
M1b <- writeHDF5Array(m0, h5file, name="M1b", with.dimnames=FALSE)
dimnames(M1b) # no dimnames
## With sparse data:
sm <- rsparsematrix(20, 8, density=0.1)
M2 <- writeHDF5Array(sm, h5file, name="M2", chunkdim=c(5, 5))
M2
is_sparse(M2) # TRUE
## ---------------------------------------------------------------------
## WRITE A DelayedArray OBJECT TO AN HDF5 FILE
## ---------------------------------------------------------------------
M3 <- log(t(DelayedArray(m0)) + 1)
M3 <- writeHDF5Array(M3, h5file, name="M3", chunkdim=c(5, 5))
M3
chunkdim(M3)
library(h5vcData)
tally_file <- system.file("extdata", "example.tally.hfs5",
package="h5vcData")
h5ls(tally_file)
cvg0 <- HDF5Array(tally_file, "/ExampleStudy/16/Coverages")
cvg1 <- cvg0[ , , 29000001:29000007]
writeHDF5Array(cvg1, h5file, "cvg1")
h5ls(h5file)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.