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