annotate GO-enrich.R @ 13:f6107b8ae8f8 draft default tip

"planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
author proteore
date Fri, 09 Apr 2021 14:39:05 +0000
parents d951677a50d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
1 options(warn = -1) #TURN OFF WARNINGS !!!!!!
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
2 suppressMessages(library(clusterProfiler, quietly = TRUE))
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
3
4
710414ebb6db planemo upload commit 0a42c3d46be24406936ca0036bb436e6e2524fd2-dirty
proteore
parents: 0
diff changeset
4 # Read file and return file content as data.frame
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
5 read_file <- function(path, header) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
6 file <- try(read.csv(path, header = header, sep = "\t",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
7 stringsAsFactors = FALSE, quote = "", check.names = F),
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
8 silent = TRUE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
9 if (inherits(file, "try-error")) {
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
10 stop("File not found !")
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
11 }else{
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
12 file <- file[!apply(is.na(file) | file == "", 1, all), , drop = FALSE]
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
13 return(file)
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
14 }
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
15 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
16
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
17
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
18 #return the number of character from the longest description found
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
19 #(from the 10 first)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
20 max_str_length_10_first <- function(vector) {
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
21 vector <- as.vector(vector)
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
22 nb_description <- length(vector)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
23 if (nb_description >= 10) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
24 nb_description <- 10
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
25 }
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
26
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
27 return(max(nchar(vector[1:nb_description])))
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
28 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
29
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
30 str2bool <- function(x) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
31 if (any(is.element(c("t", "true"), tolower(x)))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
32 return(TRUE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
33 }else if (any(is.element(c("f", "false"), tolower(x)))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
34 return(FALSE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
35
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
36 }else{
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
37 return(NULL)
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
38 }
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
39 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
40
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
41 #used before the limit was set to 50 characters
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
42 width_by_max_char <- function(nb_max_char) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
43 if (nb_max_char < 50) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
44 width <- 600
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
45 } else if (nb_max_char < 75) {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
46 width <- 800
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
47 } else if (nb_max_char < 100) {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
48 width <- 900
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
49 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
50 width <- 1000
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
51 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
52 return(width)
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
53 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
54
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
55
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
56 repartition_go <- function(geneid, orgdb, ontology,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
57 level = 3, readable = TRUE) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
58 ggo <- groupGO(gene = geneid,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
59 OrgDb = orgdb,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
60 ont = ontology,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
61 level = level,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
62 readable = TRUE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
63
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
64
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
65 if (length(ggo@result$ID) > 0) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
66 ggo@result$Description <- sapply(as.vector(ggo@result$Description), #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
67 function(x) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
68 ifelse(nchar(x) > 50,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
69 substr(x, 1, 50), x)}, USE.NAMES = FALSE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
70
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
71
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
72 name <- paste("GGO_", ontology, "_bar-plot", sep = "")
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
73 png(name, height = 720, width = 600)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
74 p <- barplot(ggo, showCategory = 10)
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
75 print(p)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
76 dev.off()
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
77 ggo <- as.data.frame(ggo)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
78 return(ggo)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
79 }
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
80 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
81
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
82 # nolint end
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
83
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
84 # GO over-representation test
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
85 enrich_go <- function(geneid, universe, orgdb, ontology, pval_cutoff,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
86 qval_cutoff, plot) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
87 ego <- enrichGO(gene = geneid,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
88
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
89 universe = universe,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
90 OrgDb = orgdb,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
91 ont = ontology,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
92 pAdjustMethod = "BH",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
93 pvalueCutoff = pval_cutoff,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
94 qvalueCutoff = qval_cutoff,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
95 readable = TRUE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
96
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
97 # Plot bar & dot plots
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
98 #if there are enriched GoTerms
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
99
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
100
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
101
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
102 if (length(ego$ID) > 0) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
103
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
104 ego@result$Description <- sapply(ego@result$Description, function(x) { #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
105 ifelse(nchar(x) > 50, substr(x, 1, 50), x)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
106 }, USE.NAMES = FALSE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
107
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
108
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
109 if ("dotplot" %in% plot) {
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
110 dot_name <- paste("EGO_", ontology, "_dot-plot", sep = "")
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
111 png(dot_name, height = 720, width = 600)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
112 p <- dotplot(ego, showCategory = 10) #nolint
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
113 print(p)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
114 dev.off()
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
115 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
116
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
117 if ("barplot" %in% plot) {
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
118 bar_name <- paste("EGO_", ontology, "_bar-plot", sep = "")
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
119 png(bar_name, height = 720, width = 600)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
120 p <- barplot(ego, showCategory = 10)
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
121 print(p)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
122 dev.off()
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
123 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
124
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
125 ego <- as.data.frame(ego)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
126 return(ego)
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
127 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
128 warning(paste("No Go terms enriched (EGO) found for ",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
129 ontology, "ontology"), immediate. = TRUE, noBreaks. = TRUE, call. = FALSE)
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
130 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
131 }
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
132
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
133
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
134 clean_ids <- function(ids) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
135 ids <- gsub(" ", "", ids)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
136 ids <- ids[which(ids != "")]
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
137 ids <- ids[which(ids != "NA")]
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
138 ids <- ids[!is.na(ids)]
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
139
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
140 return(ids)
10
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
141 }
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
142
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
143 check_ids <- function(vector, type) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
144 uniprot_pattern <- "^([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})$" #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
145 entrez_id <- "^([0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+)$" #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
146 if (type == "entrez") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
147 return(grepl(entrez_id, vector))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
148 }else if (type == "uniprot") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
149 return(grepl(uniprot_pattern, vector))
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
150 }
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
151 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
152
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
153 get_args <- function() {
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
154 args <- commandArgs(TRUE)
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
155 if (length(args) < 1) {
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
156 args <- c("--help")
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
157 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
158
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
159 # Help section
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
160 if ("--help" %in% args) {
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
161 cat("clusterProfiler Enrichment Analysis
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
162 Arguments:
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
163 --input_type: type of input (list of id or filename)
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
164 --input: input
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
165 --ncol: the column number which contains list of input IDs
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
166 --header: true/false if your file contains a header
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
167 --id_type: the type of input IDs (UniProt/EntrezID)
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
168 --universe_type: list or filename
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
169 --universe: background IDs list
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
170 --uncol: the column number which contains background IDs list
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
171 --uheader: true/false if the background IDs file contains header
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
172 --universe_id_type: the type of universe IDs (UniProt/EntrezID)
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
173 --species
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
174 --onto_opt: ontology options
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
175 --go_function: groupGO/enrichGO
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
176 --level: 1-3
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
177 --pval_cutoff
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
178 --qval_cutoff
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
179 --text_output: text output filename
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
180 --plot : type of visualization, dotplot or/and barplot \n")
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
181 q(save = "no")
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
182 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
183 # Parse arguments
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
184
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
185 parseargs <- function(x) strsplit(sub("^--", "", x), "=")
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
186 argsdf <- as.data.frame(do.call("rbind", parseargs(args)))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
187 args <- as.list(as.character(argsdf$V2))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
188 names(args) <- argsdf$V1
10
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
189 return(args)
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
190 }
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
191
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
192 main <- function() { #nolint
10
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
193 #get args from command
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
194 args <- get_args()
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
195
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
196 go_represent <- str2bool(args$go_represent)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
197 go_enrich <- str2bool(args$go_enrich)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
198 if (go_enrich) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
199 plot <- unlist(strsplit(args$plot, ","))
9
2f67202ffdb3 planemo upload commit 6ca074d75447a272b570f7709ed10d0c8356bec5-dirty
proteore
parents: 8
diff changeset
200 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
201
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
202 suppressMessages(library(args$species, character.only = TRUE, quietly = TRUE))
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
203
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
204 # Extract OrgDb
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
205 if (args$species == "org.Hs.eg.db") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
206 orgdb <- org.Hs.eg.db #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
207 } else if (args$species == "org.Mm.eg.db") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
208 orgdb <- org.Mm.eg.db #nolint
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
209 } else if (args$species == "org.Rn.eg.db") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
210 orgdb <- org.Rn.eg.db #nolint
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
211 }
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
212
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
213 # Extract input IDs
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
214 input_type <- args$input_type
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
215 id_type <- args$id_type
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
216
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
217 if (input_type == "text") {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
218 input <- unlist(strsplit(strsplit(args$input, "[ \t\n]+")[[1]], ";"))
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
219 } else if (input_type == "file") {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
220 filename <- args$input
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
221 ncol <- args$ncol
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
222 # Check ncol
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
223 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) {
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
224 stop("Please enter the right format for column number: c[number]")
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
225 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
226 ncol <- as.numeric(gsub("c", "", ncol))
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
227 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
228
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
229 header <- str2bool(args$header) # Get file content
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
230 file <- read_file(filename, header) # Extract Protein IDs list
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
231 input <- unlist(sapply(as.character(file[, ncol]),
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
232 function(x) rapply(strsplit(x, ";"), c), USE.NAMES = FALSE))
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
233 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
234 input <- clean_ids(input)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
235
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
236 ## Get input gene list from input IDs
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
237 #ID format Conversion
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
238 #This case : from UNIPROT (protein id) to ENTREZ (gene id)
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
239 #bitr = conversion function from clusterProfiler
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
240 if (id_type == "Uniprot" & any(check_ids(input, "uniprot"))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
241 any(check_ids(input, "uniprot"))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
242
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
243 idfrom <- "UNIPROT"
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
244 idto <- "ENTREZID"
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
245 suppressMessages(gene <- bitr(input, fromType = idfrom, toType = idto,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
246 OrgDb = orgdb))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
247
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
248 gene <- unique(gene$ENTREZID)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
249 } else if (id_type == "Entrez" & any(check_ids(input, "entrez"))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
250 gene <- unique(input)
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
251 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
252
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
253 stop(paste(id_type, "not found in your ids list,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
254 please check your IDs in input or the selected column of your input file"))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
255
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
256 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
257
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
258 ontology <- strsplit(args$onto_opt, ",")[[1]]
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
259
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
260 ## Extract GGO/EGO arguments
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
261 if (go_represent) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
262 level <- as.numeric(args$level)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
263
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
264 }
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
265
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
266 if (go_enrich) {
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
267 pval_cutoff <- as.numeric(args$pval_cutoff)
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
268 qval_cutoff <- as.numeric(args$qval_cutoff)
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
269 # Extract universe background genes (same as input file)
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
270 if (!is.null(args$universe_type)) {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
271 universe_type <- args$universe_type
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
272 if (universe_type == "text") {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
273 universe <- unlist(strsplit(strsplit(args$input, "[ \t\n]+")[[1]], ";"))
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
274 } else if (universe_type == "file") {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
275 universe_filename <- args$universe
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
276 universe_ncol <- args$uncol
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
277 # Check ncol
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
278 if (! as.numeric(gsub("c", "", universe_ncol)) %% 1 == 0) {
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
279 stop("Please enter the right format for column number: c[number]")
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
280 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
281 universe_ncol <- as.numeric(gsub("c", "", universe_ncol))
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
282 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
283 universe_header <- str2bool(args$uheader)
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
284 # Get file content
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
285 universe_file <- read_file(universe_filename, universe_header)
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
286 # Extract Protein IDs list
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
287 universe <- unlist(sapply(universe_file[, universe_ncol],
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
288 function(x) rapply(strsplit(x, ";"), c), USE.NAMES = FALSE))
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
289 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
290 universe <- clean_ids(input)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
291 universe_id_type <- args$universe_id_type
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
292 ##to initialize
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
293 if (universe_id_type == "Uniprot" & any(check_ids(universe, "uniprot"))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
294 idfrom <- "UNIPROT"
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
295 idto <- "ENTREZID"
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
296 suppressMessages(universe_gene <- bitr(universe, fromType = idfrom,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
297 toType = idto, OrgDb = orgdb))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
298 universe_gene <- unique(universe_gene$ENTREZID)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
299 } else if (universe_id_type == "Entrez" &
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
300 any(check_ids(universe, "entrez"))) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
301 universe_gene <- unique(unlist(universe))
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
302 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
303 if (universe_type == "text") {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
304 print(paste(universe_id_type, "not found in your background IDs list",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
305 sep = " "))
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
306 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
307 print(paste(universe_id_type, "not found in the column",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
308 universe_ncol, "of your background IDs file", sep = " "))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
309
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
310 }
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
311 universe_gene <- NULL
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
312 }
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
313 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
314 universe_gene <- NULL
6
5e16cec55146 planemo upload commit 2da0aec067fd35a8ec102ce27ec4bac8f54b1c30-dirty
proteore
parents: 5
diff changeset
315 }
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
316 } else {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
317 universe_gene <- NULL
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
318 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
319
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
320 ##enrichGO : GO over-representation test
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
321 for (onto in ontology) {
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
322 if (go_represent) {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
323 ggo <- repartition_go(gene, orgdb, onto, level, readable = TRUE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
324 if (is.list(ggo)) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
325 ggo <- as.data.frame(apply(ggo, c(1, 2),
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
326 function(x) gsub("^$|^ $", NA, x)))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
327 } #convert "" and " " to NA
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
328 output_path <- paste("cluster_profiler_GGO_", onto, ".tsv", sep = "")
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
329 write.table(ggo, output_path, sep = "\t",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
330 row.names = FALSE, quote = FALSE)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
331
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
332 }
7
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
333
4609346d8108 planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
proteore
parents: 6
diff changeset
334 if (go_enrich) {
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
335 ego <- enrich_go(gene, universe_gene, orgdb, onto, pval_cutoff,
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
336 qval_cutoff, plot)
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
337 if (is.list(ego)) {
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
338 ego <- as.data.frame(apply(ego, c(1, 2),
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
339 function(x) gsub("^$|^ $", NA, x)))
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
340 } #convert "" and " " to NA
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
341 output_path <- paste("cluster_profiler_EGO_", onto, ".tsv", sep = "")
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
342 write.table(ego, output_path, sep = "\t",
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
343 row.names = FALSE, quote = FALSE)
0
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
344 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
345 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
346 }
bd052861852b planemo upload commit ffa3be72b850aecbfbd636de815967c06a8f643f-dirty
proteore
parents:
diff changeset
347
13
f6107b8ae8f8 "planemo upload commit be9070db4a3b178ab45ecd9c9c3ab369240f7617-dirty"
proteore
parents: 10
diff changeset
348 if (!interactive()) {
10
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
349 main()
d951677a50d4 planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents: 9
diff changeset
350 }