Composite track is a way to combine multiple types of features into one track. A composite track can be constructed by combining a list of different tracks with function merge
.
Label, background and height of the composite track will be derived from the component tracks and can be further accessed and modified with trackSpec
and trackSpec<-
.
suppressPackageStartupMessages({
library(TnT)
library(GenomicFeatures)
library(AnnotationHub)
})
set.seed(42)
First to construct a block track and a pin track from data.
gr <- GRanges("chr1", IRanges(c(11000, 20000, 60000), width = 2000))
gpos <- GRanges("chr1", IRanges(c(12000, 21000, 61000), width = 1), value = c(1, 2, 3))
btrack <- TnT::BlockTrack(gr, label = "Block Track", tooltip = as.data.frame(gr), color = "lightblue4")
ptrack <- TnT::PinTrack(gpos, label = "Pin Track", tooltip = as.data.frame(gpos), background = "beige")
Then use merge
to construct a composite track and showing it.
ctrack <- TnT::merge(btrack, ptrack)
TnTBoard(ctrack)
## - Missing argument `view.range`:
## automatically select 4625..68374 on seqlevel chr1...
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to 71..72927 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
Be aware that the components in a composite track are rendered according to the order in merge
. For example, the block track will cover the pin track if we switch the order.
TnTBoard(merge(ptrack, btrack)) # the pin track has been covered
## - Missing argument `view.range`:
## automatically select 4625..68374 on seqlevel chr1...
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to 71..72927 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
Show all three tracks and add axis indicator.
TnTGenome(list(ctrack, ptrack, btrack))
## - Missing argument `view.range`:
## automatically select 5875..67125 on seqlevel chr1...
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to 71..72927 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
gtrack <- TnT::GeneTrackFromTxDb(txdb, label = "Gene", color = "burlywood3")
ah <- AnnotationHub()
## snapshotDate(): 2017-10-27
ah <- query(ah, "cpgisland")
cpg <- ah[[names(ah[ah$genome == "hg19"])]]
## loading from cache '/home/jialin//.AnnotationHub/5086'
cpgtrack <- TnT::BlockTrack(cpg, label = "CpG Islands", tooltip = as.data.frame(cpg),
color = "lightblue")
TnTGenome(merge(cpgtrack, gtrack),
view.range = GRanges("chr1", IRanges(84884317, 85205497)))
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'