Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
103 lines (71 sloc) 2.34 KB
---
title: "Tooltip Display in Tracks"
---
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)`.
```{r}
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.
```{r}
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)))
```
<br/> <br/>
## Modify Tooltip of a Constructed Track
First, construct a gene track from the TxDb object.
```{r}
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.
```{r}
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.
```{r}
geneTrack$display_label <- TnT::strandlabel(TnT::tooltip(geneTrack)$gene_symbol,
strand(TnT::trackData(geneTrack)))
```
Click to see the tooltip.
```{r}
TnTGenome(geneTrack, GRanges("chrX", IRanges(100000, 10000000)))
```
<br/> <br/>
## Use Sub-headers in Tooltip
Columns of empty strings will be regarded as subsection titles, for example:
```{r}
head(df.tooltip)
df.tooltip <- cbind(
data.frame(`Identity` = ""),
df.tooltip[c("gene_id", "gene_symbol")]
)
```
Click to see.
```{r}
TnT::tooltip(geneTrack) <- df.tooltip
TnTGenome(geneTrack, GRanges("chrX", IRanges(100000, 10000000)))
```
<br/> <br/>
## Session Info
```{r}
sessionInfo()
```
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.