Colors of features in a track can be specified with a character vector or a positive integer vector which will be expanded to the same length of track data. The values will be part of the track data and can be modified after the track is constructed.
suppressPackageStartupMessages({
library(TnT)
library(GenomicFeatures)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
})
This example shows all available color names in R with a block track.
colors <- colors()
data <- GRanges("Unknown", IRanges(seq_along(colors), width = 2), "Color Name" = colors)
track <- TnT::BlockTrack(data, color = data$"Color Name", label = NULL)
TnT::TnTBoard(track)
## - Missing argument `view.range`:
## automatically select -81..740 on seqlevel Unknown...
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to -140..799 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
Colors can be also specified with a positive integer vector i
, meaning palette()[i]
, as in R base graphics.
data <- GRanges("Unknown", IRanges(1:6, width = 2), "Color" = 1:6)
track <- TnT::BlockTrack(data, color = data$"Color", label = NULL)
board <- TnT::TnTBoard(track, view.range = range(data))
board
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to -1..8 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
You can use color palette to change the mapping of colors.
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to -1..8 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
grDevices::palette(grDevices::terrain.colors(6))
board
## - Missing argument `coord.range` and seqlength is unknown:
## automatically set coordinate limit to -1..8 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'
This example shows a gene track that genes have different colors based on their biotypes.
First is to get the data from EnsDb.
suppressPackageStartupMessages(
library(EnsDb.Hsapiens.v75)
)
gene <- genes(EnsDb.Hsapiens.v75)
In the track constructor, specify the colors of features by converting the gene_biotype
to integer vector. Then set the color palette and build the browser.
genetrack <- TnT::FeatureTrack(gene, tooltip = as.data.frame(gene),
color = as.integer(factor(gene$gene_biotype)))
# Set color palette
palette(terrain.colors(length(unique(gene$gene_biotype))))
TnT::TnTGenome(genetrack, view.range = gene[gene$symbol == "BRCA2"][1] * .5)
## 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] EnsDb.Hsapiens.v75_2.99.0
## [2] ensembldb_2.1.13
## [3] AnnotationFilter_1.1.9
## [4] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
## [5] GenomicFeatures_1.30.3
## [6] AnnotationDbi_1.40.0
## [7] Biobase_2.38.0
## [8] TnT_1.3.1
## [9] GenomicRanges_1.30.3
## [10] GenomeInfoDb_1.14.0
## [11] IRanges_2.12.0
## [12] S4Vectors_0.16.0
## [13] BiocGenerics_0.24.0
##
## loaded via a namespace (and not attached):
## [1] httr_1.3.1 RMySQL_0.10.14
## [3] bit64_0.9-7 jsonlite_1.5
## [5] AnnotationHub_2.9.17 shiny_1.0.5
## [7] assertthat_0.2.0 interactiveDisplayBase_1.15.0
## [9] blob_1.1.1 GenomeInfoDbData_1.0.0
## [11] Rsamtools_1.30.0 yaml_2.1.19
## [13] progress_1.1.2 RSQLite_2.1.0
## [15] backports_1.1.2-9000 lattice_0.20-35
## [17] digest_0.6.15 XVector_0.18.0
## [19] colorspace_1.3-2 htmltools_0.3.6
## [21] httpuv_1.3.6.2 Matrix_1.2-10
## [23] XML_3.98-1.10 pkgconfig_2.0.1
## [25] biomaRt_2.34.2 zlibbioc_1.24.0
## [27] xtable_1.8-2 BiocParallel_1.12.0
## [29] SummarizedExperiment_1.8.1 lazyeval_0.2.1
## [31] magrittr_1.5 crayon_1.3.4
## [33] mime_0.5 memoise_1.1.0
## [35] evaluate_0.10.1 fs_1.2.2
## [37] MASS_7.3-47 xml2_1.1.1
## [39] BiocInstaller_1.28.0 tools_3.4.1
## [41] prettyunits_1.0.2 matrixStats_0.52.2
## [43] stringr_1.3.0 DelayedArray_0.4.1
## [45] Biostrings_2.46.0 compiler_3.4.1
## [47] pkgdown_1.0.0 rlang_0.2.0.9001
## [49] grid_3.4.1 RCurl_1.95-4.10
## [51] htmlwidgets_1.2 bitops_1.0-6
## [53] rmarkdown_1.9 curl_3.2
## [55] DBI_0.8 roxygen2_6.0.1
## [57] R6_2.2.2 GenomicAlignments_1.14.2
## [59] knitr_1.20 rtracklayer_1.38.3
## [61] bit_1.1-12 commonmark_1.4
## [63] rprojroot_1.3-2 ProtGenerics_1.9.1
## [65] desc_1.2.0 stringi_1.2.2
## [67] Rcpp_0.12.16