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'
sessionInfo()
## R version 3.4.1 (2017-06-30)
## Platform: x86_64-suse-linux-gnu (64-bit)
## Running under: openSUSE Tumbleweed
##
## Matrix products: default
## BLAS: /usr/lib64/R/lib/libRblas.so
## LAPACK: /usr/lib64/R/lib/libRlapack.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] parallel stats4 methods stats graphics grDevices utils
## [8] datasets base
##
## other attached packages:
## [1] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
## [2] AnnotationHub_2.9.17
## [3] GenomicFeatures_1.30.3
## [4] AnnotationDbi_1.40.0
## [5] Biobase_2.38.0
## [6] TnT_1.3.1
## [7] GenomicRanges_1.30.3
## [8] GenomeInfoDb_1.14.0
## [9] IRanges_2.12.0
## [10] S4Vectors_0.16.0
## [11] BiocGenerics_0.24.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.16 lattice_0.20-35
## [3] prettyunits_1.0.2 Rsamtools_1.30.0
## [5] Biostrings_2.46.0 assertthat_0.2.0
## [7] rprojroot_1.3-2 digest_0.6.15
## [9] mime_0.5 R6_2.2.2
## [11] backports_1.1.2-9000 RSQLite_2.1.0
## [13] evaluate_0.10.1 BiocInstaller_1.28.0
## [15] httr_1.3.1 zlibbioc_1.24.0
## [17] rlang_0.2.0.9001 progress_1.1.2
## [19] curl_3.2 blob_1.1.1
## [21] Matrix_1.2-10 rmarkdown_1.9
## [23] pkgdown_1.0.0 desc_1.2.0
## [25] RMySQL_0.10.14 BiocParallel_1.12.0
## [27] stringr_1.3.0 htmlwidgets_1.2
## [29] RCurl_1.95-4.10 bit_1.1-12
## [31] biomaRt_2.34.2 shiny_1.0.5
## [33] DelayedArray_0.4.1 compiler_3.4.1
## [35] httpuv_1.3.6.2 rtracklayer_1.38.3
## [37] pkgconfig_2.0.1 htmltools_0.3.6
## [39] SummarizedExperiment_1.8.1 GenomeInfoDbData_1.0.0
## [41] interactiveDisplayBase_1.15.0 roxygen2_6.0.1
## [43] matrixStats_0.52.2 XML_3.98-1.10
## [45] crayon_1.3.4 GenomicAlignments_1.14.2
## [47] MASS_7.3-47 bitops_1.0-6
## [49] commonmark_1.4 grid_3.4.1
## [51] xtable_1.8-2 jsonlite_1.5
## [53] DBI_0.8 magrittr_1.5
## [55] stringi_1.2.2 XVector_0.18.0
## [57] fs_1.2.2 xml2_1.1.1
## [59] tools_3.4.1 bit64_0.9-7
## [61] yaml_2.1.19 colorspace_1.3-2
## [63] memoise_1.1.0 knitr_1.20