Tooltip can be specified by supplying a data frame when constructing the track and it can be modified after the track is constructed.

By default, when constructing a track from GRanges/IRanges, the tooltip is converted from the “meta-columns” of GRanges/IRanges, i.e. mcols(d).

suppressPackageStartupMessages({
    library(TnT)
    library(GenomicFeatures)
    library(TxDb.Hsapiens.UCSC.hg19.knownGene)
    library(org.Hs.eg.db)
})
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene

Basic Example using BlockTrack

Click on the block to see the tooltip.

myIRanges <- IRanges(c(10, 100, 1000), width = c(30, 50, 500))
mytooltip <- as.data.frame(myIRanges)
myTrack <- TnT::BlockTrack(myIRanges, tooltip = mytooltip)
#TnTBoard(myTrack, IRanges(1, 2000))
TnTBoard(myTrack, GRanges("UnKnown", IRanges(1, 2000)))
## - Missing argument `coord.range` and seqlength is unknown:
##   automatically set coordinate limit to -309..1818 ...
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'



Modify Tooltip of a Constructed Track

First, construct a gene track from the TxDb object.

geneTrack <- TnT::GeneTrackFromTxDb(txdb, height = 300)

We can extract and replace the tooltip with tooltip and tooltip<-. In this case, we use the organism database to find the corresponding gene names of every gene, then add them to the tooltip.

head(df.tooltip <- TnT::tooltip(geneTrack))
##     gene_id
## 1         1
## 2        10
## 3       100
## 4      1000
## 5     10000
## 6 100008586
genename <- AnnotationDbi::select(org.Hs.eg.db, as.character(df.tooltip$gene_id),
                      columns = "SYMBOL", keytype = "ENTREZID")
## 'select()' returned 1:1 mapping between keys and columns
df.tooltip$gene_symbol <- genename$SYMBOL[match(df.tooltip$gene_id, genename$ENTREZID)]
TnT::tooltip(geneTrack) <- df.tooltip
head(TnT::tooltip(geneTrack))
##     gene_id gene_symbol
## 1         1        A1BG
## 2        10        NAT2
## 3       100         ADA
## 4      1000        CDH2
## 5     10000        AKT3
## 6 100008586     GAGE12F

We can also modify the label to show gene symbol instead of entrez ID.

geneTrack$display_label <- TnT::strandlabel(TnT::tooltip(geneTrack)$gene_symbol,
                                            strand(TnT::trackData(geneTrack)))

Click to see the tooltip.

TnTGenome(geneTrack, GRanges("chrX", IRanges(100000, 10000000)))
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'



Use Sub-headers in Tooltip

Columns of empty strings will be regarded as subsection titles, for example:

head(df.tooltip)
##     gene_id gene_symbol
## 1         1        A1BG
## 2        10        NAT2
## 3       100         ADA
## 4      1000        CDH2
## 5     10000        AKT3
## 6 100008586     GAGE12F
df.tooltip <- cbind(
    data.frame(`Identity` = ""),
    df.tooltip[c("gene_id", "gene_symbol")]
)

Click to see.

TnT::tooltip(geneTrack) <- df.tooltip
TnTGenome(geneTrack, GRanges("chrX", IRanges(100000, 10000000)))
## Warning in readLines(con): incomplete final line found on '/home/jialin/R/
## x86_64-suse-linux-gnu-library/3.4/TnT/htmlwidgets/trackWidget.yaml'



Session Info

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] org.Hs.eg.db_3.4.1                     
##  [2] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
##  [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] SummarizedExperiment_1.8.1 progress_1.1.2            
##  [3] lattice_0.20-35            colorspace_1.3-2          
##  [5] htmltools_0.3.6            rtracklayer_1.38.3        
##  [7] yaml_2.1.19                blob_1.1.1                
##  [9] XML_3.98-1.10              rlang_0.2.0.9001          
## [11] pkgdown_1.0.0              DBI_0.8                   
## [13] BiocParallel_1.12.0        bit64_0.9-7               
## [15] matrixStats_0.52.2         GenomeInfoDbData_1.0.0    
## [17] stringr_1.3.0              zlibbioc_1.24.0           
## [19] Biostrings_2.46.0          commonmark_1.4            
## [21] htmlwidgets_1.2            memoise_1.1.0             
## [23] evaluate_0.10.1            knitr_1.20                
## [25] biomaRt_2.34.2             Rcpp_0.12.16              
## [27] backports_1.1.2-9000       DelayedArray_0.4.1        
## [29] desc_1.2.0                 jsonlite_1.5              
## [31] XVector_0.18.0             fs_1.2.2                  
## [33] bit_1.1-12                 Rsamtools_1.30.0          
## [35] RMySQL_0.10.14             digest_0.6.15             
## [37] stringi_1.2.2              grid_3.4.1                
## [39] rprojroot_1.3-2            tools_3.4.1               
## [41] bitops_1.0-6               magrittr_1.5              
## [43] RCurl_1.95-4.10            RSQLite_2.1.0             
## [45] pkgconfig_2.0.1            crayon_1.3.4              
## [47] Matrix_1.2-10              MASS_7.3-47               
## [49] xml2_1.1.1                 prettyunits_1.0.2         
## [51] assertthat_0.2.0           rmarkdown_1.9             
## [53] roxygen2_6.0.1             httr_1.3.1                
## [55] R6_2.2.2                   GenomicAlignments_1.14.2  
## [57] compiler_3.4.1