Intro

This function is written with chromosome maps in mind but generalized for visualizing much more. All that is required is a data frame of segmants with columns called band, start, end.

In the future, I plan to keep it as generalized as possible, maximizing its flexibility and application in various types of analyses. Feel free to suggest ideas, report bugs, or contribute!

Source

library(bands)

Human gene locations

chromosomes <- c(paste("chr", 1:21, sep=""), "chrX", "chrY", "chrM")
df <- read.table('data/df.txt', sep="\t", header=TRUE, stringsAsFactors=FALSE)

Default plot

df.1 <- df[sample(1:nrow(df), 2500, replace=F),]
head(df.1)
       band     start       end      name
32065 chr17  50834649  50841308      SKA2
7731   chr3 150602874 150627831   C3orf80
36145 chr20  63908954  63909119      LTN1
5221   chr2 165833047 165839098    GTF3C3
34996 chr19  55230884  55230952   MIR518C
20514 chr10  31756041  31756136 LRRC37A6P
draw.bands(df.1, chromosomes, labels=F)

Add colors to highlight regions of interest

df.2 <- df.1
df.2$color <- ifelse(sample(c(T, T, T, F), 2500, replace=T), "grey", "firebrick")
head(df.2)
       band     start       end      name     color
32065 chr17  50834649  50841308      SKA2      grey
7731   chr3 150602874 150627831   C3orf80 firebrick
36145 chr20  63908954  63909119      LTN1      grey
5221   chr2 165833047 165839098    GTF3C3      grey
34996 chr19  55230884  55230952   MIR518C      grey
20514 chr10  31756041  31756136 LRRC37A6P      grey
draw.bands(df.2, chromosomes, labels=F)

Add names for hover info

df.3 <- head(df.2, 500)
head(df.3)
       band     start       end      name     color
32065 chr17  50834649  50841308      SKA2      grey
7731   chr3 150602874 150627831   C3orf80 firebrick
36145 chr20  63908954  63909119      LTN1      grey
5221   chr2 165833047 165839098    GTF3C3      grey
34996 chr19  55230884  55230952   MIR518C      grey
20514 chr10  31756041  31756136 LRRC37A6P      grey
draw.bands(df.3, chromosomes, labels=T)