annotate src/ExprPlotsScript.R @ 0:708f43bda2b6 draft

"planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
author vandelj
date Fri, 26 Jun 2020 09:35:11 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
1 # A command-line interface to basic plots for use with Galaxy
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
2 # written by Jimmy Vandel
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
3 # one of these arguments is required:
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
4 #
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
5 #
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
6 initial.options <- commandArgs(trailingOnly = FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
7 file.arg.name <- "--file="
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
8 script.name <- sub(file.arg.name, "", initial.options[grep(file.arg.name, initial.options)])
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
9 script.basename <- dirname(script.name)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
10 source(file.path(script.basename, "utils.R"))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
11 source(file.path(script.basename, "getopt.R"))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
12
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
13 #addComment("Welcome R!")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
14
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
15 # setup R error handling to go to stderr
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
16 options( show.error.messages=F, error = function () { cat(geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
17
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
18 # we need that to not crash galaxy with an UTF8 error on German LC settings.
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
19 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
20 loc <- Sys.setlocale("LC_NUMERIC", "C")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
21
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
22 #get starting time
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
23 start.time <- Sys.time()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
24
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
25 #get options
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
26 options(stringAsfactors = FALSE, useFancyQuotes = FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
27 args <- commandArgs()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
28
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
29
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
30 # get options, using the spec as defined by the enclosed list.
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
31 # we read the options from the default: commandArgs(TRUE).
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
32 spec <- matrix(c(
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
33 "dataFile", "i", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
34 "factorInfo","t", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
35 "dataFileFormat","j",1,"character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
36 "conditionNames","c",1,"character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
37 "format", "f", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
38 "quiet", "q", 0, "logical",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
39 "log", "l", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
40 "histo" , "h", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
41 "maPlot" , "a", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
42 "boxplot" , "b", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
43 "microarray" , "m", 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
44 "acp" , "p" , 1, "character",
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
45 "screePlot" , "s" , 1, "character"),
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
46 byrow=TRUE, ncol=4)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
47 opt <- getopt(spec)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
48
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
49 # enforce the following required arguments
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
50 if (is.null(opt$log)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
51 addComment("[ERROR]'log file' is required")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
52 q( "no", 1, F )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
53 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
54 addComment("[INFO]Start of R script",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
55 if (is.null(opt$dataFile) || is.null(opt$dataFileFormat)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
56 addComment("[ERROR]'dataFile' and it format are required",T,opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
57 q( "no", 1, F )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
58 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
59 if (is.null(opt$format)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
60 addComment("[ERROR]'output format' is required",T,opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
61 q( "no", 1, F )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
62 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
63 if (is.null(opt$histo) & is.null(opt$maPlot) & is.null(opt$boxplot) & is.null(opt$microarray) & is.null(opt$acp)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
64 addComment("[ERROR]Select at least one plot to draw",T,opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
65 q( "no", 1, F )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
66 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
67
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
68 verbose <- if (is.null(opt$quiet)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
69 TRUE
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
70 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
71 FALSE}
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
72
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
73 addComment("[INFO]Parameters checked!",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
74
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
75 addComment(c("[INFO]Working directory: ",getwd()),TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
76 addComment(c("[INFO]Command line: ",args),TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
77
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
78 #directory for plots
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
79 dir.create(file.path(getwd(), "plotDir"))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
80 dir.create(file.path(getwd(), "plotLyDir"))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
81
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
82 #silent package loading
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
83 suppressPackageStartupMessages({
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
84 library("oligo")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
85 library("ff")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
86 library("ggplot2")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
87 library("plotly")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
88 })
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
89
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
90
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
91 #chargement des fichiers en entrée
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
92 #fichier de type CEL
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
93 dataAreFromCel=FALSE
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
94 if(toupper(opt$dataFileFormat)=="CEL"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
95 dataAreFromCel=TRUE
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
96 celData=read.celfiles(unlist(strsplit(opt$dataFile,",")))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
97 #load all expressions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
98 dataMatrix=exprs(celData)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
99 #select "pm" probes
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
100 probeInfo=getProbeInfo(celData,probeType = c("pm"),target="probeset")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
101 #reduce dataMatrix to log expression matrix for a randomly probe selection
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
102 dataMatrix=log2(dataMatrix[sample(unique(probeInfo[,1]),min(100000,length(unique(probeInfo[,1])))),])
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
103 addComment("[INFO]Raw data are log2 transformed",TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
104 remove(probeInfo)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
105 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
106 #fichier deja tabule
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
107 dataMatrix=read.csv(file=opt$dataFile,header=F,sep="\t",colClasses="character")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
108 #remove first row to convert it as colnames (to avoid X before colnames with header=T)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
109 colNamesData=dataMatrix[1,-1]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
110 dataMatrix=dataMatrix[-1,]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
111 #remove first colum to convert it as rownames
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
112 rowNamesData=dataMatrix[,1]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
113 dataMatrix=dataMatrix[,-1]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
114 if(is.data.frame(dataMatrix)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
115 dataMatrix=data.matrix(dataMatrix)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
116 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
117 dataMatrix=data.matrix(as.numeric(dataMatrix))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
118 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
119 dimnames(dataMatrix)=list(rowNamesData,colNamesData)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
120 if(any(duplicated(rowNamesData)))addComment("[WARNING] several rows share the same probe/gene name, you should merge or rename them to avoid further analysis mistakes",TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
121 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
122
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
123 addComment("[INFO]Input data loaded",TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
124 addComment(c("[INFO]Dim of data matrix:",dim(dataMatrix)),T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
125
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
126 #get number of conditions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
127 nbConditions=ncol(dataMatrix)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
128
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
129 #get condition names if they are specified
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
130 if(!is.null(opt$conditionNames) && length(opt$conditionNames)==nbConditions){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
131 nameConditions=opt$conditionNames
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
132 colnames(dataMatrix)=nameConditions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
133 #rownames(phenoData(celData)@data)=nameConditions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
134 #rownames(protocolData(celData)@data)=nameConditions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
135 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
136 nameConditions=colnames(dataMatrix)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
137 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
138
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
139 #create a correspondance table between plot file names and name displayed in figure legend and html items
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
140 correspondanceNameTable=matrix("",ncol=2,nrow=nbConditions)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
141 correspondanceNameTable[,1]=paste("Condition",1:nbConditions,sep="")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
142 correspondanceNameTable[,2]=nameConditions
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
143 rownames(correspondanceNameTable)=correspondanceNameTable[,2]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
144
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
145 addComment("[INFO]Retreive condition names",TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
146
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
147 if(!is.null(opt$factorInfo)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
148 #chargement du fichier des facteurs
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
149 factorInfoMatrix=read.csv(file=file.path(getwd(), opt$factorInfo),header=F,sep="\t",colClasses="character")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
150 #remove first row to convert it as colnames
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
151 colnames(factorInfoMatrix)=factorInfoMatrix[1,]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
152 factorInfoMatrix=factorInfoMatrix[-1,]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
153 #use first colum to convert it as rownames but not removing it to avoid conversion as vector in unique factor case
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
154 rownames(factorInfoMatrix)=factorInfoMatrix[,1]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
155
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
156
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
157 if(length(setdiff(colnames(dataMatrix),rownames(factorInfoMatrix)))!=0){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
158 addComment("[ERROR]Missing samples in factor file",T,opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
159 q( "no", 1, F )
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
160 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
161
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
162 #order sample as in expression matrix and remove spurious sample
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
163 factorInfoMatrix=factorInfoMatrix[colnames(dataMatrix),]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
164
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
165 addComment("[INFO]Factors OK",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
166 addComment(c("[INFO]Dim of factorInfo matrix:",dim(factorInfoMatrix)),T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
167
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
168 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
169
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
170 addComment("[INFO]Ready to plot",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
171
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
172
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
173 ##----------------------
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
174
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
175 ###plot histograms###
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
176 histogramPerFigure=50
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
177 if (!is.null(opt$histo)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
178 for(iToPlot in 1:(((nbConditions-1)%/%histogramPerFigure)+1)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
179 firstPlot=1+histogramPerFigure*(iToPlot-1)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
180 lastPlot=min(nbConditions,histogramPerFigure*iToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
181 dataToPlot=data.frame(x=c(dataMatrix[,firstPlot:lastPlot]),Experiment=rep(colnames(dataMatrix)[firstPlot:lastPlot],each=nrow(dataMatrix)))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
182 p <- ggplot(data=dataToPlot, aes(x = x, color=Experiment)) + stat_density(geom="line", size=1, position="identity") +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
183 ggtitle("Intensity densities") + theme_bw() + ylab(label="Density") +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
184 theme(panel.border=element_blank(),plot.title = element_text(hjust = 0.5))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
185 if(dataAreFromCel){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
186 #original ploting function
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
187 #hist(celData[,firstPlot:lastPlot],lty=rep(1,nbConditions)[firstPlot:lastPlot],lwd=2,which='pm',target="probeset",transfo=log2,col=rainbow(nbConditions)[firstPlot:lastPlot])
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
188 p <- p + xlab(label="Log2 intensities")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
189 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
190 p <- p + xlab(label="Intensities")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
191 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
192 if(opt$format=="pdf"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
193 pdf(paste(c("./plotDir/",opt$histo,iToPlot,".pdf"),collapse=""))}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
194 png(paste(c("./plotDir/",opt$histo,iToPlot,".png"),collapse=""))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
195 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
196 print(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
197 dev.off()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
198 #save plotly files
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
199 pp <- ggplotly(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
200 htmlwidgets::saveWidget(as_widget(pp), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$histo,iToPlot,".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
201 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
202 remove(p,dataToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
203 addComment("[INFO]Histograms drawn",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
204 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
205
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
206 ##----------------------
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
207
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
208 ###plot MAplots###
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
209 MAplotPerPage=4
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
210 if (!is.null(opt$maPlot)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
211 iToPlot=1
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
212 plotVector=list()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
213 toTake=sample(nrow(dataMatrix),min(200000,nrow(dataMatrix)))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
214 refMedianColumn=rowMedians(as.matrix(dataMatrix[toTake,]))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
215 if(length(toTake)>100000)addComment(c("[INFO]high number of input data rows ",length(toTake),"; the generation of MA plot can take a while, please be patient"),TRUE,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
216 for (iCondition in 1:nbConditions){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
217 #MAplot(celData,which=i,what=pm,transfo=log2)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
218 #smoothScatter(x=xToPlot,y=yToPlot,main=nameConditions[iCondition])
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
219 dataA=dataMatrix[toTake,iCondition]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
220 dataB=refMedianColumn####ATTENTION PAR DEFAUT
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
221 xToPlot=0.5*(dataA+dataB)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
222 yToPlot=dataA-dataB
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
223 tempX=seq(min(xToPlot),max(xToPlot),0.1)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
224 tempY=unlist(lapply(tempX,function(x){median(yToPlot[intersect(which(xToPlot>=(x-0.1/2)),which(xToPlot<(x+0.1/2)))])}))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
225
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
226 dataToPlot=data.frame(x=xToPlot,y=yToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
227 dataMedianToPlot=data.frame(x=tempX,y=tempY)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
228 p <- ggplot(data=dataToPlot, aes(x,y)) + stat_density2d(aes(fill = ..density..^0.25), geom = "tile", contour = FALSE, n = 100) +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
229 scale_fill_continuous(low = "white", high = "dodgerblue4") + geom_smooth(data=dataMedianToPlot,colour="red", size=0.5, se=FALSE) +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
230 ggtitle(correspondanceNameTable[iCondition,2]) + theme_bw() + xlab(label="") + ylab(label="") +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
231 theme(panel.border=element_blank(),plot.title = element_text(hjust = 0.5),legend.position = "none")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
232 plotVector[[length(plotVector)+1]]=p
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
233
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
234 #save plotly files
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
235 pp <- ggplotly(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
236 htmlwidgets::saveWidget(as_widget(pp), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$maPlot,"_",correspondanceNameTable[iCondition,1],".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
237
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
238 if(iCondition==nbConditions || length(plotVector)==MAplotPerPage){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
239 #define a new plotting file
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
240 if(opt$format=="pdf"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
241 pdf(paste(c("./plotDir/",opt$maPlot,iToPlot,".pdf"),collapse=""))}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
242 png(paste(c("./plotDir/",opt$maPlot,iToPlot,".png"),collapse=""))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
243 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
244 multiplot(plotlist=plotVector,cols=2)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
245 dev.off()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
246 if(iCondition<nbConditions){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
247 #prepare for a new plotting file if necessary
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
248 plotVector=list()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
249 iToPlot=iToPlot+1
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
250 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
251 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
252 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
253 remove(p,dataToPlot,dataA,dataB,toTake,xToPlot,yToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
254 addComment("[INFO]MAplots drawn",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
255 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
256
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
257 ##----------------------
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
258
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
259 ###plot boxplots###
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
260 boxplotPerFigure=50
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
261 if (!is.null(opt$boxplot)) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
262 for(iToPlot in 1:(((nbConditions-1)%/%boxplotPerFigure)+1)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
263 firstPlot=1+boxplotPerFigure*(iToPlot-1)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
264 lastPlot=min(nbConditions,boxplotPerFigure*iToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
265 dataToPlot=data.frame(intensities=c(dataMatrix[,firstPlot:lastPlot]),Experiment=rep(colnames(dataMatrix)[firstPlot:lastPlot],each=nrow(dataMatrix)))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
266 #to make HTML file lighter, sampling will be done amongst outliers
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
267 #get outliers for each boxplot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
268 boxplotsOutliers=apply(dataMatrix[,firstPlot:lastPlot],2,function(x)boxplot.stats(x)$out)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
269 #sample amongst them to keep at maximum of 1000 points and include both min and max outliers values
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
270 boxplotsOutliers=lapply(boxplotsOutliers,function(x)if(length(x)>0)c(sample(c(x),min(length(x),1000)),max(c(x)),min(c(x))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
271 dataOutliers=data.frame(yVal=unlist(boxplotsOutliers),xVal=unlist(lapply(seq_along(boxplotsOutliers),function(x)rep(names(boxplotsOutliers)[x],length(boxplotsOutliers[[x]])))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
272 #plot boxplots without outliers
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
273 p <- ggplot(data=dataToPlot, aes(y = intensities, x=Experiment ,color=Experiment)) + geom_boxplot(outlier.colour=NA,outlier.shape =NA) +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
274 ggtitle("Intensities") + theme_bw() + xlab(label="") +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
275 theme(panel.border=element_blank(),plot.title = element_text(hjust = 0.5),axis.text.x = element_text(angle = 45, hjust = 1),plot.margin=unit(c(10,10,max(unlist(lapply(dataToPlot$Experiment,function(x)nchar(as.character(x))))),15+max(unlist(lapply(dataToPlot$Experiment,function(x)nchar(as.character(x)))))),"mm"))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
276 #add to plot sampled outliers
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
277 p <- p + geom_point(data=dataOutliers,aes(x=xVal,y=yVal,color=xVal),inherit.aes = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
278 if(dataAreFromCel){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
279 #original plotting function
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
280 #boxplot(celData[,firstPlot:lastPlot],which='pm',col=rainbow(nbConditions)[firstPlot:lastPlot],target="probeset",transfo=log2,names=nameConditions[firstPlot:lastPlot],main="Intensities")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
281 p <- p + ylab(label="Log2 intensities")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
282 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
283 p <- p + ylab(label="Intensities")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
284 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
285 if(opt$format=="pdf"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
286 pdf(paste(c("./plotDir/",opt$boxplot,iToPlot,".pdf"),collapse=""))}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
287 png(paste(c("./plotDir/",opt$boxplot,iToPlot,".png"),collapse=""))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
288 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
289 print(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
290 dev.off()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
291 #save plotly files
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
292 pp <- ggplotly(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
293
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
294 #modify plotly object to get HTML file not too heavy for loading
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
295 for(iData in 1:length(pp$x$data)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
296 ##get kept outliers y values
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
297 #yPointsToKeep=dataOutliers$yVal[which(dataOutliers$xVal==pp$x$data[[iData]]$name)]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
298 if(pp$x$data[[iData]]$type=="scatter"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
299 ##scatter plot represent outliers points added to boxplot through geom_point
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
300 ##nothing to do as outliers have been sampled allready, just have to modify hover text
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
301 #if(length(yPointsToKeep)>0){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
302 #pointsToKeep=which(pp$x$data[[iData]]$y %in% yPointsToKeep)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
303 #pp$x$data[[iData]]$x=pp$x$data[[iData]]$x[pointsToKeep]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
304 #pp$x$data[[iData]]$y=pp$x$data[[iData]]$y[pointsToKeep]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
305 #pp$x$data[[iData]]$text=pp$x$data[[iData]]$text[pointsToKeep]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
306 #}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
307 #pp$x$data[[iData]]$x=NULL
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
308 #pp$x$data[[iData]]$y=NULL
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
309 #pp$x$data[[iData]]$marker$opacity=0
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
310 #pp$x$data[[iData]]$hoverinfo=NULL
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
311 #pp$x$data[[iData]]$text=NULL
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
312 #}
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
313 #modify text to display
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
314 if(dataAreFromCel){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
315 pp$x$data[[iData]]$text=unlist(lapply(seq_along(pp$x$data[[iData]]$y),function(x)return(paste(c("log2(intensity) ",prettyNum(pp$x$data[[iData]]$y[x],digits=4)),collapse = ""))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
316 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
317 pp$x$data[[iData]]$text=unlist(lapply(seq_along(pp$x$data[[iData]]$y),function(x)return(paste(c("intensity ",prettyNum(pp$x$data[[iData]]$y[x],digits=4)),collapse = ""))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
318 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
319 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
320 ##disable marker plotting to keep only box and whiskers plot (outliers are displayed through scatter plot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
321 pp$x$data[[iData]]$marker$opacity=0
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
322
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
323 #sample 50000 points amongst all data to get a lighter html file, sampling size should not be too low to avoid modifying limit of boxplots
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
324 pp$x$data[[iData]]$y=c(sample(dataMatrix[,pp$x$data[[iData]]$name],min(length(dataMatrix[,pp$x$data[[iData]]$name]),50000)),min(dataMatrix[,pp$x$data[[iData]]$name]),max(dataMatrix[,pp$x$data[[iData]]$name]))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
325 pp$x$data[[iData]]$x=rep(pp$x$data[[iData]]$x[1],length(pp$x$data[[iData]]$y))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
326
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
327 ##first remove outliers info
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
328 #downUpValues=boxplot.stats(dataMatrix[,pp$x$data[[iData]]$name])$stats
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
329 #if(verbose)addComment(c("filter values for boxplot",pp$x$data[[iData]]$name,"between",min(downUpValues),"and",max(downUpValues)),T,opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
330 #pointsToRemove=which(pp$x$data[[iData]]$y<min(downUpValues))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
331 #if(length(pointsToRemove)>0)pp$x$data[[iData]]$y=pp$x$data[[iData]]$y[-pointsToRemove]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
332 #pointsToRemove=which(pp$x$data[[iData]]$y>max(downUpValues))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
333 #if(length(pointsToRemove)>0)pp$x$data[[iData]]$y=pp$x$data[[iData]]$y[-pointsToRemove]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
334 #then add sampled outliers info
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
335 #pp$x$data[[iData]]$y=c(yPointsToKeep,pp$x$data[[iData]]$y)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
336 #pp$x$data[[iData]]$x=rep(pp$x$data[[iData]]$x[1],length(pp$x$data[[iData]]$y))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
337 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
338 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
339
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
340 htmlwidgets::saveWidget(as_widget(pp), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$boxplot,iToPlot,".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
341 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
342 remove(p,dataToPlot)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
343 addComment("[INFO]Boxplots drawn",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
344
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
345 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
346
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
347 ##----------------------
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
348
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
349 ###plot microarrays (only for .CEL files)###
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
350 if (!is.null(opt$microarray) && dataAreFromCel) {
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
351 for (iCondition in 1:nbConditions){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
352 if(opt$format=="pdf"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
353 pdf(paste(c("./plotDir/",opt$microarray,"_",correspondanceNameTable[iCondition,1],".pdf"),collapse=""),onefile = F,width = 5,height = 5)}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
354 png(paste(c("./plotDir/",opt$microarray,"_",correspondanceNameTable[iCondition,1],".png"),collapse=""))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
355 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
356 image(celData[,iCondition],main=correspondanceNameTable[iCondition,2])
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
357 dev.off()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
358 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
359 addComment("[INFO]Microarray drawn",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
360 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
361
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
362 ##----------------------
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
363
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
364 ###plot PCA plot###
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
365 if (!is.null(opt$acp)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
366 ##to avoid error when nrow is too large, results quite stable with 200k random selected rows
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
367 randomSelection=sample(nrow(dataMatrix),min(200000,nrow(dataMatrix)))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
368 #remove constant variables
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
369
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
370 dataFiltered=dataMatrix[randomSelection,]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
371 toRemove=which(unlist(apply(dataFiltered,1,var))==0)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
372 if(length(toRemove)>0){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
373 dataFiltered=dataFiltered[-toRemove,]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
374 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
375 ##geom_text(aes(label=Experiments,hjust=1, vjust=1.3), y = PC2+0.01)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
376 PACres = prcomp(t(dataFiltered),scale.=TRUE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
377
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
378 if(!is.null(opt$screePlot)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
379 #scree plot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
380 #p <- fviz_eig(PACres)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
381 dataToPlot=data.frame(compo=seq(1,length(PACres$sdev)),var=(PACres$sdev^2/sum(PACres$sdev^2))*100)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
382 p<-ggplot(data=dataToPlot, aes(x=compo, y=var)) + geom_bar(stat="identity", fill="steelblue") + geom_line() + geom_point() +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
383 ggtitle("Scree plot") + theme_bw() + theme(panel.border=element_blank(),plot.title = element_text(hjust = 0.5)) +
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
384 xlab(label="Dimensions") + ylab(label="% explained variances") + scale_x_discrete(limits=dataToPlot$compo)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
385 pp <- ggplotly(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
386
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
387 if(opt$format=="pdf"){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
388 pdf(paste(c("./plotDir/",opt$screePlot,".pdf"),collapse=""))}else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
389 png(paste(c("./plotDir/",opt$screePlot,".png"),collapse=""))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
390 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
391 plot(p)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
392 dev.off()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
393 htmlwidgets::saveWidget(as_widget(pp), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$screePlot,".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
394 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
395
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
396 #now plot pca plots
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
397
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
398 if(!is.null(opt$factorInfo)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
399 fileIdent=""
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
400 symbolset = c("circle","cross","square","diamond","circle-open","square-open","diamond-open","x")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
401
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
402 #save equivalence between real factor names and generic ones in correspondanceNameTable
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
403 correspondanceNameTable=rbind(correspondanceNameTable,matrix(c(paste("Factor",1:(ncol(factorInfoMatrix)-1),sep=""),colnames(factorInfoMatrix)[-1]),ncol=2,nrow=ncol(factorInfoMatrix)-1))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
404 rownames(correspondanceNameTable)=correspondanceNameTable[,2]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
405
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
406 #first order factors from decreasing groups number
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
407 orderedFactors=colnames(factorInfoMatrix)[-1][order(unlist(lapply(colnames(factorInfoMatrix)[-1],function(x)length(table(factorInfoMatrix[,x])))),decreasing = T)]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
408 allFactorsBigger=length(table(factorInfoMatrix[,orderedFactors[length(orderedFactors)]]))>length(symbolset)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
409 if(allFactorsBigger)addComment("[WARNING]All factors are composed of too many groups to display two factors at same time, each PCA plot will display only one factor groups",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
410 for(iFactor in 1:length(orderedFactors)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
411 #if it is the last factor of the list or if all factor
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
412 if(iFactor==length(orderedFactors) || allFactorsBigger){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
413 if(length(orderedFactors)==1 || allFactorsBigger){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
414 dataToPlot=data.frame(PC1=PACres$x[,1],PC2=PACres$x[,2],PC3=PACres$x[,3],Experiments=rownames(PACres$x), Attribute1=factorInfoMatrix[rownames(PACres$x),orderedFactors[iFactor]], hoverLabel=unlist(lapply(rownames(PACres$x),function(x)paste(factorInfoMatrix[x,-1],collapse=","))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
415 p <- plot_ly(dataToPlot,x = ~PC1, y = ~PC2, z = ~PC3, type = 'scatter3d', mode="markers", color=~Attribute1,colors=rainbow(length(levels(dataToPlot$Attribute1))+2),hoverinfo = 'text', text = ~paste(Experiments,"\n",hoverLabel),marker=list(size=5))%>%
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
416 layout(title = "Principal Component Analysis", scene = list(xaxis = list(title = "Component 1"),yaxis = list(title = "Component 2"),zaxis = list(title = "Component 3")),
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
417 legend=list(font = list(family = "sans-serif",size = 15,color = "#000")))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
418 fileIdent=correspondanceNameTable[orderedFactors[iFactor],1]
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
419 #add text label to plot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
420 ##p <- add_text(p,x = dataToPlot$PC1, y = dataToPlot$PC2 + (max(PACres$x[,2])-min(PACres$x[,2]))*0.02, z = dataToPlot$PC3, mode = 'text', inherit = F, text=rownames(PACres$x), hoverinfo='skip', showlegend = FALSE, color=I('black'))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
421 #save the plotly plot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
422 htmlwidgets::saveWidget(as_widget(p), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$acp,"_",fileIdent,".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
423 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
424 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
425 for(iFactorBis in (iFactor+1):length(orderedFactors)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
426 if(length(table(factorInfoMatrix[,orderedFactors[iFactorBis]]))<=length(symbolset)){
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
427 dataToPlot=data.frame(PC1=PACres$x[,1],PC2=PACres$x[,2],PC3=PACres$x[,3],Experiments=rownames(PACres$x), Attribute1=factorInfoMatrix[rownames(PACres$x),orderedFactors[iFactor]], Attribute2=factorInfoMatrix[rownames(PACres$x),orderedFactors[iFactorBis]], hoverLabel=unlist(lapply(rownames(PACres$x),function(x)paste(factorInfoMatrix[x,-1],collapse=","))))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
428 p <- plot_ly(dataToPlot,x = ~PC1, y = ~PC2, z = ~PC3, type = 'scatter3d', mode="markers", color=~Attribute1,colors=rainbow(length(levels(dataToPlot$Attribute1))+2),symbol=~Attribute2,symbols = symbolset,hoverinfo = 'text', text = ~paste(Experiments,"\n",hoverLabel),marker=list(size=5))%>%
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
429 layout(title = "Principal Component Analysis", scene = list(xaxis = list(title = "Component 1"),yaxis = list(title = "Component 2"),zaxis = list(title = "Component 3")),
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
430 legend=list(font = list(family = "sans-serif",size = 15,color = "#000")))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
431 fileIdent=paste(correspondanceNameTable[orderedFactors[c(iFactor,iFactorBis)],1],collapse="_AND_")
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
432 #add text label to plot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
433 ##p <- add_text(p,x = dataToPlot$PC1, y = dataToPlot$PC2 + (max(PACres$x[,2])-min(PACres$x[,2]))*0.02, z = dataToPlot$PC3, mode = 'text', inherit = F, text=rownames(PACres$x), hoverinfo='skip', showlegend = FALSE, color=I('black'))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
434 #save the plotly plot
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
435 htmlwidgets::saveWidget(as_widget(p), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$acp,"_",fileIdent,".html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
436 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
437 addComment(c("[WARNING]PCA with",orderedFactors[iFactor],"and",orderedFactors[iFactorBis],"groups cannot be displayed, too many groups (max",length(symbolset),")"),T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
438 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
439 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
440 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
441 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
442 }else{
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
443 dataToPlot=data.frame(PC1=PACres$x[,1],PC2=PACres$x[,2],PC3=PACres$x[,3],Experiments=rownames(PACres$x))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
444 p <- plot_ly(dataToPlot,x = ~PC1, y = ~PC2, z = ~PC3, type = 'scatter3d', mode="markers",marker=list(size=5,color="salmon"),hoverinfo = 'text',text = ~paste(Experiments))%>%
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
445 layout(title = "Principal Component Analysis", scene = list(xaxis = list(title = "Component 1"),yaxis = list(title = "Component 2"),zaxis = list(title = "Component 3")),
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
446 legend=list(font = list(family = "sans-serif",size = 15,color = "#000")))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
447 ##p <- add_text(p,x = dataToPlot$PC1, y = dataToPlot$PC2 + (max(PACres$x[,2])-min(PACres$x[,2]))*0.02, z = dataToPlot$PC3, mode = 'text', inherit = F, text=rownames(PACres$x), hoverinfo='skip', showlegend = FALSE, color=I('black'))
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
448
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
449 #save plotly files
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
450 htmlwidgets::saveWidget(as_widget(p), paste(c(file.path(getwd(), "plotLyDir"),"/",opt$acp,"_plot.html"),collapse=""),selfcontained = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
451 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
452 remove(p,dataToPlot,dataFiltered)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
453 addComment("[INFO]ACP plot drawn",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
454 }
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
455
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
456 #write correspondances between plot file names and displayed names in figure legends, usefull to define html items in xml file
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
457 write.table(correspondanceNameTable,file=file.path(getwd(), "correspondanceFileNames.csv"),quote=FALSE,sep="\t",col.names = F,row.names = F)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
458
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
459 end.time <- Sys.time()
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
460 addComment(c("[INFO]Total execution time for R script:",as.numeric(end.time - start.time,units="mins"),"mins"),T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
461
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
462 addComment("[INFO]End of R script",T,opt$log,display=FALSE)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
463
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
464 printSessionInfo(opt$log)
708f43bda2b6 "planemo upload for repository https://github.com/juliechevalier/GIANT/tree/master commit cb276a594444c8f32e9819fefde3a21f121d35df"
vandelj
parents:
diff changeset
465 #sessionInfo()