File: test_findOverlaps-methods.R

package info (click to toggle)
r-bioc-summarizedexperiment 1.36.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 948 kB
  • sloc: makefile: 2
file content (92 lines) | stat: -rw-r--r-- 3,147 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
###

M1 <- matrix(1, 5, 3)
M2 <- matrix(1, 3, 3)
assaysList <- list(gr=SimpleList(m=M1), grl=SimpleList(m=M2))
rowRangesList <-
    list(gr=GRanges("chr1", IRanges(1:5, 10)),
         grl=split(GRanges("chr1", IRanges(1:5, 10)), c(1,1,2,2,3)))
names(rowRangesList[["grl"]]) <- NULL
colData <- DataFrame(x=letters[1:3])

## a list of one SE with GRanges and one with GRangesList
rseList <-
    list(SummarizedExperiment(
           assays=assaysList[["gr"]],
           rowRanges=rowRangesList[["gr"]],
           colData=colData),
         SummarizedExperiment(
           assays=assaysList[["grl"]],
           rowRanges=rowRangesList[["grl"]],
           colData=colData))


test_interfaces <- function()
{
    fun <- "findOverlaps"
    signatures <- list(
        c("RangedSummarizedExperiment", "Vector"),
        c("Vector", "RangedSummarizedExperiment"),
        c("RangedSummarizedExperiment", "RangedSummarizedExperiment")
    )
    generic <- getGeneric(fun)
    for (sig in signatures) {
        method <- getMethod(fun, sig)
        checkIdentical(c("query", "subject"), generic@signature)
        checkIdentical(formals(generic@.Data), formals(method@.Data))
    }
}

test_findOverlaps_methods <- function()
{
    identical_SummarizedExperiment <- function(x, y) {
        x@assays <- as(assays(x), "SimpleAssays")
        y@assays <- as(assays(y), "SimpleAssays")
        identical(x, y)
    }
    for (i in 1:2) {
        x <- rseList[[i]]
        for (j in 1:2) {
            y <- rseList[[j]]

            ## findOverlaps
            target <- findOverlaps(rowRanges(x), rowRanges(y))
            current <- findOverlaps(x, rowRanges(y))
            checkIdentical(target, current)
            current <- findOverlaps(rowRanges(x), y)
            checkIdentical(target, current)
            current <- findOverlaps(x, y)
            checkIdentical(target, current)

            ## countOverlaps
            target <- countOverlaps(rowRanges(x), rowRanges(y))
            current <- countOverlaps(x, rowRanges(y))
            checkIdentical(target, current)
            current <- countOverlaps(rowRanges(x), y)
            checkIdentical(target, current)
            current <- countOverlaps(x, y)
            checkIdentical(target, current)

            ## overlapsAny
            target <- overlapsAny(rowRanges(x), rowRanges(y))
            current <- overlapsAny(x, rowRanges(y))
            checkIdentical(target, current)
            current <- overlapsAny(rowRanges(x), y)
            checkIdentical(target, current)
            current <- overlapsAny(x, y)
            checkIdentical(target, current)

            ## subsetByOverlaps
            target <- subsetByOverlaps(x, rowRanges(y))
            current <- subsetByOverlaps(x, rowRanges(y))
            checkTrue(identical_SummarizedExperiment(target, current))
            current <- subsetByOverlaps(x, y)
            checkTrue(identical_SummarizedExperiment(target, current))

            target <- subsetByOverlaps(rowRanges(x), rowRanges(y))
            current <- subsetByOverlaps(rowRanges(x), y)
            checkIdentical(target, current)
        }
    }
}