This file is indexed.

/usr/lib/R/site-library/Biostrings/unitTests/test_twoWayAlphabetFrequency.R is in r-bioc-biostrings 2.42.1-1.

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
test_twoWayAlphabetFrequency <- function() {
  ## Equivalence classes:
  ##
  ## x, y:
  ## - length [Set]: (different length), zero, length one, length > one
  ## - string length: (inconsistent lengths), zero, same, [Set] varying
  ## - content: some matches, every cell
  ## - types: XString, DNAString, XStringSet, DNAStringSet, (different)
  ##
  ## as.prob: TRUE, FALSE, (NA), (not logical)
  ## baseOnly [DNA]: TRUE, FALSE, (NA), (not logical)
  ## collapse [Set]: TRUE, FALSE, (NA), (not logical)

  library(Biostrings)
  library(RUnit)
  
  testMatrix <-
    function(x, y, v, as.prob = FALSE, baseOnly = FALSE, collapse = FALSE) {
      x.alphabet <- Biostrings:::xscodes(x, baseOnly=baseOnly)
      y.alphabet <- Biostrings:::xscodes(y, baseOnly=baseOnly)
      dim <- c(length(x.alphabet), length(y.alphabet))
      dimnames <- list(names(x.alphabet), names(y.alphabet))
      if (baseOnly) {
        if (!is.null(dimnames[[1]]))
          dimnames[[1]] <- c(dimnames[[1]], "other")
        if (!is.null(dimnames[[2]]))
          dimnames[[2]] <- c(dimnames[[2]], "other")
        dim <- dim + 1L
      }
      mode(v) <- "integer"
      if (as.prob) {
        if (collapse)
          v <- v / sum(v)
        else v <- v / rep(nchar(x), each = prod(dim(v)))
      }
      if (is(x, "XStringSet") || is(y, "XStringSet")) {
        dimnames <- c(dimnames, list(NULL))
        dim <- c(dim, nchar(x))
      }
      a <- array(0L, dim = dim, dimnames = dimnames)
      if (is.null(rownames(a))) {
        x.ind <- as.integer(sapply(rownames(v), charToRaw)) + 1L
      } else {
        x.ind <- rownames(v)
      }
      if (is.null(colnames(a))) {
        y.ind <- as.integer(sapply(rownames(v), charToRaw)) + 1L
      } else {
        y.ind <- rownames(v)
      }
      if (length(dim(a)) == 3)
        a[x.ind,y.ind,] <- v
      else a[x.ind,y.ind] <- v
      a
    }
  
  some.a <- "ACGTACGTACGT"
  some.b <- "ACGTTGCAGGGA"
  some.mat <- rbind(A = c(1, 0, 1, 1),
                    C = c(0, 1, 2, 0),
                    G = c(0, 1, 2, 0),
                    T = c(2, 0, 0, 1))
  
  ## CASE: different nchar, DNAString
  checkException(twoWayAlphabetFrequency(DNAString("ACGT"), DNAString("ACG")),
                 silent = TRUE)
  
  ## CASE: zero, DNAString
  x <- y <- DNAString("")
  checkIdentical(testMatrix(x, y, 0L), twoWayAlphabetFrequency(x, y))
  
  ## CASE: some, XString, FALSE
  x <- BString(some.a)
  y <- BString(some.b)
  truth <- testMatrix(x, y, some.mat)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y))
  
  ## CASE: some, XString, TRUE
  truth <- truth / sum(truth)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y, as.prob = TRUE))
  
  ## CASE: XString, DNAString
  x <- BString(some.a)
  y <- DNAString(some.b)
  
  truth <- testMatrix(x, y, some.mat)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y))

  ## CASE: XString, DNAString, baseOnly = TRUE
  truth <- testMatrix(x, y, some.mat, baseOnly = TRUE)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y, baseOnly = TRUE))
  
  ## CASE: some, DNAString, NA, FALSE
  x <- DNAString(some.a)
  y <- DNAString(some.b)
  
  checkException(twoWayAlphabetFrequency(x, y, as.prob = NA),
                 silent = TRUE)  
  
  ## CASE: some, DNAString, "foo", FALSE
  checkException(twoWayAlphabetFrequency(x, y, as.prob = "foo"),
                 silent = TRUE)

  
  ## CASE: some, DNAString, FALSE, NA
  checkException(twoWayAlphabetFrequency(x, y, baseOnly = NA),
                 silent = TRUE)

  
  ## CASE: some, DNAString, FALSE, "foo"
  checkException(twoWayAlphabetFrequency(x, y, baseOnly = "foo"),
                 silent = TRUE)

  ## CASE: some, DNAString, TRUE, FALSE
  truth <- testMatrix(x, y, some.mat, as.prob = TRUE)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y, as.prob = TRUE))
  
  ## CASE: some, DNAString, FALSE, TRUE
  truth <- testMatrix(x, y, some.mat, baseOnly = TRUE)
  checkIdentical(truth, twoWayAlphabetFrequency(x, y, baseOnly = TRUE))
  
  ## CASE: some, DNAString, TRUE, TRUE
  ## CASE: every, DNAString, FALSE, FALSE
  ## CASE: DNAStringSet, DNAString
  ## CASE: different length, DNAStringSet
  ## CASE: different length, XStringSet
  ## CASE: different widths, DNAStringSet
  ## CASE: different widths, XStringSet
  ## CASE: length==0, DNAString, FALSE, FALSE, FALSE
  ## CASE: length==0, DNAString, FALSE, FALSE, TRUE
  ## CASE: length==1, some, DNAStringSet, FALSE, FALSE, FALSE
  ## CASE: length==1, some, DNAStringSet, FALSE, FALSE, TRUE
  ## CASE: length >1, some, XStringSet, FALSE, , FALSE
  ## CASE: length >1, some, XStringSet, TRUE, , FALSE
  ## CASE: length >1, some, XStringSet, FALSE, , TRUE
  ## CASE: length >1, some, XStringSet, TRUE, , TRUE
  ## CASE: length >1, some, DNAStringSet, FALSE, FALSE, NA
  ## CASE: length >1, some, DNAStringSet, FALSE, FALSE, "foo"
  ## CASE: length >1, some, DNAStringSet, FALSE, FALSE, FALSE
  ## CASE: length >1, some, DNAStringSet, TRUE, FALSE, FALSE
  ## CASE: length >1, some, DNAStringSet, FALSE, FALSE, TRUE
  ## CASE: length >1, some, DNAStringSet, TRUE, FALSE, TRUE
  ## CASE: length >1, some, DNAStringSet, FALSE, TRUE, FALSE
  ## CASE: length >1, some, DNAStringSet, TRUE, TRUE, FALSE
  ## CASE: length >1, some, DNAStringSet, FALSE, TRUE, TRUE
  ## CASE: length >1, some, DNAStringSet, TRUE, TRUE, TRUE

  ## CASE: XString, DNAStringSet

  ## CASE: XStringSet, DNAString
  
}