This file is indexed.

/usr/lib/R/site-library/rtracklayer/unitTests/test_wig.R is in r-bioc-rtracklayer 1.38.0-1build1.

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
test_wig <- function() {
  test_path <- system.file("tests", package = "rtracklayer")
  test_wig <- file.path(test_path, "step.wig")

  createCorrectGR <- function(si) {
    score <- c(seq(10, 20, by = 2.5), seq(17.5, 10, by = -2.5),
               seq(1000, 100, by = -100))
    start <- c(59104701 + cumsum(c(0, 200, 500, 200, 300, 180, 220, 390, 1180)),
               59108021 + cumsum(c(0, rep(300, 9))))
    width <- c(rep(1, 9), rep(200, 10))
    space <- factor(c(rep("chr19", 9), rep("chr18", 10)), seqlevels(si))
    correct_gr <- GRanges(space, IRanges(start, width = width), score = score)
    if (!any(is.na(genome(si))))
      genome(correct_gr) <- unname(genome(si)[1])
    seqinfo(correct_gr) <- si
    correct_gr
  }
  createCorrectUCSC <- function(gr) {  
    track_line <- new("GraphTrackLine", type = "wig", name = "test",
                      description = "test track", visibility = "full",
                      autoScale = FALSE, viewLimits = c(0, 1000),
                      color = c(0L, 200L, 100L),
                      maxHeightPixels = c(100L, 50L, 20L),
                      graphType = "points", priority = 30)
    new("UCSCData", gr, trackLine = track_line)
  }

  correct_gr <- createCorrectGR(Seqinfo(c("chr19", "chr18")))
  correct_ucsc <- createCorrectUCSC(correct_gr)

  ## TEST: basic import
  test <- import(test_wig)
  checkIdentical(correct_ucsc, test)
  test <- import.wig(test_wig)
  checkIdentical(correct_ucsc, test)
  test_wig_file <- WIGFile(test_wig)
  checkException(import(test_wig_file, format = "bed"))
  test <- import(test_wig_file, format = "wig")
  checkIdentical(correct_ucsc, test)
  test <- import(test_wig_file)
  checkIdentical(correct_ucsc, test)
  test_wig_con <- file(test_wig)
  test <- import(test_wig_con, format = "wig")
  checkIdentical(correct_ucsc, test)
  test_wig_con <- file(test_wig)
  test <- import(WIGFile(test_wig_con))
  checkIdentical(correct_ucsc, test)
  
  ## TEST: 'genome'
  hg19_seqinfo <- SeqinfoForBSGenome("hg19")
  correct_genome <- createCorrectUCSC(createCorrectGR(hg19_seqinfo))
  test <- import(test_wig, genome = "hg19")
  checkIdentical(correct_genome, test)

  ## TEST: trackLine = FALSE
  test <- import(test_wig, trackLine = FALSE)
  checkIdentical(correct_gr, test)

  ## TEST: which
  which <- correct_gr[3:4]
  correct_which <- subsetByOverlaps(correct_ucsc, which)
  test <- import(test_wig, which = which)
  checkIdentical(correct_which, test)

  ## TEST: basic export
  test_wig_out <- file.path(tempdir(), "test.wig")
  on.exit(unlink(test_wig_out))
  export(correct_ucsc, test_wig_out)
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc, test)

  export.wig(correct_ucsc, test_wig_out)
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc, test)
  test_foo_out <- file.path(tempdir(), "test.foo")
  export(correct_ucsc, test_foo_out, format = "wig")
  on.exit(unlink(test_foo_out))
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc, test)
  test_wig_out_file <- WIGFile(test_wig_out)
  export(correct_ucsc, test_wig_out_file)
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc, test)
  checkException(export(correct_ucsc, test_wig_out_file, format = "gff"))

  ## TEST: append
  correct_ucsc2 <- initialize(correct_ucsc,
                              trackLine = initialize(correct_ucsc@trackLine,
                                                     name = "test2"))
  export(correct_ucsc2, test_wig_out_file, append = TRUE)
  test <- import(test_wig_out_file)
  correct_list <- GenomicRangesList(test = correct_ucsc,
                                    test2 = correct_ucsc2)
  checkIdentical(correct_list, test)

  ## TEST: track line parameters
  export(correct_ucsc, test_wig_out, name = "test2")
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc2, test)

  ## TEST: export trackLine
  export(correct_ucsc, test_wig_out, trackLine = FALSE)
  test <- import(test_wig_out)
  checkIdentical(test, correct_gr)

  ## TEST: Plain GRanges / bedGraph
  export.ucsc(correct_gr, test_wig_out) # mixture of steps leads to bedGraph
  test <- import(test_wig_out)
  default_line <- new("GraphTrackLine", name = "R Track", type = "bedGraph")
  correct_default <- new("UCSCData", correct_gr, trackLine = default_line)
  checkIdentical(test, correct_default)
  correct_chr18 <- keepSeqlevels(correct_gr, "chr18", pruning.mode="coarse")
  export.ucsc(correct_chr18, test_wig_out)
  test <- import(test_wig_out)
  default_line <- new("GraphTrackLine", name = "R Track", type = "wig")
  correct_default <- new("UCSCData",
                         keepSeqlevels(correct_gr, "chr18",
                                       pruning.mode="coarse"),
                         trackLine = default_line)
  checkIdentical(test, correct_default)
  
  ## TEST: GenomicRangesList
  export(correct_list, test_wig_out)
  test <- import(test_wig_out)
  checkIdentical(correct_list, test)
  
  ## TEST: gzip
  test_wig_gz <- paste(test_wig_out, ".gz", sep = "")
  on.exit(unlink(test_wig_gz))
  export(correct_ucsc, test_wig_gz)
  test <- import(test_wig_gz)
  checkIdentical(correct_ucsc, test)
  export(correct_ucsc2, test_wig_gz, append = TRUE)
  test <- import(test_wig_gz)
  checkIdentical(correct_list, test)
  
  ## TEST: Using connection to add comment header
  test_wig_con <- file(test_wig_out)
  open(test_wig_con, "w")
  comment <- "# test comment"
  writeLines(comment, test_wig_con)
  export(correct_ucsc, test_wig_con)
  close(test_wig_con)
  checkIdentical(comment, readLines(test_wig_out, n = 1))
  test <- import(test_wig_out)
  checkIdentical(correct_ucsc, test)
}