Mercurial > repos > proteore > proteore_go_terms_enrich_comparison
annotate GO_terms_enrich_comparison.R @ 7:2e7245bd643d draft default tip
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
author | proteore |
---|---|
date | Tue, 04 Feb 2020 05:16:19 -0500 |
parents | 04f363ee805a |
children |
rev | line source |
---|---|
7
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
1 options(warn=-1) #TURN OFF WARNINGS !!!!!! |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
2 suppressMessages(library(clusterProfiler,quietly = TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
3 suppressMessages(library(plyr, quietly = TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
4 suppressMessages(library(ggplot2, quietly = TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
5 suppressMessages(library(DOSE, quietly = TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
6 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
7 #return the number of character from the longest description found (from the 10 first) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
8 max_str_length_10_first <- function(vector){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
9 vector <- as.vector(vector) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
10 nb_description = length(vector) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
11 if (nb_description >= 10){nb_description=10} |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
12 return(max(nchar(vector[1:nb_description]))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
13 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
14 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
15 str2bool <- function(x){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
16 if (any(is.element(c("t","true"),tolower(x)))){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
17 return (TRUE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
18 }else if (any(is.element(c("f","false"),tolower(x)))){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
19 return (FALSE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
20 }else{ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
21 return(NULL) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
22 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
23 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
24 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
25 get_args <- function(){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
26 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
27 ## Collect arguments |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
28 args <- commandArgs(TRUE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
29 #value = character vector of length=nb of arguments |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
30 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
31 ## Default setting when no arguments passed |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
32 if(length(args) < 1) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
33 args <- c("--help") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
34 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
35 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
36 ## Help section |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
37 if("--help" %in% args) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
38 cat("Selection and Annotation HPA |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
39 Arguments: |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
40 --inputtype1: type of input (list of id or filename) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
41 --inputtype2: type of input (list of id or filename) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
42 --inputtype3: type of input (list of id or filename) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
43 --input1: input1 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
44 --input2: input2 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
45 --input3: input3 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
46 --column1: the column number which you would like to apply... |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
47 --column2: the column number which you would like to apply... |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
48 --column3: the column number which you would like to apply... |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
49 --header1: true/false if your file contains a header |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
50 --header2: true/false if your file contains a header |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
51 --header3: true/false if your file contains a header |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
52 --ont: ontology to use |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
53 --org: organism db package |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
54 --list_name1: name of the first list |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
55 --list_name2: name of the second list |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
56 --list_name3: name of the third list \n") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
57 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
58 q(save="no") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
59 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
60 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
61 parseArgs <- function(x) strsplit(sub("^--", "", x), "=") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
62 argsDF <- as.data.frame(do.call("rbind", parseArgs(args))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
63 args <- as.list(as.character(argsDF$V2)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
64 names(args) <- argsDF$V1 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
65 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
66 return(args) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
67 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
68 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
69 get_ids=function(input, inputtype, header , ncol) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
70 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
71 if (inputtype == "text") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
72 ids = strsplit(input, "[ \t\n]+")[[1]] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
73 } else if (inputtype == "file") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
74 header=str2bool(header) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
75 ncol=get_cols(ncol) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
76 csv = read.csv(input,header=header, sep="\t", as.is=T) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
77 ids=csv[,ncol] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
78 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
79 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
80 ids = unlist(strsplit(as.character(ids),";")) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
81 ids = ids[which(!is.na(ids))] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
82 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
83 return(ids) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
84 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
85 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
86 str2bool <- function(x){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
87 if (any(is.element(c("t","true"),tolower(x)))){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
88 return (TRUE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
89 }else if (any(is.element(c("f","false"),tolower(x)))){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
90 return (FALSE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
91 }else{ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
92 return(NULL) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
93 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
94 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
95 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
96 check_ids <- function(vector,type) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
97 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})$" |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
98 entrez_id = "^([0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+)$" |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
99 if (type == "entrez") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
100 return(grepl(entrez_id,vector)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
101 else if (type == "uniprot") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
102 return(grepl(uniprot_pattern,vector)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
103 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
104 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
105 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
106 #res.cmp@compareClusterResult$Description <- sapply(as.vector(res.cmp@compareClusterResult$Description), function(x) {ifelse(nchar(x)>50, substr(x,1,50),x)},USE.NAMES = FALSE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
107 fortify.compareClusterResult <- function(res.cmp, showCategory=30, by="geneRatio", split=NULL, includeAll=TRUE) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
108 clProf.df <- as.data.frame(res.cmp) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
109 .split <- split |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
110 ## get top 5 (default) categories of each gene cluster. |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
111 if (is.null(showCategory)) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
112 result <- clProf.df |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
113 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
114 Cluster <- NULL # to satisfy codetools |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
115 topN <- function(res, showCategory) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
116 ddply(.data = res, .variables = .(Cluster), .fun = function(df, N) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
117 if (length(df$Count) > N) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
118 if (any(colnames(df) == "pvalue")) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
119 idx <- order(df$pvalue, decreasing=FALSE)[1:N] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
120 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
121 ## for groupGO |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
122 idx <- order(df$Count, decreasing=T)[1:N] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
123 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
124 return(df[idx,]) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
125 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
126 return(df) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
127 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
128 }, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
129 N=showCategory |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
130 ) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
131 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
132 if (!is.null(.split) && .split %in% colnames(clProf.df)) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
133 lres <- split(clProf.df, as.character(clProf.df[, .split])) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
134 lres <- lapply(lres, topN, showCategory = showCategory) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
135 result <- do.call('rbind', lres) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
136 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
137 result <- topN(clProf.df, showCategory) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
138 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
139 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
140 ID <- NULL |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
141 if (includeAll == TRUE) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
142 result = subset(clProf.df, ID %in% result$ID) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
143 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
144 ## remove zero count |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
145 result$Description <- as.character(result$Description) ## un-factor |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
146 GOlevel <- result[,c("ID", "Description")] ## GO ID and Term |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
147 #GOlevel <- unique(GOlevel) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
148 result <- result[result$Count != 0, ] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
149 #bug 19.11.2019 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
150 #result$Description <- factor(result$Description,levels=rev(GOlevel[,2])) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
151 if (by=="rowPercentage") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
152 Description <- Count <- NULL # to satisfy codetools |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
153 result <- ddply(result,.(Description),transform,Percentage = Count/sum(Count),Total = sum(Count)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
154 ## label GO Description with gene counts. |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
155 x <- mdply(result[, c("Description", "Total")], paste, sep=" (") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
156 y <- sapply(x[,3], paste, ")", sep="") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
157 result$Description <- y |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
158 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
159 ## restore the original order of GO Description |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
160 xx <- result[,c(2,3)] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
161 xx <- unique(xx) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
162 rownames(xx) <- xx[,1] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
163 Termlevel <- xx[as.character(GOlevel[,1]),2] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
164 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
165 ##drop the *Total* column |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
166 result <- result[, colnames(result) != "Total"] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
167 result$Description <- factor(result$Description, levels=rev(Termlevel)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
168 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
169 } else if (by == "count") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
170 ## nothing |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
171 } else if (by == "geneRatio") { ##default |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
172 gsize <- as.numeric(sub("/\\d+$", "", as.character(result$GeneRatio))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
173 gcsize <- as.numeric(sub("^\\d+/", "", as.character(result$GeneRatio))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
174 result$GeneRatio = gsize/gcsize |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
175 cluster <- paste(as.character(result$Cluster),"\n", "(", gcsize, ")", sep="") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
176 lv <- unique(cluster)[order(as.numeric(unique(result$Cluster)))] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
177 result$Cluster <- factor(cluster, levels = lv) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
178 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
179 ## nothing |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
180 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
181 return(result) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
182 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
183 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
184 ##function plotting.clusteProfile from clusterProfiler pkg |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
185 plotting.clusterProfile <- function(clProf.reshape.df,x = ~Cluster,type = "dot", colorBy = "p.adjust",by = "geneRatio",title="",font.size=12) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
186 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
187 Description <- Percentage <- Count <- Cluster <- GeneRatio <- p.adjust <- pvalue <- NULL # to |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
188 if (type == "dot") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
189 if (by == "rowPercentage") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
190 p <- ggplot(clProf.reshape.df, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
191 aes_(x = x, y = ~Description, size = ~Percentage)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
192 } else if (by == "count") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
193 p <- ggplot(clProf.reshape.df, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
194 aes_(x = x, y = ~Description, size = ~Count)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
195 } else if (by == "geneRatio") { ##DEFAULT |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
196 p <- ggplot(clProf.reshape.df, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
197 aes_(x = x, y = ~Description, size = ~GeneRatio)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
198 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
199 ## nothing here |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
200 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
201 if (any(colnames(clProf.reshape.df) == colorBy)) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
202 p <- p + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
203 geom_point() + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
204 aes_string(color=colorBy) + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
205 scale_color_continuous(low="red", high="blue", guide=guide_colorbar(reverse=TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
206 ## scale_color_gradientn(guide=guide_colorbar(reverse=TRUE), colors = enrichplot:::sig_palette) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
207 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
208 p <- p + geom_point(colour="steelblue") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
209 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
210 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
211 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
212 p <- p + xlab("") + ylab("") + ggtitle(title) + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
213 theme_dose(font.size) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
214 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
215 ## theme(axis.text.x = element_text(colour="black", size=font.size, vjust = 1)) + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
216 ## theme(axis.text.y = element_text(colour="black", |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
217 ## size=font.size, hjust = 1)) + |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
218 ## ggtitle(title)+theme_bw() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
219 ## p <- p + theme(axis.text.x = element_text(angle=angle.axis.x, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
220 ## hjust=hjust.axis.x, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
221 ## vjust=vjust.axis.x)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
222 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
223 return(p) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
224 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
225 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
226 make_dotplot<-function(res.cmp,ontology) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
227 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
228 dfok<-fortify.compareClusterResult(res.cmp) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
229 dfok$Description <- sapply(as.vector(dfok$Description), function(x) {ifelse(nchar(x)>50, substr(x,1,50),x)},USE.NAMES = FALSE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
230 p<-plotting.clusterProfile(dfok, title="") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
231 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
232 #plot(p, type="dot") # |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
233 output_path= paste("GO_enrich_comp_",ontology,".png",sep="") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
234 png(output_path,height = 720, width = 600) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
235 pl <- plot(p, type="dot") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
236 print(pl) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
237 dev.off() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
238 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
239 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
240 get_cols <-function(input_cols) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
241 input_cols <- gsub("c","",gsub("C","",gsub(" ","",input_cols))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
242 if (grepl(":",input_cols)) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
243 first_col=unlist(strsplit(input_cols,":"))[1] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
244 last_col=unlist(strsplit(input_cols,":"))[2] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
245 cols=first_col:last_col |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
246 } else { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
247 cols = as.integer(unlist(strsplit(input_cols,","))) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
248 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
249 return(cols) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
250 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
251 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
252 #to check |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
253 cmp.GO <- function(l,fun="enrichGO",orgdb, ontology, readable=TRUE) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
254 cmpGO<-compareCluster(geneClusters = l, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
255 fun=fun, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
256 OrgDb = orgdb, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
257 ont=ontology, |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
258 readable=TRUE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
259 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
260 return(cmpGO) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
261 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
262 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
263 check_ids <- function(vector,type) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
264 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})$" |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
265 entrez_id = "^([0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+)$" |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
266 if (type == "entrez") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
267 return(grepl(entrez_id,vector)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
268 else if (type == "uniprot") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
269 return(grepl(uniprot_pattern,vector)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
270 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
271 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
272 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
273 main = function() { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
274 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
275 #to get the args of the command line |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
276 args=get_args() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
277 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
278 #saved |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
279 #l<-list() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
280 #for(j in 1:args$nb){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
281 # i<-j-1 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
282 # ids<-get_ids(args$input.i, args$inputtype.i, args$header.i, args$column.i) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
283 # l[[args$name.i]]<-ids |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
284 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
285 #} |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
286 #saved |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
287 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
288 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
289 l<-list() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
290 for(j in 1:args$nb){ |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
291 i<-j-1 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
292 ids<-get_ids( args[[paste("input",i,sep=".")]], |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
293 args[[paste("inputtype",i,sep=".")]], |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
294 args[[paste("header",i,sep=".")]], |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
295 args[[paste("column",i,sep=".")]] ) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
296 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
297 l[[args[[paste("name",i,sep=".")]]]]<-ids |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
298 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
299 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
300 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
301 ont = strsplit(args$ont, ",")[[1]] |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
302 org=args$org |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
303 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
304 #load annot package |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
305 suppressMessages(library(args$org, character.only = TRUE, quietly = TRUE)) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
306 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
307 # Extract OrgDb |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
308 if (args$org=="org.Hs.eg.db") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
309 orgdb<-org.Hs.eg.db |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
310 } else if (args$org=="org.Mm.eg.db") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
311 orgdb<-org.Mm.eg.db |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
312 } else if (args$org=="org.Rn.eg.db") { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
313 orgdb<-org.Rn.eg.db |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
314 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
315 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
316 for(ontology in ont) { |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
317 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
318 res.cmp<-cmp.GO(l=l,fun="enrichGO",orgdb, ontology, readable=TRUE) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
319 make_dotplot(res.cmp,ontology) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
320 output_path = paste("GO_enrich_comp_",ontology,".tsv",sep="") |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
321 write.table(res.cmp@compareClusterResult, output_path, sep="\t", row.names=F, quote=F) |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
322 } |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
323 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
324 } #end main |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
325 |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
326 main() |
2e7245bd643d
"planemo upload commit 373a85c4179ac6b5cfc77013eab020badb8c8370-dirty"
proteore
parents:
0
diff
changeset
|
327 |