## ---------------------------------------------------------------------
## shift()
## ---------------------------------------------------------------------
## On a Ranges object:
ir1 <- successiveIRanges(c(19, 5, 0, 8, 5))
ir1
shift(ir1, shift=-3)
## On a RangesList object:
range1 <- IRanges(start=c(1, 2, 3), end=c(5, 2, 8))
range2 <- IRanges(start=c(15, 45, 20, 1), end=c(15, 100, 80, 5))
range3 <- IRanges(start=c(-2, 6, 7), width=c(8, 0, 0)) # with empty ranges
collection <- IRangesList(one=range1, range2, range3)
shift(collection, shift=5) # same as endoapply(collection, shift, shift=5)
## Sanity check:
res1 <- shift(collection, shift=5)
res2 <- endoapply(collection, shift, shift=5)
stopifnot(identical(res1, res2))
## ---------------------------------------------------------------------
## narrow()
## ---------------------------------------------------------------------
## On a Ranges object:
ir2 <- ir1[width(ir1) != 0]
narrow(ir2, start=4, end=-2)
narrow(ir2, start=-4, end=-2)
narrow(ir2, end=5, width=3)
narrow(ir2, start=c(3, 4, 2, 3), end=c(12, 5, 7, 4))
## On a RangesList object:
narrow(collection[-3], start=2)
narrow(collection[-3], end=-2)
## On a MaskCollection object:
mask1 <- Mask(mask.width=29, start=c(11, 25, 28), width=c(5, 2, 2))
mask2 <- Mask(mask.width=29, start=c(3, 10, 27), width=c(5, 8, 1))
mask3 <- Mask(mask.width=29, start=c(7, 12), width=c(2, 4))
mymasks <- append(append(mask1, mask2), mask3)
mymasks
narrow(mymasks, start=8)
## ---------------------------------------------------------------------
## resize()
## ---------------------------------------------------------------------
## On a Ranges object:
resize(ir2, 200)
resize(ir2, 2, fix="end")
## On a RangesList object:
resize(collection, width=200)
## ---------------------------------------------------------------------
## flank()
## ---------------------------------------------------------------------
## On a Ranges object:
ir3 <- IRanges(c(2,5,1), c(3,7,3))
flank(ir3, 2)
flank(ir3, 2, start=FALSE)
flank(ir3, 2, start=c(FALSE, TRUE, FALSE))
flank(ir3, c(2, -2, 2))
flank(ir3, 2, both = TRUE)
flank(ir3, 2, start=FALSE, both=TRUE)
flank(ir3, -2, start=FALSE, both=TRUE)
## On a RangesList object:
flank(collection, width=10)
## ---------------------------------------------------------------------
## promoters()
## ---------------------------------------------------------------------
## On a Ranges object:
ir4 <- IRanges(20:23, width=3)
promoters(ir4, upstream=0, downstream=0) ## no change
promoters(ir4, upstream=0, downstream=1) ## start value only
promoters(ir4, upstream=1, downstream=0) ## single upstream nucleotide
## On a RangesList object:
promoters(collection, upstream=5, downstream=2)
## ---------------------------------------------------------------------
## reflect()
## ---------------------------------------------------------------------
## On a Ranges object:
bounds <- IRanges(c(0, 5, 3), c(10, 6, 9))
reflect(ir3, bounds)
## reflect() does not yet support RangesList objects!
## ---------------------------------------------------------------------
## restrict()
## ---------------------------------------------------------------------
## On a Ranges object:
restrict(ir1, start=12, end=34)
restrict(ir1, start=20)
restrict(ir1, start=21)
restrict(ir1, start=21, keep.all.ranges=TRUE)
## On a RangesList object:
restrict(collection, start=2, end=8)
## ---------------------------------------------------------------------
## threebands()
## ---------------------------------------------------------------------
## On a Ranges object:
z <- threebands(ir2, start=4, end=-2)
ir2b <- punion(z$left, z$right, fill.gap=TRUE)
stopifnot(identical(ir2, ir2b))
threebands(ir2, start=-5)
## threebands() does not support RangesList objects.
Run the code above in your browser using DataLab