File: test_h5dimscales.R

package info (click to toggle)
r-bioc-hdf5array 1.34.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,736 kB
  • sloc: ansic: 5,815; makefile: 4
file content (110 lines) | stat: -rw-r--r-- 4,440 bytes parent folder | download | duplicates (3)
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
test_h5getdimscales_h5setdimscales <- function()
{
    h5getdimscales <- HDF5Array:::h5getdimscales
    h5setdimscales <- HDF5Array:::h5setdimscales

    h5file <- tempfile(fileext=".h5")
    h5createFile(h5file)
    h5createGroup(h5file, "stuff")
    h5createGroup(h5file, "more stuff")
    writeHDF5Array(array(1:24, 4:1), h5file, "A")
    writeHDF5Array(matrix(11:16, ncol=3), h5file, "B")
    writeHDF5Array(matrix(letters, ncol=2), h5file, "stuff/C")
    writeHDF5Array(matrix(runif(10), ncol=5), h5file, "more stuff/D")
    writeHDF5Array(matrix(1:4, ncol=2), h5file, "more stuff/E")
    writeHDF5Array(matrix(1:8, ncol=2), h5file, "E")

    target <- rep(NA_character_, 4)
    current <- h5getdimscales(h5file, "A")
    checkIdentical(target, current)

    dimscales <- c("B", "stuff/C", NA, "more stuff/D")
    target <- c(TRUE, TRUE, FALSE, TRUE)
    current <- h5setdimscales(h5file, "A", dimscales, dry.run=TRUE)
    checkIdentical(target, current)
    current <- h5setdimscales(h5file, "A", dimscales)
    checkIdentical(target, current)
    checkIdentical(logical(4), h5setdimscales(h5file, "A", dimscales))

    target <- paste0("/", dimscales); target[is.na(dimscales)] <- NA
    current <- h5getdimscales(h5file, "A")
    checkIdentical(target, current)

    target <- rep(NA_character_, 4)
    current <- h5getdimscales(h5file, "A", scalename="foo")
    checkIdentical(target, current)

    dimscales <- c(NA, "E", "more stuff/E", "E")
    target <- c(FALSE, TRUE, TRUE, TRUE)
    current <- h5setdimscales(h5file, "A", dimscales, scalename="foo",
                              dry.run=TRUE)
    checkIdentical(target, current)
    current <- h5setdimscales(h5file, "A", dimscales, scalename="foo")
    checkIdentical(target, current)
    checkIdentical(logical(4), h5setdimscales(h5file, "A", dimscales,
                                              scalename="foo"))

    target <- paste0("/", dimscales); target[is.na(dimscales)] <- NA
    current <- h5getdimscales(h5file, "A", scalename="foo")
    checkIdentical(target, current)

    for (name in paste0("Adim", 1:4))
        writeHDF5Array(matrix(1:2), h5file, name)
    for (scalename in c(NA, "foo", "bar"))
        dimscales0 <- h5getdimscales(h5file, "A", scalename=scalename)
        for (scale1 in c(NA, "Adim1", "B"))
          for (scale2 in c(NA, "Adim2", "E"))
            for (scale3 in c(NA, "Adim3", "bogus"))
              for (scale4 in c(NA, "Adim4", "bogus")) {
                dimscales <- c(scale1, scale2, scale3, scale4)
                dimscales2 <- paste0("/", dimscales)
                ok <- is.na(dimscales) |
                      is.na(dimscales0) |
                      dimscales2 == dimscales0
                if (scale1 %in% "B" && !(scalename %in% NA))
                    ok[[1]] <- FALSE
                if (scale2 %in% "E" && !(scalename %in% "foo"))
                    ok[[2]] <- FALSE
                if (!all(ok) || "bogus" %in% dimscales) {
                    checkException(h5setdimscales(h5file, "A", dimscales,
                                                  scalename=scalename),
                                   silent=TRUE)
                    next
                }
                target <- !is.na(dimscales)
                current <- h5setdimscales(h5file, "A", dimscales,
                                          scalename=scalename, dry.run=TRUE)
                checkIdentical(target, current)
              }
}

test_h5getdimlabels_h5setdimlabels <- function()
{
    h5getdimlabels <- HDF5Array:::h5getdimlabels
    h5setdimlabels <- HDF5Array:::h5setdimlabels

    h5file <- tempfile(fileext=".h5")
    h5createFile(h5file)
    h5createGroup(h5file, "stuff")
    h5createGroup(h5file, "more stuff")
    writeHDF5Array(array(1:24, 4:1), h5file, "stuff/A")

    checkIdentical(NULL, h5getdimlabels(h5file, "stuff/A"))

    dimlabels <- c("dim1", NA, NA, "dim4")
    h5setdimlabels(h5file, "stuff/A", dimlabels)
    target <- c("dim1", "", "", "dim4")
    current <- h5getdimlabels(h5file, "stuff/A")
    checkIdentical(target, current)

    dimlabels <- c(NA, "dim2", NA, "XXXX")
    h5setdimlabels(h5file, "stuff/A", dimlabels)
    target <- c("dim1", "dim2", "", "XXXX")
    current <- h5getdimlabels(h5file, "stuff/A")
    checkIdentical(target, current)

    dimlabels <- c("", "", NA, "")
    h5setdimlabels(h5file, "stuff/A", dimlabels)
    checkIdentical(NULL, h5getdimlabels(h5file, "stuff/A"))
}