# HG changeset patch # User proteore # Date 1537522358 14400 # Node ID 70c0c8757f5fbb43c292bd7069be22fc71f66489 # Parent ddaa0c318d65503060f24a1e07d93b1a7fd662cb planemo upload commit 9d3e0b226140b566fc529fd0ffe7aa9e8388c6e5-dirty diff -r ddaa0c318d65 -r 70c0c8757f5f enrichment_v3.R --- a/enrichment_v3.R Fri Mar 23 10:43:32 2018 -0400 +++ b/enrichment_v3.R Fri Sep 21 05:32:38 2018 -0400 @@ -30,9 +30,10 @@ # results file, barplot.png for the barplot image file and dotplot.png for the # dotplot image file +options(warn=-1) #TURN OFF WARNINGS !!!!!! # loading topGO library -library(topGO) +suppressMessages(library(topGO)) # Read file and return file content as data.frame readfile = function(filename, header) { @@ -54,6 +55,11 @@ return(file) } +check_ens_ids <- function(vector) { + ens_pattern = "^(ENS[A-Z]+[0-9]{11}|[A-Z]{3}[0-9]{3}[A-Za-z](-[A-Za-z])?|CG[0-9]+|[A-Z0-9]+\\.[0-9]+|YM[A-Z][0-9]{3}[a-z][0-9])$" + return(grepl(ens_pattern,vector)) +} + '%!in%' <- function(x,y)!('%in%'(x,y)) @@ -83,6 +89,10 @@ stop("Not enough/Too many arguments", call. = FALSE) } +#save(options.args,file="/home/dchristiany/proteore_project/ProteoRE/tools/topGO/args.Rda") +#load("/home/dchristiany/proteore_project/ProteoRE/tools/topGO/args.Rda") + + typeinput = options.args[1] listfile = options.args[2] onto = as.character(options.args[3]) @@ -108,8 +118,14 @@ sample = readfile(listfile, "false") } sample = sample[,column] +} +#check of ENS ids +if (! any(check_ens_ids(sample))){ + print("no ensembl gene ids found in your ids list, please check your IDs in input or the selected column of your input file") + stop() } + # Launch enrichment analysis and return result data from the analysis or the null # object if the enrichment could not be done. goEnrichment = function(geneuniverse,sample,onto){ @@ -239,11 +255,8 @@ count = data$Significant labely = paste("GO terms",onto,sep=" ") - png(filename="dotplot.png",res=300, width = 3200, height = 3200, units = "px") - sp1 = ggplot(data,aes(x=geneRatio,y=goTerms, color=values,size=count)) +geom_point() + scale_colour_gradientn(colours=c("red","violet","blue")) + xlab("Gene Ratio") + ylab(labely) + labs(color="p-values\n") - - plot(sp1) - dev.off() + ggplot(data,aes(x=geneRatio,y=goTerms, color=values,size=count)) +geom_point( ) + scale_colour_gradientn(colours=c("red","violet","blue")) + xlab("Gene Ratio") + ylab(labely) + labs(color="p-values\n" ) + ggsave("dotplot.png", device = "png", dpi = 320, limitsize = TRUE, width = 15, height = 15, units="cm") } createBarPlot = function(data, onto){ @@ -255,12 +268,10 @@ values = as.numeric(values) goTerms = data$Term count = data$Significant - png(filename="barplot.png",res=300, width = 3200, height = 3200, units = "px") labely = paste("GO terms",onto,sep=" ") - p<-ggplot(data, aes(x=goTerms, y=count,fill=values)) + ylab("Gene count") + xlab(labely) +geom_bar(stat="identity") + scale_fill_gradientn(colours=c("red","violet","blue")) + coord_flip() + labs(fill="p-values\n") - plot(p) - dev.off() + ggplot(data, aes(x=goTerms, y=count,fill=values,scale(scale = 0.5))) + ylab("Gene count") + xlab(labely) +geom_bar(stat="identity") + scale_fill_gradientn(colours=c("red","violet","blue")) + coord_flip() + labs(fill="p-values\n") + ggsave("barplot.png", device = "png", dpi = 320, limitsize = TRUE, width = 15, height = 15, units="cm") } @@ -342,16 +353,15 @@ createDotPlot(cut_result, onto) } - return(TRUE) } # Load R library ggplot2 to plot graphs -library(ggplot2) +suppressMessages(library(ggplot2)) # Launch enrichment analysis -allresult = goEnrichment(geneuniverse,sample,onto) +allresult = suppressMessages(goEnrichment(geneuniverse,sample,onto)) result = allresult[1][[1]] myGOdata = allresult[2][[1]] if (!is.null(result)){ diff -r ddaa0c318d65 -r 70c0c8757f5f topGO.xml --- a/topGO.xml Fri Mar 23 10:43:32 2018 -0400 +++ b/topGO.xml Fri Sep 21 05:32:38 2018 -0400 @@ -1,15 +1,20 @@ - + Enrichment analysis for Gene Ontology R - r-ggplot2 - bioconductor-org.hs.eg.db - bioconductor-graph - bioconductor-annotationdbi - bioconductor-go.db - bioconductor-topgo + r-ggplot2 + bioconductor-org.hs.eg.db + bioconductor-org.mm.eg.db + bioconductor-org.ce.eg.db + bioconductor-org.dm.eg.db + bioconductor-org.sc.sgd.db + + bioconductor-graph + bioconductor-annotationdbi + bioconductor-go.db + bioconductor-topgo @@ -73,7 +78,7 @@ - + @@ -82,12 +87,12 @@ - - - - - - + + + + + +