Dear All,
I'm experiencing a problem while using your super-useful packages DOSE and ClusterProfiler.
I try to create a for loop to process multiple genelists in batch. The script works generating the result-tables but fails to find the enrichment objects (namely ego's,ggo's, kk and kk2 that you'll see in the following script). It seems to me that they are unavailable after the table creation and can’t be found by the graphical functions (barplot, dotplot, enrichmap or cnetplot). If I run it out of the for loop, it works smoothly with a single list, I mean the exact same commands.
Here is the error I get when graphical functions (dotplot in this case) fail:
Error in
dotplot
(egoBP) :
error in evaluating the argument 'object' in selecting a method for function 'dotplot':
Error: object 'egoBP' not found
Here is my script in case you can tell me what can be the problem:
###############ClusterProfiler#############################
#install.packages(c("DOSE", "clusterProfiler"),repos="http://www.bioconductor.org/packages/devel/bioc")
# source("https://bioconductor.org/biocLite.R")
# biocLite (c("tidyr","pathview","Rgraphviz","RDAVIDWebService"))
#install.packages("rJava")
library(DOSE)
library(clusterProfiler)
#library(RDAVIDWebService)
x<-setwd("C:/R_data/Folder/")
file.list <- as.list(list.files(".", pattern = "*.tsv$"))
file.list
for(i in 1:length(file.list))
{
#create the new output directory list
dir<- gsub("\\.tsv$", "", file.list[[i]])
file.path<-x
dir.create(file.path(dir))
#read the table
geneList2<- read.table(file.list[[i]]) #For loop
head(geneList2)
str(geneList2)
#generate vector
gene.vector=geneList2$V2
names(gene.vector)=geneList2$V1
head(gene.vector)
vlist<-gene.vector
head(vlist)
str(vlist)
listaGenes <- as.vector(geneList2[,1])#
head(listaGenes)
genes<-as.character(listaGenes)#list of genes
#Gene Ontology Classification Examples
ggoBP <- groupGO(gene = genes,
organism = "mouse",#organism = "human"
ont = "BP",
level = 3,
readable = TRUE)
head(summary(ggoBP))
write.csv(summary(ggoBP), file=(paste(file.path, dir,"GOc_GOBp_table.csv", sep="/")))
#GO over-representation test
egoBP <- enrichGO(gene = genes,
universe = allEntrez,
organism = "mouse",#organism = "human"
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.1,#pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
readable = TRUE)
head(summary(egoBP))
write.csv(summary(egoBP), file=(paste(file.path, dir,"Overrep_GOBP_table.csv", sep="/")))
#GO Gene Set Enrichment Analysis
ego2BP <- gseGO(geneList = vlist,
organism = "mouse",#organism = "human"
ont = "BP",
nPerm = 1000,
minGSSize = 5,#120,
pvalueCutoff = 0.5,#pvalueCutoff = 0.01,
verbose = FALSE)
write.csv(summary(ego2BP), file=(paste(file.path, dir,"gseGOBP_table.csv", sep="/")))
#KEGG over-representation test
kk <- enrichKEGG(gene = genes,
organism = "mouse",#organism = "human",
pvalueCutoff = 0.05,
readable = TRUE)
#use_internal_data = TRUE)
head(summary(kk))
write.csv(summary(kk), file=(paste(file.path, dir,"enrichKEGG_table.csv", sep="/")))
#Graphical Visualization Examples
#Barplot
pdf(paste(file.path, dir, "Enrichment_barplot.pdf", sep="/"))
barplot(egoBP, showCategory=8,font.size=5)
dev.off()
#Dotplot
pdf(paste(file.path, dir, "Enrichment_dotplot.pdf", sep="/"))
dotplot(egoBP)
dev.off()
#Enrichmap
pdf(paste(file.path, dir, "Enrichment2_Map.pdf", sep="/"))
enrichMap(egoBP,vertex.label.cex=1.2,layout=igraph::layout.kamada.kawai)
dev.off()
#cnetplot
pdf(paste(file.path, dir, "Enrichment_Cnet.pdf", sep="/"))
cnetplot(egoBP, categorySize="pvalue", foldChange=vlist)
dev.off()
#Networks
pdf(paste(file.path, dir, "Enrichment_Networks.pdf", sep="/"))
plotGOgraph(egoBP)
dev.off()
}
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] grid parallel stats4 stats graphics grDevices utils
[8] datasets methods base
other attached packages:
[1] pathview_1.10.1 org.Hs.eg.db_3.2.3 Rgraphviz_2.14.0
[4] graph_1.48.0 SparseM_1.7 GO.db_3.2.2
[7] org.Mm.eg.db_3.2.3 AnnotationDbi_1.32.0 IRanges_2.4.4
[10] S4Vectors_0.8.3 Biobase_2.30.0 BiocGenerics_0.16.1
[13] clusterProfiler_2.4.3 DOSE_2.8.3 RSQLite_1.0.0
[16] DBI_0.3.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.2 plyr_1.8.3 XVector_0.10.0 tools_3.2.2
[5] zlibbioc_1.16.0 digest_0.6.8 lattice_0.20-33 gtable_0.1.2
[9] png_0.1-7 KEGGgraph_1.28.0 igraph_1.0.1 curl_0.9.4
[13] proto_0.3-10 topGO_2.22.0 stringr_1.0.0 httr_1.0.0
[17] Biostrings_2.38.2 qvalue_2.2.2 R6_2.1.1 XML_3.98-1.3
[21] GOSemSim_1.28.2 ggplot2_1.0.1 reshape2_1.4.1 DO.db_2.9
[25] magrittr_1.5 scales_0.3.0 MASS_7.3-45 splines_3.2.2
[29] KEGGREST_1.10.1 colorspace_1.2-6 labeling_0.3 stringi_1.0-1
[33] munsell_0.4.2
I did that in a previous version of the code, and I did confirm my lists entered the loop (In fact, as I said before, lists are processed and the different csv tables are retrieved. The problem comes when the plotting functions try to find the objects such as "
egoBP".
Is at that point when the object can't be found, but ironically It was found previously for this process, e.g.:
write.csv(summary(egoBP), file=(paste(file.path, dir,"Overrep_GOBP_table.csv", sep="/")))
If the object is present to print its summary into a csv, how can it dissapear when I call the dotplot function inside the same loop a few lines after? e.g.
#Dotplot
pdf(paste(file.path, dir, "Enrichment_dotplot.pdf", sep="/"))
dotplot(egoBP)
dev.off()
I suspect that it could be related with R language itself, not only to clusterProfile package specifically, that is why I published such a big piece of code...due to this I decided to post this issue to the list, just in case I have made a newbie mistake I am unable to detect.
Anyway, as I told you before, out of the "For loop" you code works perfectly well.
Thanks in advance for your attention.
JL