## ---------------------------------------------------------------------
## A. WITH A TOY GENOME
## ---------------------------------------------------------------------
seqlengths <- c(chr1=60, chr2=20, chr3=25)
## Create 5 tiles:
tiles <- tileGenome(seqlengths, ntile=5)
tiles
elementNROWS(tiles) # tiles 3 and 4 contain 2 ranges
width(tiles)
## Use sum() on this IntegerList object to get the effective tile
## widths:
sum(width(tiles)) # each tile covers exactly 21 genomic positions
## Create 9 tiles:
tiles <- tileGenome(seqlengths, ntile=9)
elementNROWS(tiles) # tiles 6 and 7 contain 2 ranges
table(sum(width(tiles))) # some tiles cover 12 genomic positions,
# others 11
## Specify the tile width:
tiles <- tileGenome(seqlengths, tilewidth=20)
length(tiles) # 6 tiles
table(sum(width(tiles))) # effective tile width is <= specified
## Specify the tile width and cut the last tile in each chromosome:
tiles <- tileGenome(seqlengths, tilewidth=24,
cut.last.tile.in.chrom=TRUE)
tiles
width(tiles) # each tile covers exactly 24 genomic positions, except
# the last tile in each chromosome
## Partition a genome by chromosome ("natural partitioning"):
tiles <- tileGenome(seqlengths, tilewidth=max(seqlengths),
cut.last.tile.in.chrom=TRUE)
tiles # one tile per chromosome
## sanity check
stopifnot(all.equal(setNames(end(tiles), seqnames(tiles)), seqlengths))
## ---------------------------------------------------------------------
## B. WITH A REAL GENOME
## ---------------------------------------------------------------------
library(BSgenome.Scerevisiae.UCSC.sacCer2)
tiles <- tileGenome(seqinfo(Scerevisiae), ntile=20)
tiles
tiles <- tileGenome(seqinfo(Scerevisiae), tilewidth=50000,
cut.last.tile.in.chrom=TRUE)
tiles
## ---------------------------------------------------------------------
## C. AN APPLICATION: COMPUTE THE BINNED AVERAGE OF A NUMERICAL VARIABLE
## DEFINED ALONG A GENOME
## ---------------------------------------------------------------------
## See '?genomicvars' for an example of how to compute the binned
## average of a numerical variable defined along a genome.
Run the code above in your browser using DataLab