Colors of Track

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)
})

R Color Names

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)



Use Color Palettes

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

You can use color palette to change the mapping of colors.

grDevices::palette(grDevices::rainbow(6))
board
grDevices::palette(grDevices::terrain.colors(6))
board

Gene Colors

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)

Session Info

sessionInfo()


Try the TnT package in your browser

Any scripts or data that you put into this service are public.

TnT documentation built on Nov. 8, 2020, 8:11 p.m.