annotate src/VolcanoPlotsScript.R @ 0:14045c80a222 draft

"planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
author vandelj
date Fri, 26 Jun 2020 09:38:23 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
1 # R script to plot volcanos through Galaxy based GIANT tool
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
2 # written by Jimmy Vandel
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
3 #
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
4 #
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
5 initial.options <- commandArgs(trailingOnly = FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
6 file.arg.name <- "--file="
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
7 script.name <- sub(file.arg.name, "", initial.options[grep(file.arg.name, initial.options)])
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
8 script.basename <- dirname(script.name)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
9 source(file.path(script.basename, "utils.R"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
10 source(file.path(script.basename, "getopt.R"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
11
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
12 #addComment("Welcome R!")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
13
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
14 # setup R error handling to go to stderr
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
15 options( show.error.messages=F, error = function () { cat(geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
16
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
17 # we need that to not crash galaxy with an UTF8 error on German LC settings.
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
18 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
19 loc <- Sys.setlocale("LC_NUMERIC", "C")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
20
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
21 #get starting time
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
22 start.time <- Sys.time()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
23
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
24 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
25 args <- commandArgs()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
26
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
27 # get options, using the spec as defined by the enclosed list.
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
28 # we read the options from the default: commandArgs(TRUE).
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
29 spec <- matrix(c(
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
30 "statisticsFile", "i", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
31 "volcanoName" , "n", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
32 "pvalColumnName" , "p", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
33 "fdrColumnName" , "m", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
34 "fcColumnName" , "c", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
35 "fcKind","d", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
36 "fdrThreshold","s", 1, "double",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
37 "fcThreshold","e", 1, "double",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
38 "organismID","x",1,"character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
39 "rowNameType","y",1,"character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
40 "log", "l", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
41 "outputFile" , "o", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
42 "format", "f", 1, "character",
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
43 "quiet", "q", 0, "logical"),
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
44 byrow=TRUE, ncol=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
45 opt <- getopt(spec)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
46
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
47 # enforce the following required arguments
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
48 if (is.null(opt$log)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
49 addComment("[ERROR]'log file' is required\n")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
50 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
51 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
52 addComment("[INFO]Start of R script",T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
53 if (is.null(opt$statisticsFile)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
54 addComment("[ERROR]'statisticsFile' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
55 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
56 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
57 if (length(opt$pvalColumnName)==0 || length(opt$fdrColumnName)==0 || length(opt$fcColumnName)==0) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
58 addComment("[ERROR]no selected columns",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
59 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
60 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
61 if (length(opt$pvalColumnName)!=length(opt$fcColumnName) || length(opt$pvalColumnName)!=length(opt$fdrColumnName)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
62 addComment("[ERROR]different number of selected columns between p.val, adj-p.val and FC ",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
63 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
64 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
65 if (is.null(opt$fcKind)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
66 addComment("[ERROR]'fcKind' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
67 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
68 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
69 if (is.null(opt$fdrThreshold)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
70 addComment("[ERROR]'FDR threshold' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
71 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
72 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
73 if (is.null(opt$fcThreshold)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
74 addComment("[ERROR]'FC threshold' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
75 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
76 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
77 if (is.null(opt$outputFile)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
78 addComment("[ERROR]'output file' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
79 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
80 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
81 if (is.null(opt$format)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
82 addComment("[ERROR]'output format' is required",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
83 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
84 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
85
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
86 #demande si le script sera bavard
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
87 verbose <- if (is.null(opt$quiet)) {
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
88 TRUE
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
89 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
90 FALSE
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
91 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
92
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
93 #paramètres internes
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
94 addComment("[INFO]Parameters checked test mode !",T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
95
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
96 addComment(c("[INFO]Working directory: ",getwd()),TRUE,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
97 addComment(c("[INFO]Command line: ",args),TRUE,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
98
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
99 #directory for plots
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
100 dir.create(file.path(getwd(), "plotDir"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
101 dir.create(file.path(getwd(), "plotLyDir"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
102
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
103 #charge des packages silencieusement
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
104 suppressPackageStartupMessages({
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
105 library("methods")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
106 library("biomaRt")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
107 library("ggplot2")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
108 library("plotly")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
109 library("stringr")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
110 })
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
111
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
112 #define some usefull variable
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
113 nbVolcanosToPlot=length(opt$pvalColumnName)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
114
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
115 #load input file
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
116 statDataMatrix=read.csv(file=file.path(getwd(), opt$statisticsFile),header=F,sep="\t",colClasses="character")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
117 #remove first colum to convert it as rownames
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
118 rownames(statDataMatrix)=statDataMatrix[,1]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
119 statDataMatrix=statDataMatrix[,-1]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
120
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
121 #identify lines without adjusted p-value info (should contain the same content as rownames) and replace them with NA values
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
122 FDRinfo=rep(TRUE,nbVolcanosToPlot)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
123 for(iVolcano in 1:nbVolcanosToPlot){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
124 #input parameter should be None when adjusted p-val are not available
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
125 if(opt$fdrColumnName[iVolcano]=="None"){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
126 #content of the corresponding column should also be the same as rownames
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
127 if(!all(statDataMatrix[,(iVolcano-1)*3+2]==rownames(statDataMatrix))){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
128 addComment(c("[ERROR]It seems that input stat matrix contains adjusted p-values for volcano",iVolcano,"whereas input parameter indicates that not."),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
129 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
130 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
131 FDRinfo[iVolcano]=FALSE
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
132 statDataMatrix[,(iVolcano-1)*3+2]=NA
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
133 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
134 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
135
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
136 if(is.data.frame(statDataMatrix)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
137 statDataMatrix=data.matrix(statDataMatrix)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
138 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
139 statDataMatrix=data.matrix(as.numeric(statDataMatrix))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
140 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
141
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
142 #check if available column number match with volcano requested number
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
143 if(ncol(statDataMatrix)!=3*nbVolcanosToPlot){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
144 addComment("[ERROR]Input file column number is different from requested volcano number",T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
145 q( "no", 1, F )
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
146 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
147
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
148 #build global dataFrame with data and fill with p.val and log2(FC) and FDR
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
149 dataFrame=data.frame(row.names = rownames(statDataMatrix))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
150 #start with p-value
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
151 dataFrame$p.value=statDataMatrix[,seq(1,nbVolcanosToPlot*3,3),drop=FALSE]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
152 #compute FDR if needed or just get available info
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
153 dataFrame$adj_p.value=dataFrame$p.value
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
154 for(iVolcano in 1:nbVolcanosToPlot){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
155 #adjusted p-value are already computed
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
156 if(FDRinfo[iVolcano]){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
157 dataFrame$adj_p.value[,iVolcano]=statDataMatrix[,(iVolcano-1)*3+2,drop=FALSE]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
158 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
159 #adjusted p-value should be computed based on p-val using FDR
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
160 dataFrame$adj_p.value[,iVolcano]=p.adjust(dataFrame$p.value[,iVolcano,drop=FALSE],"fdr")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
161 addComment(c("[INFO]Adjusted p-values are not available in input for volcano",iVolcano,", FDR approach will be used on available raw p-values"),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
162 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
163 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
164 if(opt$fcKind=="FC"){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
165 #we should transform as Log2FC
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
166 dataFrame$coefficients=log2(statDataMatrix[,seq(3,nbVolcanosToPlot*3,3),drop=FALSE])
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
167 addComment(c("[INFO]FC are converted in log2(FC) for plotting"),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
168 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
169 dataFrame$coefficients=statDataMatrix[,seq(3,nbVolcanosToPlot*3,3),drop=FALSE]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
170 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
171
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
172 addComment(c("[INFO]Input data available for",nbVolcanosToPlot,"volcano(s) with",nrow(statDataMatrix),"rows"),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
173
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
174
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
175 #plot VOLCANOs
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
176 volcanoPerPage=1
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
177 logFCthreshold=log2(opt$fcThreshold)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
178 iToPlot=1
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
179 plotVector=list()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
180 volcanoNameList=c()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
181 for (iVolcano in 1:nbVolcanosToPlot){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
182
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
183 if(nchar(opt$volcanoName[iVolcano])>0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
184 curentVolcanoName=opt$volcanoName[iVolcano]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
185 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
186 curentVolcanoName=paste(iVolcano,opt$pvalColumnName[iVolcano],sep="_")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
187 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
188
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
189 #keep only rows without NA for p-val, adjusted p-val and coeff
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
190 pValToPlot=dataFrame$p.value[,iVolcano]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
191 fdrToPlot=dataFrame$adj_p.value[,iVolcano]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
192 coeffToPlot=dataFrame$coefficients[,iVolcano]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
193
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
194 rowToRemove=unique(c(which(is.na(pValToPlot)),which(is.na(fdrToPlot)),which(is.na(coeffToPlot))))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
195 if(length(rowToRemove)>0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
196 pValToPlot=pValToPlot[-rowToRemove]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
197 fdrToPlot=fdrToPlot[-rowToRemove]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
198 coeffToPlot=coeffToPlot[-rowToRemove]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
199 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
200 addComment(c("[INFO]For",curentVolcanoName,"volcano,",length(rowToRemove),"rows are discarded due to NA values,",length(pValToPlot),"remaining rows."),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
201
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
202 #save volcano name
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
203 volcanoNameList=c(volcanoNameList,curentVolcanoName)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
204
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
205 #remove characters possibly troubling
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
206 volcanoFileName=iVolcano
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
207
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
208 #define the log10(p-val) threshold corresponding to FDR threshold fixed by user
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
209 probeWithLowFDR=-log10(pValToPlot[which(fdrToPlot<=opt$fdrThreshold)])
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
210 pvalThresholdFDR=NULL
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
211 if(length(probeWithLowFDR)>0)pvalThresholdFDR=min(probeWithLowFDR)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
212
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
213 #get significant points over FC and FDR thresholds
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
214 significativePoints=intersect(which(abs(coeffToPlot)>=logFCthreshold),which(fdrToPlot<=opt$fdrThreshold))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
215
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
216 #to reduce size of html plot, we keep 20000 points maximum sampled amongst genes with pval>=33%(pval) and abs(log2(FC))<=66%(abs(log2(FC)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
217 htmlPointsToRemove=intersect(which(abs(coeffToPlot)<=quantile(abs(coeffToPlot),c(0.66))),which(pValToPlot>=quantile(abs(pValToPlot),c(0.33))))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
218 if(length(htmlPointsToRemove)>20000){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
219 htmlPointsToRemove=setdiff(htmlPointsToRemove,sample(htmlPointsToRemove,20000))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
220 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
221 htmlPointsToRemove=c()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
222 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
223
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
224 xMinLimPlot=min(coeffToPlot)-0.2
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
225 xMaxLimPlot=max(coeffToPlot)+0.2
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
226 yMaxLimPlot= max(-log10(pValToPlot))+0.2
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
227
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
228 if(length(significativePoints)>0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
229 dataSignifToPlot=data.frame(pval=-log10(pValToPlot[significativePoints]),FC=coeffToPlot[significativePoints],description=paste(names(coeffToPlot[significativePoints]),"\n","FC: " , round(2^coeffToPlot[significativePoints],2) , " | Adjusted p-val: ",prettyNum(fdrToPlot[significativePoints],digits=4), sep=""))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
230 #to test if remains any normal points to draw
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
231 if(length(significativePoints)<length(pValToPlot)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
232 dataToPlot=data.frame(pval=-log10(pValToPlot[-significativePoints]),FC=coeffToPlot[-significativePoints],description=paste("FC: " , round(2^coeffToPlot[-significativePoints],2) , " | Adjusted p-val: ",prettyNum(fdrToPlot[-significativePoints],digits=4), sep=""))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
233 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
234 dataToPlot=data.frame(pval=0,FC=0,description="null")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
235 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
236 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
237 dataToPlot=data.frame(pval=-log10(pValToPlot),FC=coeffToPlot,description=paste("FC: " , round(2^coeffToPlot,2) , " | Adjusted p-val: ",prettyNum(fdrToPlot,digits=4), sep=""))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
238 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
239
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
240 ##traditional plot
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
241
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
242 p <- ggplot(data=dataToPlot, aes(x=FC, y=pval)) + geom_point() +
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
243 theme_bw() + ggtitle(curentVolcanoName) + ylab(label="-Log10(p-val)") + xlab(label="Log2 Fold Change") +
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
244 theme(panel.border=element_blank(),plot.title = element_text(hjust = 0.5),legend.position="none")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
245 if(logFCthreshold!=0) p <- p + geom_vline(xintercept=-logFCthreshold, color="salmon",linetype="dotted", size=1) + geom_vline(xintercept=logFCthreshold, color="salmon",linetype="dotted", size=1) + geom_text(data.frame(text=c(paste(c("log2(1/FC=",opt$fcThreshold,")"),collapse=""),paste(c("log2(FC=",opt$fcThreshold,")"),collapse="")),x=c(-logFCthreshold,logFCthreshold),y=c(0,0)),mapping=aes(x=x, y=y, label=text), size=4, angle=90, vjust=-0.4, hjust=0, color="salmon")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
246 if(!is.null(pvalThresholdFDR)) p <- p + geom_hline(yintercept=pvalThresholdFDR, color="skyblue1",linetype="dotted", size=0.5) + geom_text(data.frame(text=c(paste(c("Adjusted pval limit(",opt$fdrThreshold,")"),collapse="")),x=c(xMinLimPlot),y=c(pvalThresholdFDR)),mapping=aes(x=x, y=y, label=text), size=4, vjust=0, hjust=0, color="skyblue3")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
247 if(length(significativePoints)>0)p <- p + geom_point(data=dataSignifToPlot,aes(colour=description))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
248
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
249 ##interactive plot
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
250
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
251 if(length(htmlPointsToRemove)>0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
252 pointToRemove=union(htmlPointsToRemove,significativePoints)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
253 #to test if it remains any normal points to draw
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
254 if(length(pointToRemove)<length(pValToPlot)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
255 dataToPlot=data.frame(pval=-log10(pValToPlot[-pointToRemove]),FC=coeffToPlot[-pointToRemove],description=paste("FC: " , round(2^coeffToPlot[-pointToRemove],2) , " | Adjusted p-val: ", prettyNum(fdrToPlot[-pointToRemove],digits=4), sep=""))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
256 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
257 dataToPlot=data.frame(pval=0,FC=0,description="null")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
258 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
259 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
260
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
261 if((nrow(dataToPlot)+length(significativePoints))>40000)addComment(c("[WARNING]For",curentVolcanoName,"volcano, numerous points to plot(",nrow(dataToPlot)+nrow(dataSignifToPlot),"), resulting volcano could be heavy, using more stringent thresholds could be helpful."),T,opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
262
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
263 phtml <- plot_ly(data=dataToPlot, x=~FC, y=~pval,type="scatter", mode="markers",showlegend = FALSE, marker = list(color="gray",opacity=0.5), text=~description, hoverinfo="text") %>%
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
264 layout(title = curentVolcanoName[iVolcano],xaxis=list(title="Log2 Fold Change",showgrid=TRUE, zeroline=FALSE),yaxis=list(title="-Log10(p-val)", showgrid=TRUE, zeroline=FALSE))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
265 if(length(significativePoints)>0) phtml=add_markers(phtml,data=dataSignifToPlot, x=~FC, y=~pval, mode="markers" , marker=list( color=log10(abs(dataSignifToPlot$FC)*dataSignifToPlot$pval),colorscale='Rainbow'), text=~description, hoverinfo="text", inherit = FALSE) %>% hide_colorbar()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
266 if(logFCthreshold!=0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
267 phtml=add_trace(phtml,x=c(-logFCthreshold,-logFCthreshold), y=c(0,yMaxLimPlot), type="scatter", mode = "lines", line=list(color="coral",dash="dash"), hoverinfo='none', showlegend = FALSE,inherit = FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
268 phtml=add_annotations(phtml,x=-logFCthreshold,y=0,xref = "x",yref = "y",text = paste(c("log2(1/FC=",opt$fcThreshold,")"),collapse=""),xanchor = 'right',showarrow = F,textangle=270,font=list(color="coral"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
269 phtml=add_trace(phtml,x=c(logFCthreshold,logFCthreshold), y=c(0, yMaxLimPlot), type="scatter", mode = "lines", line=list(color="coral",dash="dash"), hoverinfo='none', showlegend = FALSE,inherit = FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
270 phtml=add_annotations(phtml,x=logFCthreshold,y=0,xref = "x",yref = "y",text = paste(c("log2(FC=",opt$fcThreshold,")"),collapse=""),xanchor = 'right',showarrow = F,textangle=270,font=list(color="coral"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
271 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
272 if(!is.null(pvalThresholdFDR)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
273 phtml=add_trace(phtml,x=c(xMinLimPlot,xMaxLimPlot), y=c(pvalThresholdFDR,pvalThresholdFDR), type="scatter", mode = "lines", line=list(color="cornflowerblue",dash="dash"), hoverinfo='none', showlegend = FALSE,inherit = FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
274 phtml=add_annotations(phtml,x=xMinLimPlot,y=pvalThresholdFDR+0.1,xref = "x",yref = "y",text = paste(c("Adjusted pval limit(",opt$fdrThreshold,")"),collapse=""),xanchor = 'left',showarrow = F,font=list(color="cornflowerblue"))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
275 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
276 plotVector[[length(plotVector)+1]]=p
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
277
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
278 #save plotly files
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
279 pp <- ggplotly(phtml)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
280 htmlwidgets::saveWidget(as_widget(pp), paste(c(file.path(getwd(), "plotLyDir"),"/Volcanos_",volcanoFileName,".html"),collapse=""),selfcontained = F)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
281
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
282
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
283 if(iVolcano==nbVolcanosToPlot || length(plotVector)==volcanoPerPage){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
284 #plot and close the actual plot
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
285 if(opt$format=="pdf"){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
286 pdf(paste(c("./plotDir/Volcanos_",volcanoFileName,".pdf"),collapse=""))}else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
287 png(paste(c("./plotDir/Volcanos_",volcanoFileName,".png"),collapse=""))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
288 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
289 multiplot(plotlist=plotVector,cols=1)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
290 dev.off()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
291 if(iVolcano<nbVolcanosToPlot){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
292 #prepare for a new ploting file if necessary
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
293 plotVector=list()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
294 iToPlot=iToPlot+1
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
295 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
296 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
297 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
298 remove(dataToPlot,dataSignifToPlot)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
299 addComment("[INFO]Volcanos drawn",T,opt$log,T,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
300
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
301
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
302 #now add anotation infos about genes
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
303
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
304 rowItemInfo=NULL
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
305 if(!is.null(opt$rowNameType) && !is.null(opt$organismID)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
306 ##get gene information from BioMart
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
307 #if(!require("biomaRt")){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
308 # source("https://bioconductor.org/biocLite.R")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
309 # biocLite("biomaRt")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
310 #}
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
311
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
312 ensembl_hs_mart <- useMart(biomart="ensembl", dataset=opt$organismID)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
313 ensembl_df <- getBM(attributes=c(opt$rowNameType,"description"),mart=ensembl_hs_mart)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
314 rowItemInfo=ensembl_df[which(ensembl_df[,1]!=""),2]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
315 rowItemInfo=unlist(lapply(rowItemInfo,function(x)substr(unlist(strsplit(x," \\[Source"))[1],1,30)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
316 names(rowItemInfo)=ensembl_df[which(ensembl_df[,1]!=""),1]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
317 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
318
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
319 #filter out genes with higher p-values for all comparisons
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
320 genesToKeep=names(which(apply(dataFrame$adj_p.value,1,function(x)length(which(x<=opt$fdrThreshold))>0)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
321 #filter out genes with lower FC for all comparisons
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
322 genesToKeep=intersect(genesToKeep,names(which(apply(dataFrame$coefficients,1,function(x)length(which(abs(x)>=logFCthreshold))>0))))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
323
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
324 if(length(genesToKeep)>0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
325 dataFrameNew=data.frame(row.names=genesToKeep)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
326
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
327 dataFrameNew$adj_p.value=matrix(dataFrame$adj_p.value[genesToKeep,,drop=FALSE],ncol=ncol(dataFrame$adj_p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
328 rownames(dataFrameNew$adj_p.value)=genesToKeep
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
329 colnames(dataFrameNew$adj_p.value)=colnames(dataFrame$p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
330
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
331 dataFrameNew$p.value=matrix(dataFrame$p.value[genesToKeep,,drop=FALSE],ncol=ncol(dataFrame$p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
332 rownames(dataFrameNew$p.value)=genesToKeep
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
333 colnames(dataFrameNew$p.value)=colnames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
334
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
335 dataFrameNew$coefficients=matrix(dataFrame$coefficients[genesToKeep,,drop=FALSE],ncol=ncol(dataFrame$coefficients))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
336 rownames(dataFrameNew$coefficients)=genesToKeep
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
337 colnames(dataFrameNew$coefficients)=colnames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
338
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
339 dataFrame=dataFrameNew
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
340 rm(dataFrameNew)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
341 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
342 addComment("[WARNING]No significative genes",T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
343 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
344
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
345 addComment("[INFO]Significant genes filtering done",T,opt$log,T,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
346
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
347
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
348 #plot VennDiagramm for genes below threshold between comparisons
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
349 #t=apply(dataFrame$adj_p.value[,1:4],2,function(x)names(which(x<=opt$threshold)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
350 #get.venn.partitions(t)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
351 #vennCounts(dataFrame$adj_p.value[,1:4]<=opt$threshold)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
352
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
353 #make a simple sort genes based only on the first comparison
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
354 #newOrder=order(dataFrame$adj_p.value[,1])
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
355 #dataFrame$adj_p.value=dataFrame$adj_p.value[newOrder,]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
356
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
357 #alternative sorting strategy based on the mean gene rank over all comparisons
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
358 if(length(genesToKeep)>1){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
359 currentRank=rep(0,nrow(dataFrame$adj_p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
360 for(iVolcano in 1:ncol(dataFrame$adj_p.value)){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
361 currentRank=currentRank+rank(dataFrame$adj_p.value[,iVolcano])
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
362 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
363 currentRank=currentRank/ncol(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
364 newOrder=order(currentRank)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
365 rownames(dataFrame)=rownames(dataFrame)[newOrder]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
366
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
367 dataFrame$adj_p.value=matrix(dataFrame$adj_p.value[newOrder,],ncol=ncol(dataFrame$adj_p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
368 rownames(dataFrame$adj_p.value)=rownames(dataFrame$p.value)[newOrder]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
369 colnames(dataFrame$adj_p.value)=colnames(dataFrame$p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
370
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
371 dataFrame$p.value=matrix(dataFrame$p.value[newOrder,],ncol=ncol(dataFrame$p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
372 rownames(dataFrame$p.value)=rownames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
373 colnames(dataFrame$p.value)=colnames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
374
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
375 dataFrame$coefficients=matrix(dataFrame$coefficients[newOrder,],ncol=ncol(dataFrame$coefficients))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
376 rownames(dataFrame$coefficients)=rownames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
377 colnames(dataFrame$coefficients)=colnames(dataFrame$adj_p.value)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
378 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
379
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
380 #formating output matrix depending on genes to keep
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
381 if(length(genesToKeep)==0){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
382 outputData=matrix(0,ncol=ncol(dataFrame$adj_p.value)*4+2,nrow=3)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
383 outputData[1,]=c("X","X",rep(volcanoNameList,each=4))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
384 outputData[2,]=c("X","X",rep(c("p-val","Adjusted.p-val","FC","log2(FC)"),ncol(dataFrame$adj_p.value)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
385 outputData[,1]=c("Volcano","Gene","noGene")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
386 outputData[,2]=c("Comparison","Info","noInfo")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
387 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
388 if(length(genesToKeep)==1){
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
389 outputData=matrix(0,ncol=ncol(dataFrame$adj_p.value)*4+2,nrow=3)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
390 outputData[1,]=c("X","X",rep(volcanoNameList,each=4))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
391 outputData[2,]=c("X","X",rep(c("p-val","Adjusted.p-val","FC","log2(FC)"),ncol(dataFrame$adj_p.value)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
392 outputData[,1]=c("Volcano","Gene",genesToKeep)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
393 outputData[,2]=c("Comparison","Info","na")
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
394 if(!is.null(rowItemInfo))outputData[3,2]=rowItemInfo[genesToKeep]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
395 outputData[3,seq(3,ncol(outputData),4)]=prettyNum(dataFrame$p.value,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
396 outputData[3,seq(4,ncol(outputData),4)]=prettyNum(dataFrame$adj_p.value,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
397 outputData[3,seq(5,ncol(outputData),4)]=prettyNum(2^dataFrame$coefficients,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
398 outputData[3,seq(6,ncol(outputData),4)]=prettyNum(dataFrame$coefficients,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
399 }else{
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
400 #format matrix to be correctly read by galaxy (move headers in first column and row)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
401 outputData=matrix(0,ncol=ncol(dataFrame$adj_p.value)*4+2,nrow=nrow(dataFrame$adj_p.value)+2)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
402 outputData[1,]=c("X","X",rep(volcanoNameList,each=4))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
403 outputData[2,]=c("X","X",rep(c("p-val","Adjusted.p-val","FC","log2(FC)"),ncol(dataFrame$adj_p.value)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
404 outputData[,1]=c("Volcano","Gene",rownames(dataFrame$adj_p.value))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
405 outputData[,2]=c("Comparison","Info",rep("na",nrow(dataFrame$adj_p.value)))
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
406 if(!is.null(rowItemInfo))outputData[3:nrow(outputData),2]=rowItemInfo[rownames(dataFrame$adj_p.value)]
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
407 outputData[3:nrow(outputData),seq(3,ncol(outputData),4)]=prettyNum(dataFrame$p.value,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
408 outputData[3:nrow(outputData),seq(4,ncol(outputData),4)]=prettyNum(dataFrame$adj_p.value,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
409 outputData[3:nrow(outputData),seq(5,ncol(outputData),4)]=prettyNum(2^dataFrame$coefficients,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
410 outputData[3:nrow(outputData),seq(6,ncol(outputData),4)]=prettyNum(dataFrame$coefficients,digits=4)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
411 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
412 }
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
413 addComment("[INFO]Formated output",T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
414
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
415 #write output results
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
416 write.table(outputData,file=opt$outputFile,quote=FALSE,sep="\t",col.names = F,row.names = F)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
417
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
418
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
419 end.time <- Sys.time()
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
420 addComment(c("[INFO]Total execution time for R script:",as.numeric(end.time - start.time,units="mins"),"mins"),T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
421
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
422 addComment("[INFO]End of R script",T,opt$log,display=FALSE)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
423
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
424 printSessionInfo(opt$log)
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
425
14045c80a222 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
426 #sessionInfo()