Mercurial > repos > proteore > proteore_topgo
annotate enrichment_v3.R @ 3:5f6d95716bc9 draft
planemo upload commit 74f72978b11230744b116d34fe3f2aa7934bf545-dirty
author | proteore |
---|---|
date | Tue, 27 Feb 2018 09:17:57 -0500 |
parents | 472ad7da3d92 |
children | 829cbdb71efa |
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 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
35 library("topGO") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
36 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
37 '%!in%' <- function(x,y)!('%in%'(x,y)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
38 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
39 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
40 # Parse command line arguments |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
41 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
42 args = commandArgs(trailingOnly = TRUE) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
43 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
44 # 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
|
45 hh <- paste(unlist(args),collapse=' ') |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
46 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
47 # delete the first element of the list which is always a blank space |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
48 listoptions <- unlist(strsplit(hh,'--'))[-1] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
49 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
50 # for each input, split the arguments with blank space as separator, unlist, |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
51 # and delete the first element which is the input name (e.g --inputtype) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
52 options.args <- sapply(listoptions,function(x){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
53 unlist(strsplit(x, ' '))[-1] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
54 }) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
55 # same as the step above, except that only the names are kept |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
56 options.names <- sapply(listoptions,function(x){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
57 option <- unlist(strsplit(x, ' '))[1] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
58 }) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
59 names(options.args) <- unlist(options.names) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
60 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
61 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
62 if (length(options.args) != 12) { |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
63 stop("Not enough/Too many arguments", call. = FALSE) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
64 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
65 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
66 typeinput = options.args[1] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
67 listfile = options.args[2] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
68 onto = as.character(options.args[3]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
69 option = as.character(options.args[4]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
70 correction = as.character(options.args[6]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
71 threshold = as.numeric(options.args[5]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
72 text = as.character(options.args[7]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
73 barplot = as.character(options.args[8]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
74 dotplot = as.character(options.args[9]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
75 column = as.numeric(gsub("c","",options.args[10])) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
76 geneuniverse = as.character(options.args[11]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
77 header = as.character(options.args[12]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
78 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
79 if (typeinput=="copypaste"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
80 sample = as.data.frame(unlist(listfile)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
81 sample = sample[,column] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
82 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
83 if (typeinput=="tabfile"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
84 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
85 if (header=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
86 sample = read.table(listfile,header=TRUE,sep="\t",na.strings="NA",fill=TRUE) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
87 }else{ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
88 sample = read.table(listfile,header=FALSE,sep="\t",na.strings="NA",fill=TRUE) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
89 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
90 sample = sample[,column] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
91 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
92 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
93 # Launch enrichment analysis and return result data from the analysis or the null |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
94 # object if the enrichment could not be done. |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
95 goEnrichment = function(geneuniverse,sample,onto){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
96 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
97 # 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
|
98 # associated ensembl ids according to the org package |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
99 xx = annFUN.org(onto,mapping=geneuniverse,ID="ensembl") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
100 allGenes = unique(unlist(xx)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
101 # 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
|
102 # universe), that is in |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
103 # allGenes |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
104 if (length(intersect(sample,allGenes))==0){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
105 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
106 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
|
107 return(c(NULL,NULL)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
108 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
109 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
110 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
111 geneList = factor(as.integer(allGenes %in% sample)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
112 names(geneList) <- allGenes |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
113 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
114 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
115 #topGO enrichment |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
116 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
117 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
118 # Creation of a topGOdata object |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
119 # 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
|
120 # Parameters : |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
121 # ontology : character string specifying the ontology of interest (BP, CC, MF) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
122 # allGenes : named vector of type numeric or factor |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
123 # annot : tells topGO how to map genes to GO annotations. |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
124 # argument not used here : nodeSize : at which minimal number of GO annotations |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
125 # do we consider a gene |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
126 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
127 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
|
128 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
129 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
130 # Performing enrichment tests |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
131 result <- runTest(myGOdata, algorithm=option, statistic="fisher") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
132 return(c(result,myGOdata)) |
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 # 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
|
136 # "< 1e-30" produced by topGO. As such it is important to delete the < char |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
137 # 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
|
138 deleteInfChar = function(values){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
139 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
140 lines = grep("<",values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
141 if (length(lines)!=0){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
142 for (line in lines){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
143 values[line]=gsub("<","",values[line]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
144 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
145 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
146 return(values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
147 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
148 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
149 corrMultipleTesting = function(result, myGOdata,correction,threshold){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
150 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
151 # adjust for multiple testing |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
152 if (correction!="none"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
153 # GenTable : transforms the result object into a list. Filters can be applied |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
154 # (e.g : with the topNodes argument, to get for instance only the n first |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
155 # 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
|
156 # take all the GO terms, no matter their pvalues |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
157 allRes <- GenTable(myGOdata, test = result, orderBy = "result", ranksOf = "result",topNodes=length(attributes(result)$score)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
158 # 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
|
159 # values are converted to 1e-30 to be able to correct the pvalues |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
160 pvaluestmp = deleteInfChar(allRes$test) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
161 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
162 # the correction is done from the modified pvalues |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
163 allRes$qvalues = p.adjust(pvaluestmp, method = as.character(correction), n = length(pvaluestmp)) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
164 allRes = as.data.frame(allRes) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
165 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
166 # Rename the test column by pvalues, so that is more explicit |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
167 nb = which(names(allRes) %in% c("test")) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
168 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
169 names(allRes)[nb] = "pvalues" |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
170 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
171 allRes = allRes[which(as.numeric(allRes$pvalues) <= threshold),] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
172 if (length(allRes$pvalues)==0){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
173 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
|
174 return(NULL) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
175 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
176 allRes = allRes[order(allRes$qvalues),] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
177 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
178 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
179 if (correction=="none"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
180 # get all the go terms under user threshold |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
181 mysummary <- summary(attributes(result)$score <= threshold) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
182 numsignif <- as.integer(mysummary[[3]]) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
183 # get all significant nodes |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
184 allRes <- GenTable(myGOdata, test = result, orderBy = "result", ranksOf = "result",topNodes=numsignif) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
185 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
186 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
187 allRes = as.data.frame(allRes) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
188 # Rename the test column by pvalues, so that is more explicit |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
189 nb = which(names(allRes) %in% c("test")) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
190 names(allRes)[nb] = "pvalues" |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
191 if (numsignif==0){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
192 |
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 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
197 allRes = allRes[order(allRes$pvalues),] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
198 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
199 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
200 return(allRes) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
201 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
202 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
203 # 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
|
204 roundValues = function(values){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
205 for (line in 1:length(values)){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
206 values[line]=as.numeric(gsub(".*e","1e",as.character(values[line]))) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
207 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
208 return(values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
209 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
210 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
211 createDotPlot = function(data, onto){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
212 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
213 values = deleteInfChar(data$pvalues) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
214 values = roundValues(values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
215 values = as.numeric(values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
216 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
217 geneRatio = data$Significant/data$Annotated |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
218 goTerms = data$Term |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
219 count = data$Significant |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
220 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
221 labely = paste("GO terms",onto,sep=" ") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
222 png(filename="dotplot.png",res=300, width = 3200, height = 3200, units = "px") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
223 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
|
224 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
225 plot(sp1) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
226 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
227 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
228 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
229 createBarPlot = function(data, onto){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
230 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
231 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
232 values = deleteInfChar(data$pvalues) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
233 values = roundValues(values) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
234 |
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 goTerms = data$Term |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
237 count = data$Significant |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
238 png(filename="barplot.png",res=300, width = 3200, height = 3200, units = "px") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
239 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
240 labely = paste("GO terms",onto,sep=" ") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
241 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
|
242 plot(p) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
243 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
244 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
245 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
246 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
247 # Produce the different outputs |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
248 createOutputs = function(result, cut_result,text, barplot, dotplot, onto){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
249 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
250 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
251 if (is.null(result)){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
252 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
253 if (text=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
254 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
255 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
|
256 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
|
257 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
258 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
259 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
260 if (barplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
261 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
262 png(filename="barplot.png") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
263 plot.new() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
264 #text(0,0,err_msg) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
265 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
266 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
267 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
268 if (dotplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
269 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
270 png(filename="dotplot.png") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
271 plot.new() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
272 #text(0,0,err_msg) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
273 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
274 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
275 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
276 return(TRUE) |
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 (is.null(cut_result)){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
281 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
282 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
283 if (text=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
284 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
285 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
|
286 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
|
287 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
288 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
289 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
290 if (barplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
291 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
292 png(filename="barplot.png") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
293 plot.new() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
294 text(0,0,err_msg) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
295 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
296 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
297 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
298 if (dotplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
299 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
300 png(filename="dotplot.png") |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
301 plot.new() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
302 text(0,0,err_msg) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
303 dev.off() |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
304 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
305 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
306 return(TRUE) |
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 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
311 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
312 if (text=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
313 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
|
314 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
315 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
316 if (barplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
317 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
318 createBarPlot(cut_result, onto) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
319 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
320 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
321 if (dotplot=="TRUE"){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
322 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
323 createDotPlot(cut_result, onto) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
324 } |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
325 return(TRUE) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
326 } |
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 # Load R library ggplot2 to plot graphs |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
331 library(ggplot2) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
332 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
333 # Launch enrichment analysis |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
334 allresult = goEnrichment(geneuniverse,sample,onto) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
335 result = allresult[1][[1]] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
336 myGOdata = allresult[2][[1]] |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
337 if (!is.null(result)){ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
338 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
339 # Adjust the result with a multiple testing correction or not and with the user |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
340 # p-value cutoff |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
341 cut_result = corrMultipleTesting(result,myGOdata, correction,threshold) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
342 }else{ |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
343 |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
344 cut_result=NULL |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
345 |
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 createOutputs(result, cut_result,text, barplot, dotplot, onto) |
472ad7da3d92
planemo upload commit 9f9e8b72a239e58b5087b2b3737262c25cc2671e-dirty
proteore
parents:
diff
changeset
|
350 |