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
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)))
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)) genename <- AnnotationDbi::select(org.Hs.eg.db, as.character(df.tooltip$gene_id), columns = "SYMBOL", keytype = "ENTREZID") df.tooltip$gene_symbol <- genename$SYMBOL[match(df.tooltip$gene_id, genename$ENTREZID)] TnT::tooltip(geneTrack) <- df.tooltip head(TnT::tooltip(geneTrack))
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)))
Columns of empty strings will be regarded as subsection titles, for example:
head(df.tooltip) 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)))
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.