Mercurial > repos > proteore > proteore_topgo
diff topGO_enrichment.R @ 19:0014bd289aff draft
planemo upload commit 4cbd26b257f8a32e11289e28135da86b03b46622-dirty
| author | proteore |
|---|---|
| date | Tue, 19 Feb 2019 08:47:25 -0500 |
| parents | 36c97ab06d40 |
| children | 537a0aae9b41 |
line wrap: on
line diff
--- a/topGO_enrichment.R Mon Dec 17 11:05:04 2018 -0500 +++ b/topGO_enrichment.R Tue Feb 19 08:47:25 2019 -0500 @@ -155,91 +155,47 @@ createDotPlot = function(data, onto){ - values = deleteInfChar(data$pvalues) - values = roundValues(values) - values = as.numeric(values) - - geneRatio = data$Significant/data$Annotated - goTerms = data$Term - count = data$Significant - - labely = paste("GO terms",onto,sep=" ") - 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") + values = deleteInfChar(data$pvalues) + values = roundValues(values) + values = as.numeric(values) + + geneRatio = data$Significant/data$Annotated + goTerms = data$Term + count = data$Significant + + labely = paste("GO terms",onto,sep=" ") + 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){ - - values = deleteInfChar(data$pvalues) - values = roundValues(values) - values = as.numeric(values) - - goTerms = data$Term - count = data$Significant - - labely = paste("GO terms",onto,sep=" ") - 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") + values = deleteInfChar(data$pvalues) + values = roundValues(values) + values = as.numeric(values) + + goTerms = data$Term + count = data$Significant + + labely = paste("GO terms",onto,sep=" ") + 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") } # Produce the different outputs createOutputs = function(result, cut_result,text, barplot, dotplot, onto){ - + if (is.null(result)){ - if (text){ - err_msg = "None of the input ids can be found in the org package data, enrichment analysis cannot be realized. \n The inputs ids probably either have no associated GO terms or are not ENSG identifiers (e.g : ENSG00000012048)." - write.table(err_msg, file='result', quote=FALSE, sep='\t', col.names = T, row.names = F) - } - if (barplot){ - png(filename="barplot.png") - plot.new() - #text(0,0,err_msg) - dev.off() - } - if (dotplot){ - png(filename="dotplot.png") - plot.new() - #text(0,0,err_msg) - dev.off() - } - opt <- options(show.error.messages=FALSE) - on.exit(options(opt)) - stop("null result") - } + err_msg = "None of the input ids can be found in the org package data, enrichment analysis cannot be realized. \n The inputs ids probably either have no associated GO terms or are not ENSG identifiers (e.g : ENSG00000012048)." + write.table(err_msg, file='result', quote=FALSE, sep='\t', col.names = F, row.names = F) + }else if (is.null(cut_result)){ + err_msg = "Threshold was too stringent, no GO term found with pvalue equal or lesser than the threshold value." + write.table(err_msg, file='result.tsv', quote=FALSE, sep='\t', col.names = F, row.names = F) + }else { + write.table(cut_result, file='result.tsv', quote=FALSE, sep='\t', col.names = T, row.names = F) - if (is.null(cut_result)){ - if (text){ - err_msg = "Threshold was too stringent, no GO term found with pvalue equal or lesser than the threshold value." - write.table(err_msg, file='result', quote=FALSE, sep='\t', col.names = T, row.names = F) - } - if (barplot){ - png(filename="barplot.png") - plot.new() - text(0,0,err_msg) - dev.off() - } - if (dotplot){ - png(filename="dotplot.png") - plot.new() - text(0,0,err_msg) - dev.off() - } - opt <- options(show.error.messages=FALSE) - on.exit(options(opt)) - stop("null cut_result") - } - - if (text){ - write.table(cut_result, file='result', quote=FALSE, sep='\t', col.names = T, row.names = F) - } - - if (barplot){ - createBarPlot(cut_result, onto) - } - - if (dotplot){ - createDotPlot(cut_result, onto) + if (barplot){createBarPlot(cut_result, onto)} + if (dotplot){createDotPlot(cut_result, onto)} } } @@ -318,8 +274,7 @@ #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() + stop("no ensembl gene ids found in your ids list, please check your IDs in input or the selected column of your input file") } #get input if background genes @@ -332,8 +287,7 @@ } #check of ENS ids if (! any(check_ens_ids(background_sample))){ - print("no ensembl gene ids found in your background ids list, please check your IDs in input or the selected column of your input file") - stop() + stop("no ensembl gene ids found in your background ids list, please check your IDs in input or the selected column of your input file") } } else { background_sample=NULL
