File: H5ADMatrix-class.R

package info (click to toggle)
r-bioc-hdf5array 1.34.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,736 kB
  • sloc: ansic: 5,815; makefile: 4
file content (58 lines) | stat: -rw-r--r-- 1,764 bytes parent folder | download | duplicates (2)
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
### =========================================================================
### H5ADMatrix objects
### -------------------------------------------------------------------------
###


setClass("H5ADMatrix",
    contains="DelayedMatrix",
    representation(seed="H5ADMatrixSeed")
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Constructor
###

setMethod("DelayedArray", "H5ADMatrixSeed",
    function(seed) new_DelayedArray(seed, Class="H5ADMatrix")
)

### Works directly on an H5ADMatrixSeed derivative, in which case it must
### be called with a single argument.
H5ADMatrix <- function(filepath, layer=NULL)
{
    if (is(filepath, "H5ADMatrixSeed")) {
        if (!is.null(layer))
            stop(wmsg("H5ADMatrix() must be called with a single argument ",
                      "when passed an H5ADMatrixSeed derivative"))
        seed <- filepath
    } else {
        seed <- H5ADMatrixSeed(filepath, layer=layer)
    }
    DelayedArray(seed)
}


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Taking advantage of sparsity
###

### Will work only if the seed is an H5SparseMatrixSeed derivative, that is,
### if it's a CSC_H5ADMatrixSeed or CSR_H5ADMatrixSeed object.
setMethod("nzcount", "H5ADMatrix", function(x) nzcount(x@seed))

setMethod("read_sparse_block", "H5ADMatrix",
    function(x, viewport) read_sparse_block(x@seed, viewport)
)

### Will work only if the seed is a CSC_H5ADMatrixSeed object.
setMethod("extractNonzeroDataByCol", "H5ADMatrix",
    function(x, j) extractNonzeroDataByCol(x@seed, j)
)

### Will work only if the seed is a CSR_H5ADMatrixSeed object.
setMethod("extractNonzeroDataByRow", "H5ADMatrix",
    function(x, i) extractNonzeroDataByCol(x@seed, i)
)