Mercurial > repos > proteore > proteore_topgo
annotate topGO_enrichment.R @ 16:7f1ce70f0f09 draft default tip
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
author | proteore |
---|---|
date | Mon, 17 May 2021 14:40:03 +0000 |
parents | 8eaa43ba1bfc |
children |
rev | line source |
---|---|
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
1 options(warn = -1) #TURN OFF WARNINGS !!!!!! |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
2 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
3 suppressMessages(library(ggplot2)) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
4 suppressMessages(library(topGO)) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
5 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
6 get_args <- function() { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
7 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
8 ## Collect arguments |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
9 args <- commandArgs(TRUE) |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
10 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
11 ## Default setting when no arguments passed |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
12 if (length(args) < 1) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
13 args <- c("--help") |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
14 } |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
15 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
16 ## Help section |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
17 if ("--help" %in% args) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
18 cat("Pathview R script |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
19 Arguments: |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
20 --help Print this test |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
21 --input_type |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
22 --onto |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
23 --option |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
24 --correction |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
25 --threshold |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
26 --text |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
27 --plot |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
28 --column |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
29 --geneuniverse |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
30 --header |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
31 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
32 Example: |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
33 Rscript --vanilla enrichment_v3.R --inputtype=tabfile (or copypaste) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
34 --input=file.txt --ontology='BP/CC/MF' --option=option |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
35 (e.g : classic/elim...) --threshold=threshold --correction=correction |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
36 --textoutput=text --barplotoutput=barplot --dotplotoutput=dotplot |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
37 --column=column --geneuniver=human \n\n") |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
38 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
39 q(save = "no") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
40 } |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
41 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
42 parseargs <- function(x) strsplit(sub("^--", "", x), "=") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
43 argsdf <- as.data.frame(do.call("rbind", parseargs(args))) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
44 args <- as.list(as.character(argsdf$V2)) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
45 names(args) <- argsdf$V1 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
46 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
47 return(args) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
48 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
49 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
50 read_file <- function(path, header) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
51 file <- try(read.csv(path, header = header, sep = "\t", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
52 stringsAsFactors = FALSE, quote = "\"", check.names = F), |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
53 silent = TRUE) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
54 if (inherits(file, "try-error")) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
55 stop("File not found !") |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
56 }else { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
57 return(file) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
58 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
59 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
60 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
61 get_list_from_cp <- function(list) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
62 list <- gsub(";", " ", list) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
63 list <- strsplit(list, "[ \t\n]+")[[1]] |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
64 list <- list[list != ""] #remove empty entry |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
65 list <- gsub("-.+", "", list) #Remove isoform accession number (e.g. "-2") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
66 return(list) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
67 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
68 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
69 check_ens_ids <- function(vector) { |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
70 ens_pattern <- |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
71 "^(ENS[A-Z]+[0-9]{11}|[A-Z]{3}[0-9]{3}[A-Za-z](-[A-Za-z])? |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
72 |CG[0-9]+|[A-Z0-9]+\\.[0-9]+|YM[A-Z][0-9]{3}[a-z][0-9])$" |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
73 return(grepl(ens_pattern, vector)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
74 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
75 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
76 str2bool <- function(x) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
77 if (any(is.element(c("t", "true"), tolower(x)))) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
78 return(TRUE) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
79 }else if (any(is.element(c("f", "false"), tolower(x)))) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
80 return(FALSE) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
81 }else { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
82 return(NULL) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
83 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
84 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
85 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
86 # Some libraries such as GOsummaries won't be able to treat the values such as |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
87 # "< 1e-30" produced by topGO. As such it is important to delete the < char |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
88 # with the deleteinfchar function. Nevertheless the user will have access to |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
89 #the original results in the text output. |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
90 deleteinfchar <- function(values) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
91 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
92 lines <- grep("<", values) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
93 if (length(lines) != 0) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
94 for (line in lines) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
95 values[line] <- gsub("<", "", values[line]) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
96 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
97 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
98 return(values) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
99 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
100 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
101 #nolint start |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
102 corrMultipleTesting = function(result, mygodata, correction, threshold){ |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
103 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
104 # adjust for multiple testing |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
105 if (correction != "none"){ |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
106 # GenTable : transforms the result object into a list. Filters can be applied |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
107 # (e.g : with the topNodes argument, to get for instance only the n first |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
108 # GO terms with the lowest pvalues), but as we want to apply a correction we |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
109 # take all the GO terms, no matter their pvalues |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
110 allRes <- GenTable(mygodata, test = result, orderBy = "result", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
111 ranksOf = "result", topNodes = length(attributes(result)$score)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
112 # Some pvalues given by topGO are not numeric (e.g : "<1e-30). As such, these |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
113 # values are converted to 1e-30 to be able to correct the pvalues |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
114 pvaluestmp = deleteinfchar(allRes$test) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
115 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
116 # the correction is done from the modified pvalues |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
117 allRes$qvalues = p.adjust(pvaluestmp, method = as.character(correction), |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
118 n = length(pvaluestmp)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
119 allRes = as.data.frame(allRes) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
120 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
121 # Rename the test column by pvalues, so that is more explicit |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
122 nb = which(names(allRes) %in% c("test")) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
123 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
124 names(allRes)[nb] = "pvalues" |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
125 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
126 allRes = allRes[which(as.numeric(allRes$pvalues) <= threshold), ] |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
127 if (length(allRes$pvalues) == 0) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
128 print("Threshold was too stringent, no GO term found with pvalue |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
129 equal or lesser than the threshold value") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
130 return(NULL) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
131 } |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
132 allRes = allRes[order(allRes$qvalues), ] |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
133 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
134 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
135 if (correction == "none"){ |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
136 # get all the go terms under user threshold |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
137 mysummary <- summary(attributes(result)$score <= threshold) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
138 numsignif <- as.integer(mysummary[[3]]) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
139 # get all significant nodes |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
140 allRes <- GenTable(mygodata, test = result, orderBy = "result", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
141 ranksOf = "result", topNodes = numsignif) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
142 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
143 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
144 allRes = as.data.frame(allRes) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
145 # Rename the test column by pvalues, so that is more explicit |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
146 nb = which(names(allRes) %in% c("test")) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
147 names(allRes)[nb] = "pvalues" |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
148 if (numsignif == 0) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
149 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
150 print("Threshold was too stringent, no GO term found with pvalue |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
151 equal or lesser than the threshold value") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
152 return(NULL) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
153 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
154 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
155 allRes = allRes[order(allRes$pvalues), ] |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
156 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
157 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
158 return(allRes) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
159 } |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
160 #nolint end |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
161 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
162 #roundvalues will simplify the results by rounding down the values. |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
163 #For instance 1.1e-17 becomes 1e-17 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
164 roundvalues <- function(values) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
165 for (line in seq_len(length(values))) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
166 values[line] <- as.numeric(gsub(".*e", "1e", as.character(values[line]))) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
167 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
168 return(values) |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
169 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
170 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
171 #nolint start |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
172 createDotPlot = function(data, onto) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
173 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
174 values = deleteinfchar(data$pvalues) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
175 values = roundvalues(values) |
11
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
176 values = as.numeric(values) |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
177 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
178 geneRatio = data$Significant / data$Annotated |
11
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
179 goTerms = data$Term |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
180 count = data$Significant |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
181 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
182 labely = paste("GO terms", onto, sep = " ") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
183 ggplot(data, aes(x = geneRatio, y = goTerms, color = values, size=count)) + geom_point( ) + scale_colour_gradientn( colours = c("red", "violet", "blue")) + xlab("Gene Ratio") + ylab(labely) + labs(color = "p-values\n" ) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
184 ggsave("dotplot.png", device = "png", dpi = 320, limitsize = TRUE, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
185 width = 15, height = 15, units = "cm") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
186 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
187 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
188 createBarPlot = function(data, onto) { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
189 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
190 values = deleteinfchar(data$pvalues) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
191 values = roundvalues(values) |
11
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
192 values = as.numeric(values) |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
193 |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
194 goTerms = data$Term |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
195 count = data$Significant |
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
196 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
197 labely = paste("GO terms", onto, sep=" ") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
198 ggplot(data, aes(x = goTerms, y = count, fill = values, scale(scale = 0.5))) + ylab("Gene count") + xlab(labely) + geom_bar(stat = "identity") + scale_fill_gradientn(colours = c("red","violet","blue")) + coord_flip() + labs(fill = "p-values\n") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
199 ggsave("barplot.png", device = "png", dpi = 320, limitsize = TRUE, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
200 width = 15, height = 15, units = "cm") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
201 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
202 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
203 #nolint end |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
204 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
205 # Produce the different outputs |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
206 createoutputs <- function(result, cut_result, text, barplot, dotplot, onto) { |
11
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
207 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
208 if (is.null(result)) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
209 err_msg <- "None of the input ids can be found in the org package data, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
210 enrichment analysis cannot be realized. \n The inputs ids probably |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
211 either have no associated GO terms or are not ENSG identifiers |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
212 (e.g : ENSG00000012048)." |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
213 write.table(err_msg, file = "result", quote = FALSE, sep = "\t", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
214 col.names = F, row.names = F) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
215 }else if (is.null(cut_result)) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
216 err_msg <- "Threshold was too stringent, no GO term found with pvalue equal |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
217 or lesser than the threshold value." |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
218 write.table(err_msg, file = "result.tsv", quote = FALSE, sep = "\t", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
219 col.names = F, row.names = F) |
11
fa2e27165d5d
planemo upload commit 4efc56eb769fbceb66c64181441ff8781d523454-dirty
proteore
parents:
10
diff
changeset
|
220 }else { |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
221 write.table(cut_result, file = "result.tsv", quote = FALSE, sep = "\t", |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
222 col.names = T, row.names = F) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
223 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
224 if (barplot) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
225 createBarPlot(cut_result, onto) #nolint |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
226 } |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
227 if (dotplot) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
228 createDotPlot(cut_result, onto) #nolint |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
229 } |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
230 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
231 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
232 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
233 # Launch enrichment analysis and return result data from the analysis or the |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
234 # null object if the enrichment could not be done. |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
235 goenrichment <- function(geneuniverse, sample, background_sample, onto) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
236 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
237 if (is.null(background_sample)) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
238 xx <- annFUN.org(onto, mapping = geneuniverse, ID = "ensembl") #nolint |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
239 #get all the GO terms of the corresponding ontology (BP/CC/MF) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
240 #and all their associated ensembl ids according to the org package |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
241 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
242 #nolint start |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
243 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
244 allGenes <- unique(unlist(xx)) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
245 #check if the genes given by the user can be found in the org package |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
246 #(gene universe), that is in allGenes |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
247 } else { |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
248 allGenes <- background_sample |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
249 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
250 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
251 if (length(intersect(sample,allGenes)) == 0) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
252 print("None of the input ids can be found in the org package data, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
253 enrichment analysis cannot be realized. \n The inputs ids probably |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
254 have no associated GO terms.") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
255 return(c(NULL, NULL)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
256 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
257 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
258 geneList <- factor(as.integer(allGenes %in% sample)) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
259 #duplicated ids in sample count only for one |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
260 if (length(levels(geneList)) == 1 ){ |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
261 stop("All or none of the background genes are found in tested genes dataset, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
262 enrichment analysis can't be done") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
263 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
264 names(geneList) <- allGenes |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
265 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
266 #nolint end |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
267 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
268 #topGO enrichment |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
269 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
270 # Creation of a topGOdata object |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
271 # It will contain : the list of genes of interest, the GO annotations and |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
272 # the GO hierarchy |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
273 # Parameters : |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
274 # ontology : character string specifying the ontology of interest (BP, CC, MF) |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
275 # allGenes : named vector of type numeric or factor |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
276 # annot : tells topGO how to map genes to GO annotations. |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
277 # argument not used here : nodeSize : at which minimal number of GO |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
278 # annotations do we consider a gene |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
279 |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
280 mygodata <- new("topGOdata", description = "SEA with TopGO", ontology = onto, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
281 allGenes = geneList, annot = annFUN.org, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
282 mapping = geneuniverse, ID = "ensembl") |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
283 |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
284 # Performing enrichment tests |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
285 result <- runTest(mygodata, algorithm = option, statistic = "fisher") #nolint |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
286 return(c(result, mygodata)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
287 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
288 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
289 args <- get_args() |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
290 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
291 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
292 input_type <- args$inputtype |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
293 input <- args$input |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
294 onto <- args$ontology |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
295 option <- args$option |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
296 correction <- args$correction |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
297 threshold <- as.numeric(args$threshold) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
298 text <- str2bool(args$textoutput) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
299 barplot <- "barplot" %in% unlist(strsplit(args$plot, ",")) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
300 dotplot <- "dotplot" %in% unlist(strsplit(args$plot, ",")) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
301 column <- as.numeric(gsub("c", "", args$column)) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
302 geneuniverse <- args$geneuniverse |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
303 header <- str2bool(args$header) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
304 background <- str2bool(args$background) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
305 if (background) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
306 background_genes <- args$background_genes |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
307 background_input_type <- args$background_input_type |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
308 background_header <- str2bool(args$background_header) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
309 background_column <- as.numeric(gsub("c", "", args$background_column)) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
310 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
311 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
312 #get input |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
313 if (input_type == "copy_paste") { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
314 sample <- get_list_from_cp(input) |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
315 } else if (input_type == "file") { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
316 tab <- read_file(input, header) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
317 sample <- trimws(unlist(strsplit(tab[, column], ";"))) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
318 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
319 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
320 #check of ENS ids |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
321 if (! any(check_ens_ids(sample))) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
322 stop("no ensembl gene ids found in your ids list, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
323 please check your IDs in input or the selected column of your input file") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
324 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
325 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
326 #get input if background genes |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
327 if (background) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
328 if (background_input_type == "copy_paste") { |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
329 background_sample <- get_list_from_cp(background_genes) |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
330 } else if (background_input_type == "file") { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
331 background_tab <- read_file(background_genes, background_header) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
332 background_sample <- unique(trimws(unlist( |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
333 strsplit(background_tab[, background_column], ";")))) |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
334 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
335 #check of ENS ids |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
336 if (! any(check_ens_ids(background_sample))) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
337 stop("no ensembl gene ids found in your background ids list, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
338 please check your IDs in input or the selected column of your input file") |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
339 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
340 } else { |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
341 background_sample <- NULL |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
342 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
343 |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
344 # Launch enrichment analysis |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
345 allresult <- suppressMessages(goenrichment(geneuniverse, sample, |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
346 background_sample, onto)) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
347 result <- allresult[1][[1]] |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
348 mygodata <- allresult[2][[1]] |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
349 if (!is.null(result)) { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
350 cut_result <- corrMultipleTesting(result, mygodata, correction, threshold) |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
351 #Adjust the result with a multiple testing correction or not and with the |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
352 #user, p-value cutoff |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
353 }else { |
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
354 cut_result <- NULL |
10
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
355 } |
e3430084c996
planemo upload commit ad5f1c5a1a71d7fa2bc8bac408856aa80b0fc2a3
proteore
parents:
diff
changeset
|
356 |
16
7f1ce70f0f09
"planemo upload commit 29a04769c0546be759c38bbcc157c8bc09ec1115-dirty"
proteore
parents:
12
diff
changeset
|
357 createoutputs(result, cut_result, text, barplot, dotplot, onto) |