/usr/lib/R/site-library/IRanges/unitTests/test_findOverlaps-methods.R is in r-bioc-iranges 2.12.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | ###
test_findOverlaps_Ranges <- function()
{
## .....
## ....
## ..
## x
## xx
## xxx
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
result <- findOverlaps(query, subject, select = "first")
checkIdentical(result, c(1L, NA, 3L))
result <- findOverlaps(query, subject, select = "last")
checkIdentical(result, c(2L, NA, 3L))
result <- findOverlaps(query, subject, select = "arbitrary")
checkIdentical(result, c(2L, NA, 3L))
checkOverlap <- function(a, q, s, r, c) {
target <- Hits(q, s, r, c, sort.by.query=TRUE)
checkIdentical(t(a), t(target))
}
result <- findOverlaps(query, subject)
checkOverlap(result, c(1, 1, 3), c(1, 2, 3), 3, 3)
## with 'maxgap'
result <- findOverlaps(query, subject, maxgap = 0L)
checkOverlap(result, c(1, 1, 2, 3), c(2, 1, 2, 3), 3, 3)
## with 'minoverlap'
result <- findOverlaps(query, subject, minoverlap = 3L)
checkOverlap(result, integer(0), integer(0), 3, 3)
result <- findOverlaps(query, subject, minoverlap = 2L)
checkOverlap(result, 1, 2, 3, 3)
result <- findOverlaps(query, subject, minoverlap = 2L, select = "first")
checkIdentical(result, c(2L, NA, NA))
result <- findOverlaps(query, subject, minoverlap = 2L, select = "last")
checkIdentical(result, c(2L, NA, NA))
result <- findOverlaps(query, subject, minoverlap = 2L, select = "arbitrary")
checkIdentical(result, c(2L, NA, NA))
## zero-width ranges
query <- IRanges(9:14, 8:13)
result <- findOverlaps(query, subject, minoverlap = 1L)
checkOverlap(result, integer(0), integer(0), 6, 3)
result <- findOverlaps(query, subject)
checkOverlap(result, c(3, 4), c(3, 3), 6, 3)
result <- findOverlaps(query, subject, maxgap = 0L)
checkOverlap(result, 2:5, c(3, 3, 3, 3), 6, 3)
result <- findOverlaps(query, subject, maxgap = 1L)
checkOverlap(result, 1:6, c(3, 3, 3, 3, 3, 3), 6, 3)
result <- findOverlaps(subject, query, minoverlap = 1L)
checkOverlap(result, integer(0), integer(0), 3, 6)
result <- findOverlaps(subject, query)
checkOverlap(result, c(3, 3), c(3, 4), 3, 6)
result <- findOverlaps(subject, query, maxgap = 0L)
checkOverlap(result, c(3, 3, 3, 3), 2:5, 3, 6)
result <- findOverlaps(subject, query, maxgap = 1L)
checkOverlap(result, c(3, 3, 3, 3, 3, 3), 1:6, 3, 6)
## .....
## ....
## ..
## xxxx
## xxx
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2), c(5, 4))
result <- findOverlaps(query, subject)
checkOverlap(result, c(1, 1, 2, 2), c(1, 2, 1, 2), 3, 2)
result <- findOverlaps(subject, query)
checkOverlap(result, c(1, 1, 2, 2), c(1, 2, 1, 2), 2, 3)
query <- IRanges(c(1, 4, 9, 11), c(5, 7, 10, 11))
result <- findOverlaps(query)
checkOverlap(result, c(1, 1, 2, 2, 3, 4), c(1, 2, 1, 2, 3, 4), 4, 4)
## check case of identical subjects
## .....
## .....
## ..
## xxxx
## xxxx
## xx
## xxx
## xx
query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2, 6, 6, 6), c(5, 5, 7, 8, 7))
result <- findOverlaps(query, subject)
checkOverlap(result, c(1, 1, 2, 2, 2, 2, 2), c(1, 2, 1, 2, 3, 4, 5), 3, 5)
subject <- IRanges(c(1, 6, 13), c(4, 9, 14)) # single points
checkIdentical(findOverlaps(c(3L, 7L, 10L), subject, select = "first"),
c(1L, 2L, NA))
checkIdentical(findOverlaps(c(3L, 7L, 10L), subject, select = "last"),
c(1L, 2L, NA))
checkIdentical(findOverlaps(c(3L, 7L, 10L), subject, select = "arbitrary"),
c(1L, 2L, NA))
checkIdentical(findOverlaps(IRanges(c(2,1),c(3,4)), subject),
Hits(1:2, c(1, 1), 2, 3, sort.by.query=TRUE))
## check other types of matching
## ..
## ..
## ....
## ......
## xxxx
## xxxx
## xxxxx
## xxxx
query <- IRanges(c(1, 5, 3, 4), width=c(2, 2, 4, 6))
subject <- IRanges(c(1, 3, 5, 6), width=c(4, 4, 5, 4))
## 'start'
result <- findOverlaps(query, subject, type = "start")
checkOverlap(result, c(1, 2, 3), c(1, 3, 2), 4, 4)
## minoverlap > 1L
result <- findOverlaps(query, subject, type = "start", minoverlap = 3L)
checkOverlap(result, 3, 2, 4, 4)
## 'end'
result <- findOverlaps(query, subject, type = "end")
checkOverlap(result, c(2, 3, 4, 4), c(2, 2, 3, 4), 4, 4)
result <- findOverlaps(subject, query, type = "end")
checkOverlap(result, c(2, 2, 3, 4), c(2, 3, 4, 4), 4, 4)
## select = "first"
result <- findOverlaps(query, subject, type = "end", select = "first")
checkIdentical(result, c(NA, 2L, 2L, 3L))
## 'within'
result <- findOverlaps(query, subject, type = "within")
checkOverlap(result, c(1, 2, 2, 3), c(1, 2, 3, 2), 4, 4)
## 'equal'
result <- findOverlaps(query, subject, type = "equal")
checkOverlap(result, 3, 2, 4, 4)
checkException(findOverlaps(query, NULL), silent = TRUE)
checkException(findOverlaps(NULL, query), silent = TRUE)
}
test_subsetByOverlaps_Ranges <- function() {
x <- IRanges(9:12, 15)
ranges <- IRanges(1, 10)
checkIdentical(x[1:2], subsetByOverlaps(x, ranges))
checkIdentical(x[3:4], subsetByOverlaps(x, ranges, invert=TRUE))
checkIdentical(x[1:3], subsetByOverlaps(x, ranges, maxgap=0))
checkIdentical(x[4], subsetByOverlaps(x, ranges, maxgap=0, invert=TRUE))
x <- IRanges(c(1, 4, 9), c(5, 7, 10))
ranges <- IRanges(c(6, 8, 10), c(7, 12, 14))
checkIdentical(x[2:3], subsetByOverlaps(x, ranges))
checkIdentical(x[1], subsetByOverlaps(x, ranges, invert=TRUE))
checkIdentical(x, subsetByOverlaps(x, ranges, maxgap=0))
checkIdentical(x[0], subsetByOverlaps(x, ranges, maxgap=0, invert=TRUE))
}
|