annotate enrichment_v3.R @ 8:ddaa0c318d65 draft

planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
author proteore
date Fri, 23 Mar 2018 10:43:32 -0400
parents 829cbdb71efa
children 70c0c8757f5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
1 # enrichment_v3.R
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
2 # Usage : Rscript --vanilla enrichment_v3.R --inputtype tabfile (or
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
3 # copypaste) --input file.txt --ontology "BP/CC/MF" --option option (e.g
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
4 # : classic/elim...) --threshold threshold --correction correction --textoutput
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
5 # text --barplotoutput barplot
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
6 # --dotplotoutput dotplot --column column --geneuniver human
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
7 # e.g : Rscript --vanilla enrichment_v3.R --inputtype tabfile --input file.txt
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
8 # --ontology BP --option classic --threshold 1e-15 --correction holm
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
9 # --textoutput TRUE
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
10 # --barplotoutput TRUE --dotplotoutput TRUE --column c1 --geneuniverse
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
11 # org.Hs.eg.db
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
12 # INPUT :
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
13 # - type of input. Can be ids separated by a blank space (copypast), or a text
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
14 # file (tabfile)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
15 # - file with at least one column of ensembl ids
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
16 # - gene ontology category : Biological Process (BP), Cellular Component (CC), Molecular Function (MF)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
17 # - test option (relative to topGO algorithms) : elim, weight01, parentchild, or no option (classic)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
18 # - threshold for enriched GO term pvalues (e.g : 1e-15)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
19 # - correction for multiple testing (see p.adjust options : holm, hochberg, hommel, bonferroni, BH, BY,fdr,none
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
20 # - outputs wanted in this order text, barplot, dotplot with boolean value (e.g
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
21 # : TRUE TRUE TRUE ).
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
22 # Declare the output not wanted as none
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
23 # - column containing the ensembl ids if the input file is a tabfile
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
24 # - gene universe reference for the user chosen specie
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
25 # - header : if the input is a text file, does this text file have a header
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
26 # (TRUE/FALSE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
27 #
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
28 # OUTPUT :
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
29 # - outputs commanded by the user named respectively result.tsv for the text
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
30 # results file, barplot.png for the barplot image file and dotplot.png for the
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
31 # dotplot image file
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
32
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
33
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
34 # loading topGO library
8
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
35 library(topGO)
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
36
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
37 # Read file and return file content as data.frame
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
38 readfile = function(filename, header) {
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
39 if (header == "true") {
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
40 # Read only first line of the file as header:
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
41 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "")
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
42 #Read the data of the files (skipping the first row)
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
43 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "")
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
44 # Remove empty rows
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
45 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE]
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
46 #And assign the header to the data
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
47 names(file) <- headers
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
48 }
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
49 else {
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
50 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "")
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
51 # Remove empty rows
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
52 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE]
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
53 }
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
54 return(file)
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
55 }
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
56
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
57 '%!in%' <- function(x,y)!('%in%'(x,y))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
58
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
59
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
60 # Parse command line arguments
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
61
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
62 args = commandArgs(trailingOnly = TRUE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
63
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
64 # create a list of the arguments from the command line, separated by a blank space
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
65 hh <- paste(unlist(args),collapse=' ')
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
66
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
67 # delete the first element of the list which is always a blank space
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
68 listoptions <- unlist(strsplit(hh,'--'))[-1]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
69
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
70 # for each input, split the arguments with blank space as separator, unlist,
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
71 # and delete the first element which is the input name (e.g --inputtype)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
72 options.args <- sapply(listoptions,function(x){
8
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
73 unlist(strsplit(x, '[ \t\n]+'))[-1]
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
74 })
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
75 # same as the step above, except that only the names are kept
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
76 options.names <- sapply(listoptions,function(x){
8
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
77 option <- unlist(strsplit(x, '[ \t\n]+'))[1]
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
78 })
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
79 names(options.args) <- unlist(options.names)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
80
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
81
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
82 if (length(options.args) != 12) {
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
83 stop("Not enough/Too many arguments", call. = FALSE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
84 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
85
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
86 typeinput = options.args[1]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
87 listfile = options.args[2]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
88 onto = as.character(options.args[3])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
89 option = as.character(options.args[4])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
90 correction = as.character(options.args[6])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
91 threshold = as.numeric(options.args[5])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
92 text = as.character(options.args[7])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
93 barplot = as.character(options.args[8])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
94 dotplot = as.character(options.args[9])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
95 column = as.numeric(gsub("c","",options.args[10]))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
96 geneuniverse = as.character(options.args[11])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
97 header = as.character(options.args[12])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
98
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
99 if (typeinput=="copypaste"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
100 sample = as.data.frame(unlist(listfile))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
101 sample = sample[,column]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
102 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
103 if (typeinput=="tabfile"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
104
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
105 if (header=="TRUE"){
8
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
106 sample = readfile(listfile, "true")
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
107 }else{
8
ddaa0c318d65 planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
proteore
parents: 5
diff changeset
108 sample = readfile(listfile, "false")
0
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
109 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
110 sample = sample[,column]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
111
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
112 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
113 # Launch enrichment analysis and return result data from the analysis or the null
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
114 # object if the enrichment could not be done.
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
115 goEnrichment = function(geneuniverse,sample,onto){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
116
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
117 # get all the GO terms of the corresponding ontology (BP/CC/MF) and all their
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
118 # associated ensembl ids according to the org package
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
119 xx = annFUN.org(onto,mapping=geneuniverse,ID="ensembl")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
120 allGenes = unique(unlist(xx))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
121 # check if the genes given by the user can be found in the org package (gene
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
122 # universe), that is in
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
123 # allGenes
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
124 if (length(intersect(sample,allGenes))==0){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
125
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
126 print("None of the input ids can be found in the org package data, enrichment analysis cannot be realized. \n The inputs ids probably have no associated GO terms.")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
127 return(c(NULL,NULL))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
128
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
129 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
130
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
131 geneList = factor(as.integer(allGenes %in% sample))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
132 names(geneList) <- allGenes
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
133
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
134
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
135 #topGO enrichment
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
136
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
137
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
138 # Creation of a topGOdata object
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
139 # It will contain : the list of genes of interest, the GO annotations and the GO hierarchy
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
140 # Parameters :
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
141 # ontology : character string specifying the ontology of interest (BP, CC, MF)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
142 # allGenes : named vector of type numeric or factor
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
143 # annot : tells topGO how to map genes to GO annotations.
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
144 # argument not used here : nodeSize : at which minimal number of GO annotations
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
145 # do we consider a gene
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
146
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
147 myGOdata = new("topGOdata", description="SEA with TopGO", ontology=onto, allGenes=geneList, annot = annFUN.org, mapping=geneuniverse,ID="ensembl")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
148
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
149
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
150 # Performing enrichment tests
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
151 result <- runTest(myGOdata, algorithm=option, statistic="fisher")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
152 return(c(result,myGOdata))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
153 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
154
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
155 # Some libraries such as GOsummaries won't be able to treat the values such as
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
156 # "< 1e-30" produced by topGO. As such it is important to delete the < char
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
157 # with the deleteInfChar function. Nevertheless the user will have access to the original results in the text output.
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
158 deleteInfChar = function(values){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
159
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
160 lines = grep("<",values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
161 if (length(lines)!=0){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
162 for (line in lines){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
163 values[line]=gsub("<","",values[line])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
164 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
165 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
166 return(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
167 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
168
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
169 corrMultipleTesting = function(result, myGOdata,correction,threshold){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
170
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
171 # adjust for multiple testing
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
172 if (correction!="none"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
173 # GenTable : transforms the result object into a list. Filters can be applied
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
174 # (e.g : with the topNodes argument, to get for instance only the n first
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
175 # GO terms with the lowest pvalues), but as we want to apply a correction we
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
176 # take all the GO terms, no matter their pvalues
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
177 allRes <- GenTable(myGOdata, test = result, orderBy = "result", ranksOf = "result",topNodes=length(attributes(result)$score))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
178 # Some pvalues given by topGO are not numeric (e.g : "<1e-30). As such, these
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
179 # values are converted to 1e-30 to be able to correct the pvalues
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
180 pvaluestmp = deleteInfChar(allRes$test)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
181
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
182 # the correction is done from the modified pvalues
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
183 allRes$qvalues = p.adjust(pvaluestmp, method = as.character(correction), n = length(pvaluestmp))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
184 allRes = as.data.frame(allRes)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
185
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
186 # Rename the test column by pvalues, so that is more explicit
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
187 nb = which(names(allRes) %in% c("test"))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
188
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
189 names(allRes)[nb] = "pvalues"
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
190
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
191 allRes = allRes[which(as.numeric(allRes$pvalues) <= threshold),]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
192 if (length(allRes$pvalues)==0){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
193 print("Threshold was too stringent, no GO term found with pvalue equal or lesser than the threshold value")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
194 return(NULL)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
195 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
196 allRes = allRes[order(allRes$qvalues),]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
197 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
198
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
199 if (correction=="none"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
200 # get all the go terms under user threshold
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
201 mysummary <- summary(attributes(result)$score <= threshold)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
202 numsignif <- as.integer(mysummary[[3]])
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
203 # get all significant nodes
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
204 allRes <- GenTable(myGOdata, test = result, orderBy = "result", ranksOf = "result",topNodes=numsignif)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
205
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
206
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
207 allRes = as.data.frame(allRes)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
208 # Rename the test column by pvalues, so that is more explicit
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
209 nb = which(names(allRes) %in% c("test"))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
210 names(allRes)[nb] = "pvalues"
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
211 if (numsignif==0){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
212
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
213 print("Threshold was too stringent, no GO term found with pvalue equal or lesser than the threshold value")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
214 return(NULL)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
215 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
216
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
217 allRes = allRes[order(allRes$pvalues),]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
218 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
219
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
220 return(allRes)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
221 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
222
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
223 # roundValues will simplify the results by rounding down the values. For instance 1.1e-17 becomes 1e-17
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
224 roundValues = function(values){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
225 for (line in 1:length(values)){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
226 values[line]=as.numeric(gsub(".*e","1e",as.character(values[line])))
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
227 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
228 return(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
229 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
230
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
231 createDotPlot = function(data, onto){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
232
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
233 values = deleteInfChar(data$pvalues)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
234 values = roundValues(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
235 values = as.numeric(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
236
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
237 geneRatio = data$Significant/data$Annotated
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
238 goTerms = data$Term
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
239 count = data$Significant
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
240
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
241 labely = paste("GO terms",onto,sep=" ")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
242 png(filename="dotplot.png",res=300, width = 3200, height = 3200, units = "px")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
243 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")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
244
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
245 plot(sp1)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
246 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
247 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
248
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
249 createBarPlot = function(data, onto){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
250
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
251
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
252 values = deleteInfChar(data$pvalues)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
253 values = roundValues(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
254
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
255 values = as.numeric(values)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
256 goTerms = data$Term
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
257 count = data$Significant
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
258 png(filename="barplot.png",res=300, width = 3200, height = 3200, units = "px")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
259
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
260 labely = paste("GO terms",onto,sep=" ")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
261 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")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
262 plot(p)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
263 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
264 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
265
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
266
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
267 # Produce the different outputs
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
268 createOutputs = function(result, cut_result,text, barplot, dotplot, onto){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
269
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
270
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
271 if (is.null(result)){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
272
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
273 if (text=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
274
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
275 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)."
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
276 write.table(err_msg, file='result.csv', quote=FALSE, sep='\t', col.names = T, row.names = F)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
277
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
278 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
279
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
280 if (barplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
281
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
282 png(filename="barplot.png")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
283 plot.new()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
284 #text(0,0,err_msg)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
285 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
286 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
287
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
288 if (dotplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
289
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
290 png(filename="dotplot.png")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
291 plot.new()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
292 #text(0,0,err_msg)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
293 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
294
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
295 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
296 return(TRUE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
297 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
298
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
299
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
300 if (is.null(cut_result)){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
301
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
302
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
303 if (text=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
304
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
305 err_msg = "Threshold was too stringent, no GO term found with pvalue equal or lesser than the threshold value."
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
306 write.table(err_msg, file='result.csv', quote=FALSE, sep='\t', col.names = T, row.names = F)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
307
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
308 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
309
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
310 if (barplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
311
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
312 png(filename="barplot.png")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
313 plot.new()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
314 text(0,0,err_msg)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
315 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
316 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
317
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
318 if (dotplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
319
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
320 png(filename="dotplot.png")
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
321 plot.new()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
322 text(0,0,err_msg)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
323 dev.off()
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
324
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
325 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
326 return(TRUE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
327
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
328
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
329
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
330 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
331
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
332 if (text=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
333 write.table(cut_result, file='result.csv', quote=FALSE, sep='\t', col.names = T, row.names = F)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
334 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
335
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
336 if (barplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
337
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
338 createBarPlot(cut_result, onto)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
339 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
340
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
341 if (dotplot=="TRUE"){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
342
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
343 createDotPlot(cut_result, onto)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
344 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
345 return(TRUE)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
346 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
347
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
348
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
349
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
350 # Load R library ggplot2 to plot graphs
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
351 library(ggplot2)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
352
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
353 # Launch enrichment analysis
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
354 allresult = goEnrichment(geneuniverse,sample,onto)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
355 result = allresult[1][[1]]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
356 myGOdata = allresult[2][[1]]
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
357 if (!is.null(result)){
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
358
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
359 # Adjust the result with a multiple testing correction or not and with the user
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
360 # p-value cutoff
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
361 cut_result = corrMultipleTesting(result,myGOdata, correction,threshold)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
362 }else{
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
363
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
364 cut_result=NULL
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
365
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
366 }
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
367
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
368
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
369 createOutputs(result, cut_result,text, barplot, dotplot, onto)
472ad7da3d92 planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff changeset
370