## example 1: Importing specific ranges of records
file <- system.file("extdata", "SRR002051.chrI-V.bam",
package="yeastNagalakshmi")
which <- GRanges("chrI", IRanges(1, 2e5))
s <- Snapshot(file, range=which)
## methods
zoom(s) # zoom in
## zoom in to a specific region
zoom(s, range=GRanges("chrI", IRanges(7e4, 7e4+8000)))
pan(s) # pan right
togglez(s) # change effect of zooming
zoom(s) # zoom out
togglep(s) # change effect of panning
pan(s)
## accessors
functions(s)
vrange(s)
show(s)
ignore.strand(s)
view(s) ## extract the spTrellis object
getTrellis(s) ## extract the trellis object
## example 2: ignore strand
s <- Snapshot(file, range=which, ignore.strand=TRUE)
##
## example 3: visualizing annotation track
##
library(GenomicFeatures)
getAnnGR <- function(txdb, which) {
ex <- exonsBy(txdb, by="gene")
seqlevels(ex, force=TRUE) <- seqlevels(which)
r <- range(ex)
gr <- unlist(r)
values(gr)[["gene_id"]] <- rep.int(names(r), times=lengths(r))
gr
}
txdbFile <- system.file("extdata", "sacCer2_sgdGene.sqlite",
package="yeastNagalakshmi")
# txdb <- makeTxDbFromUCSC(genome="sacCer2", tablename="sgdGene")
txdb <- loadDb(txdbFile)
which <- GRanges("chrI", IRanges(1, 2e5))
gr <- getAnnGR(txdb, which)
## note that the first column of the elementMetadata annotates of the
## range of the elements.
gr
s <- Snapshot(file, range=which, annTrack=gr)
annTrack(s)
## zoom in to an interesting region
zoom(s, range=GRanges("chrI", IRanges(7e4, 7e4+8000)))
togglez(s) ## zoom out
zoom(s)
pan(s)
## example 4, 5, 6: multiple BAM files with 'multicoarse_covarage'
## and 'multifine_coverage' view.
## Resolution does not automatically switch for views of multiple
## files. It is important to note if width(which) < 10,000, use
## multifine_coverage. Otherwise use multicoarse_coverage
file <- system.file("extdata", "SRR002051.chrI-V.bam",
package="yeastNagalakshmi")
which <- GRanges("chrI", IRanges(1, 2e5))
s <- Snapshot(c(file, file), range=which,
currentFunction="multicoarse_coverage")
## grouping files and view by 'multicoarse_coverage'
bfiles <- BamFileList(c(a=file, b=file))
values(bfiles) <- DataFrame(sampleGroup=factor(c("normal", "tumor")))
values(bfiles)
s <- Snapshot(bfiles, range=which,
currentFunction="multicoarse_coverage", fac="sampleGroup")
## grouping files and view by 'multifine_coverage'
which <- GRanges("chrI", IRanges(7e4, 7e4+8000))
s <- Snapshot(bfiles, range=which,
currentFunction="multifine_coverage", fac="sampleGroup")
Run the code above in your browser using DataLab