Skip to content

Instantly share code, notes, and snippets.

@bobthecat
Created May 17, 2012 07:07
Show Gist options
  • Save bobthecat/2717123 to your computer and use it in GitHub Desktop.
Save bobthecat/2717123 to your computer and use it in GitHub Desktop.
GO_heatmap
library(org.Mm.eg.db); library(gplots); library(bioDist)
# get gene in GO cat
gGOcat <- list()
for(i in 1:dim(mrnaGO)[1]){
gGOcat[[mrnaGO$GOBPID[i]]] <- as.vector(unlist(mget(mrnaGO$GOBPID[i], org.Mm.egGO2ALLEGS)))
}
# filter each GO cat by the genes found to be DE
f <- function(vecGO, vecDE){
return(vecGO[which(vecGO %in% vecDE)])
}
gGOcat <- lapply(gGOcat, FUN=function(x){f(x, glist)})
mat <- matrix(nrow=length(gGOcat), ncol=length(gGOcat))
for(i in 1:length(gGOcat)) {
for(j in 1:length(gGOcat)) {
# intersect / union
mat[i,j] <- (length(intersect(gGOcat[[i]], gGOcat[[j]])) / length(union(gGOcat[[i]], gGOcat[[j]])))
}
}
rownames(mat) <- names(gGOcat)
colnames(mat) <- names(gGOcat)
goNames <- as.vector(unlist(mget(names(gGOcat), GOTERM)))
goNames <- as.vector(unlist(lapply(goNames, FUN=function(x){x@Term})))
goNames <- paste(goNames, names(gGOcat), sep=" - ")
colnames(mat) <- goNames
rownames(mat) <- goNames
# color scale
c1 <- rainbow(32,v=seq(0.5,1,length=32),s=seq(1,0.3,length=32),start=4/6,end=4.0001/6);
pie(rep(1,32),col=c1); # show off these colors
c2 <- rainbow(32,v=seq(0.5,1,length=32),s=seq(1,0.3,length=32),start=1/6,end=1.0001/6);
pie(rep(1,32),col=c2); # show off these colors
c3 <- c(c1,rev(c2)); # rev reverses the list
rm(c1,c2)
pdf(file='GO_heatmap.pdf', height=13, width=13)
heatmap.2(mat, col=c3, margins = c(20, 20), dist=function(x){cor.dist(x)}, trace='none', density.info='none', cexRow=0.5, cexCol=0.5)
dev.off()
# keep it clean
rm(mat, goNames, gGOcat, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment