Skip to content

Instantly share code, notes, and snippets.

@ngopal
Last active August 29, 2015 14:09
Applying A Divergent Color Scale to A Gene Expression Heat Map
# Blog Post is here: http://www.nikhilgopal.com/applying-a-divergent-color-scale-to-a-gene-expression-heat-map/
source("http://bioconductor.org/biocLite.R")
biocLite("ALL")
biocLite("limma")
library("ALL")
library("limma")
data("ALL")
eset <- ALL[, ALL$mol.biol %in% c("BCR/ABL", "ALL1/AF4")]
heatmap(exprs(eset[1:100,]))
f <- factor(as.character(eset$mol.biol))
design <- model.matrix(~f)
fit <- eBayes(lmFit(eset,design))
topTable(fit, coef=2)
selected <- p.adjust(fit$p.value[, 2]) <0.05
esetSel <- eset [selected, ]
heatmap(exprs(esetSel))
heatmap(exprs(esetSel), col=topo.colors(100))
color.map <- function(mol.biol) { if (mol.biol=="ALL1/AF4") "#FF0000" else "#0000FF" }
patientcolors <- unlist(lapply(esetSel$mol.bio, color.map))
heatmap(exprs(esetSel), col=topo.colors(100), ColSideColors=patientcolors)
library("gplots")
heatmap.2(exprs(esetSel), col=topo.colors(10), scale="none", ColSideColors=patientcolors,
key=TRUE, symkey=FALSE, density.info="none", trace="none", cexRow=0.5) #generates old heatmap = old10scale.jpg
library(RColorBrewer)
brewer.pal(n=10, name="RdBu")
heatmap(exprs(esetSel), col=brewer.pal(n=10, name="RdBu")) #generates divergent scale heatmap = new.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment