File: test-ExperimentList-class.R

package info (click to toggle)
r-bioc-multiassayexperiment 1.24.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 996 kB
  • sloc: makefile: 2
file content (76 lines) | stat: -rw-r--r-- 2,661 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
context("ExperimentList tests")

test_that("ExperimentList constructors work", {
    expect_identical(names(ExperimentList()), character())
    expect_true(validObject(ExperimentList()))

    expect_true(validObject(ExperimentList(list(m=matrix(0, 0, 0)))))
    expect_error(ExperimentList(list(matrix(0, 0, 0))),
                 label="unnamed list element")

    m <- matrix(0, 2, 2, dimnames=list(letters[1:2], letters[1:2]))
    expect_true(validObject(ExperimentList(list(m=m))))
})

test_that("ExperimentList constructor preserves metadata", {
    mcoldf <- DataFrame(AssayNumber=seq_len(length(ExpList)),
        row.names = names(ExpList))
    mcols(ExpList) <- mcoldf

    metalist <- list(Shiny = "Blue Jeans", Old = "Metadata")
    metadata(ExpList) <- metalist

    nexp <- ExperimentList(ExpList)

    expect_identical(mcols(nexp), mcoldf)
    expect_identical(metadata(nexp), metalist)
})

test_that("Metadata is kept in ExperimentList when replacing", {
    ## add metadata columns and metadata
    mcoldf <- DataFrame(AssayNumber=seq_len(length(ExpList)),
        row.names = names(ExpList))
    mcols(ExpList) <- mcoldf

    metalist <- list(Shiny = "Blue Jeans", Old = "Metadata")
    metadata(ExpList) <- metalist

    mae0 <- mae
    experiments(mae0) <- ExpList

    expect_identical(mcols(experiments(mae0)), mcoldf)
    expect_identical(metadata(experiments(mae0)), metalist)
})

test_that("ExperimentList validity function catches non-compatible classes", {
    # list
    testObj <- list(A = 1:3, B = letters[1:3])
    expect_error(ExperimentList(assay1 = testObj))
    # List
    testObj <- List(A = 1:3, B = letters[1:3])
    expect_error(ExperimentList(assay1 = testObj))
    testObj <- list(A = matrix(1, 1, dimnames = list("A", "A")))
    expect_true(validObject(ExperimentList(assay1 = testObj)))
    A <- array(1:24, 4:2, dimnames =
        list(letters[1:4], LETTERS[1:3], c("A", "B"))
    )
    B <- matrix(1:12, ncol=3, dimnames = list(letters[1:4], LETTERS[1:3]))
    se2 <- SummarizedExperiment(list(A=A, B=B))
    expect_true(validObject(ExperimentList(se2 = se2)))
    # top-level DataFrame / data.frame
    testObj <- DataFrame(A = 1:3, B = letters[1:3])
    testObj1 <- data.frame(A = 1:3, B = letters[1:3])
    expect_warning(ExperimentList(assay1 = list(a = testObj)))
    expect_warning(ExperimentList(assay1 = list(a = testObj, b = testObj1)))
    expect_warning(ExperimentList(assay1 = testObj))
    ## GRangesList
    expect_error(
        ExperimentList(list(GR = GRangesList())),
        "GRangesList"
    )
    ## vector
    expect_error(
        ExperimentList(list(int = 1:100L)),
        "integer"
    )
})