Skip to content

Instantly share code, notes, and snippets.

@ipurusho
Last active September 29, 2016 15:49
Show Gist options
  • Save ipurusho/0e84ec7130fba9f426bbb72ccc8c4f57 to your computer and use it in GitHub Desktop.
Save ipurusho/0e84ec7130fba9f426bbb72ccc8c4f57 to your computer and use it in GitHub Desktop.
A function to perform DAVID GO term analysis using R directly.
### "transcript" parameter is the original matrix of normalized counts
### "signifcant" parameter is the filtered matrix of significant genes (using desired cutoff)
### "email" is an email address needed to run the web service
go.david<-function(transcript,significant,email){
require("RDAVIDWebService")
if(dim(significant)[1] !=0){
david<-DAVIDWebService$new(email=email)
background<-addList(david, rownames(transcript), idType="ENSEMBL_GENE_ID",listName="full_transcript", listType="Background")
sig.genes<-addList(david, rownames(significant), idType="ENSEMBL_GENE_ID",listName="significant", listType="Gene")
termCluster<-getClusterReport(david, type="Term")
if(length(members(termCluster)) !=0){
go.data<-data.frame()
for (cluster in 1:length(members(termCluster))){
go.data<-rbind(go.data,cbind(cluster,members(termCluster)[[cluster]][,1:6]))
}
go.genes<-list()
for(l in 1:dim(go.data)[1]){
go.genes<- append(go.genes,paste(paste(unlist(getBM(attributes = c("external_gene_id"), filters = "ensembl_gene_id",values = trim.leading(unlist(strsplit(go.data[l,7],split=","))),mart=mart)),sep=","),collapse=","))
}
go.term.data<-cbind(go.data[,-7],as.data.frame(unlist(go.genes)))
}
}
return(go.term.data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment