Last active
December 26, 2015 02:39
-
-
Save sirusb/81f3f180b08a16a8ac2f to your computer and use it in GitHub Desktop.
This script is to read a CSV file that contain a list of genes in HGNC format in each column and will plot the GO enrichment analysis using DAVID webservice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DoDAVIDGOAnnotation <-function(topics,pval=0.05,GOlimit=5){ | |
clusters<-1:ncol(topics) | |
Groups<-c(); | |
Annot<-c(); | |
pvalue<-c(); | |
counts<-c(); | |
for(clus in clusters){ | |
#Get the genes in that cluster | |
inCluster<-as.character(topics[,clus]); | |
inCluster<-inCluster[inCluster!=""]; | |
#Get GO enrichment from DAVID | |
dav<-DAVIDQuery(ids=inCluster,type="OFFICIAL_GENE_SYMBOL",annot="GOTERM_BP_ALL",tool="chartReport",URLlengthLimit = 102400); | |
if(length(dav$downloadFileName)>0){ | |
dav$DAVIDQueryResult$Benjamini<-as.double(dav$DAVIDQueryResult$Benjamini); | |
sigGO<-subset(dav$DAVIDQueryResult[-1,], Benjamini <= pval); | |
#if we have some significant annotation | |
if(nrow(sigGO)>0){ | |
if(nrow(sigGO)>GOlimit ) {sigGO<-sigGO[1:GOlimit,] } | |
#anot<-as.character( paste( sigGO$Term, "(" , sigGO$Count, ")", sep="") ) | |
#Annot<-c(Annot,anot) | |
Annot<-c(Annot,sigGO$Term) | |
sigGO$Count<-as.integer(sigGO$Count) | |
counts<-c(counts,sigGO$Count/length(inCluster)) | |
gr<-paste(clus,"(",length(inCluster),")",sep="") | |
Groups<-c(Groups,rep(gr,length(sigGO$Term))); | |
pvalue<-c(pvalue,sigGO$Benjamini); | |
} | |
} | |
Sys.sleep(10) | |
} | |
result<-data.frame(Cluster=factor(Groups),GO=Annot,pvalue=as.double(pvalue),Count=as.double(counts)); | |
return(result); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DavidGOAnalysis <- function(topics,pval=0.05,path="."){ | |
require(ggplot2) | |
require(DAVIDQuery) | |
DavRes<-DoDAVIDGOAnnotation(topics,pval); | |
pngName<-file.path(path,"DavidGOEnrich.png"); | |
if(nrow(DavRes)){ | |
ggplot(DavRes, aes(x=Cluster, y=GO,colour=pvalue)) + | |
geom_point(aes(size=Count))+ | |
scale_colour_gradient(low="red", high="blue") | |
ggsave(pngName,width=50.8,height=28.575,units="cm") | |
} | |
return(DavRes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment