Skip to contents

The ReshapedHDF5Array class is a DelayedArray subclass for representing an HDF5 dataset with a user-supplied upfront virtual reshaping.

All the operations available for DelayedArray objects work on ReshapedHDF5Array objects.

Usage

## Constructor function:
ReshapedHDF5Array(filepath, name, dim, type=NA)

Arguments

filepath, name, type

See ?HDF5Array for a description of these arguments.

dim

A vector of dimensions that describes the virtual reshaping i.e. the reshaping that is virtually applied upfront to the HDF5 dataset when the ReshapedHDF5Array object gets constructed.

Note that the HDF5 dataset is treated as read-only so is not effectively reshaped, that is, the dataset dimensions encoded in the HDF5 file are not mmodified.

Also please note that arbitrary reshapings are not supported. Only reshapings that reduce the number of dimensions by collapsing a group of consecutive dimensions into a single dimension are supported. For example, reshaping a 10 x 3 x 5 x 1000 array as a 10 x 15 x 1000 array or as a 150 x 1000 matrix is supported.

Value

A ReshapedHDF5Array (or ReshapedHDF5Matrix) object. (Note that ReshapedHDF5Matrix extends ReshapedHDF5Array.)

See also

Examples

library(h5vcData)
tally_file <- system.file("extdata", "example.tally.hfs5",
                          package="h5vcData")
h5ls(tally_file)
#>               group         name       otype  dclass                   dim
#> 0                 / ExampleStudy   H5I_GROUP                              
#> 1     /ExampleStudy           16   H5I_GROUP                              
#> 2  /ExampleStudy/16       Counts H5I_DATASET INTEGER 12 x 6 x 2 x 90354753
#> 3  /ExampleStudy/16    Coverages H5I_DATASET INTEGER      6 x 2 x 90354753
#> 4  /ExampleStudy/16    Deletions H5I_DATASET INTEGER      6 x 2 x 90354753
#> 5  /ExampleStudy/16    Reference H5I_DATASET INTEGER              90354753
#> 6     /ExampleStudy           22   H5I_GROUP                              
#> 7  /ExampleStudy/22       Counts H5I_DATASET INTEGER 12 x 6 x 2 x 51304566
#> 8  /ExampleStudy/22    Coverages H5I_DATASET INTEGER      6 x 2 x 51304566
#> 9  /ExampleStudy/22    Deletions H5I_DATASET INTEGER      6 x 2 x 51304566
#> 10 /ExampleStudy/22    Reference H5I_DATASET INTEGER              51304566

## Pick up "Coverages" dataset for Human chromosome 16 and collapse its
## first 2 dimensions:
cvg <- ReshapedHDF5Array(tally_file, "/ExampleStudy/16/Coverages",
                         dim=c(12, 90354753))
cvg
#> <12 x 90354753> ReshapedHDF5Matrix object of type "integer":
#>              [,1]        [,2]        [,3]        [,4] ... [,90354750]
#>  [1,]           0           0           0           0   .           0
#>  [2,]           0           0           0           0   .           0
#>  [3,]           0           0           0           0   .           0
#>  [4,]           0           0           0           0   .           0
#>  [5,]           0           0           0           0   .           0
#>   ...           .           .           .           .   .           .
#>  [8,]           0           0           0           0   .           0
#>  [9,]           0           0           0           0   .           0
#> [10,]           0           0           0           0   .           0
#> [11,]           0           0           0           0   .           0
#> [12,]           0           0           0           0   .           0
#>       [,90354751] [,90354752] [,90354753]
#>  [1,]           0           0           0
#>  [2,]           0           0           0
#>  [3,]           0           0           0
#>  [4,]           0           0           0
#>  [5,]           0           0           0
#>   ...           .           .           .
#>  [8,]           0           0           0
#>  [9,]           0           0           0
#> [10,]           0           0           0
#> [11,]           0           0           0
#> [12,]           0           0           0

is(cvg, "DelayedArray")  # TRUE
#> [1] TRUE
seed(cvg)
#> An object of class "ReshapedHDF5ArraySeed"
#> Slot "reshaped_dim":
#> [1]       12 90354753
#> 
#> Slot "reshaped_chunkdim":
#> [1]     1 88238
#> 
#> Slot "filepath":
#> [1] "/usr/local/lib/R/site-library/h5vcData/extdata/example.tally.hfs5"
#> 
#> Slot "name":
#> [1] "/ExampleStudy/16/Coverages"
#> 
#> Slot "as_sparse":
#> [1] FALSE
#> 
#> Slot "type":
#> [1] NA
#> 
#> Slot "dim":
#> [1]        6        2 90354753
#> 
#> Slot "chunkdim":
#> [1]     1     1 88238
#> 
#> Slot "first_val":
#> [1] 0
#> 
path(cvg)
#> [1] "/usr/local/lib/R/site-library/h5vcData/extdata/example.tally.hfs5"
dim(cvg)
#> [1]       12 90354753
chunkdim(cvg)
#> [1]     1 88238