rogge_12231_data_compilation.R 24 KB
Newer Older
Gael  MILLOT's avatar
interm  
Gael MILLOT committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

################################ Initialization

erase.objects <- TRUE # write TRUE to erase all the existing objects in R before starting the algorithm and FALSE otherwise. Beginners should use TRUE
if(erase.objects == TRUE){
    rm(list=ls())
    erase.objects = TRUE
}
erase.graphs <- TRUE # write TRUE to erase all the graphic windows in R before starting the algorithm and FALSE otherwise

################################ End Initialization

sink(stdout(), type = "message")
script <- commandArgs(trailingOnly = FALSE)[1]  # recover script name, e.g., r_341_conf $check_lod_gael_conf 
args <- commandArgs(trailingOnly = TRUE)  # recover arguments written after the call of the Rscript, ie after r_341_conf $check_lod_gael_conf 
tempo.arg.names <- c("path.lib", "path.in", "path.out", "path.function1", "project.name", "activate.pdf", "label.size", "optional.text", "slurm.loop.nb", "analysis.kind") # objects names exactly in the same order as in the bash code and recovered in args
if(length(args) != length(tempo.arg.names)){
    tempo.cat <- paste0("\n\n================\n\nERROR: THE NUMBER OF ELEMENTS IN args (", length(args),") IS DIFFERENT FROM THE NUMBER OF ELEMENTS IN tempo.arg.names (", length(tempo.arg.names),")\nargs:", paste0(args, collapse = ","), "\ntempo.arg.names:", paste0(tempo.arg.names, collapse = ","), "\n\n================\n\n")
    stop(tempo.cat)
}
for(i in 1:length(tempo.arg.names)){
    assign(tempo.arg.names[i], args[i])
    if(is.character(get(tempo.arg.names[i])) == TRUE & grepl(x = get(tempo.arg.names[i]), pattern = "^[1234567890]+$")){  # convert into numeric
        assign(tempo.arg.names[i], as.integer(get(tempo.arg.names[i])))
    }else if(is.character(get(tempo.arg.names[i])) == TRUE & grepl(x = get(tempo.arg.names[i]), pattern = "^[1234567890.+e-]+$")){
        assign(tempo.arg.names[i], as.numeric(get(tempo.arg.names[i])))
    }else if(is.character(get(tempo.arg.names[i])) == TRUE & grepl(x = get(tempo.arg.names[i]), pattern = "^(TRUE|FALSE)$")){  # convert into logical
        assign(tempo.arg.names[i], as.logical(get(tempo.arg.names[i])))
    }
}

################################ Recording of the initial parameters
param.list <- c(
    "script", 
    "args",
    "tempo.arg.names",
    tempo.arg.names
)
if(any(duplicated(param.list))){
    stop(paste0("\n\n================\n\nERROR: THE param.list OBJECT CONTAINS DUPLICATED ELEMENTS\n\n================\n\n")) # message for developers
}
char.length <- nchar(param.list)
space.add <- max(char.length) - char.length + 5
param.ini.settings <- NULL
for(i in 1:length(param.list)){
    param.ini.settings <- c(param.ini.settings, paste0("\n", param.list[i], paste0(rep(" ", space.add[i]), collapse = ""), paste0(get(param.list[i]), collapse = ",")))
}
################################ End Recording of the initial parameters

################################ DEBUG

debug1 <- '
rm(list = ls())
erase.objects <- TRUE
erase.graphs <- TRUE
script <- "code ini v1.0.0"
project.name <-"rogge12231"
path.lib <- "/pasteur/homes/gmillot/softwares/R/x86_64-pc-linux-gnu-library/3.5/" # absolute path of the library folder. Write "none" if not required
path.in <- "/pasteur/homes/gmillot/rogge12231/" # absolute path of the data folder
path.out <- "/pasteur/homes/gmillot/rogge12231/" # absolute path of the output folder
path.function1 <- "/pasteur/homes/gmillot/Git_versions_to_use/cute_little_R_functions-v4.4.0/" # Define the absolute pathway of the folder containing functions created by Gael Millot
file.name1 <- "supplementary_data_file_test.csv" # name of the data file to import in path.in
name.source.file1 <- "cute_little_R_functions.R"
ml.bootstrap.nb <- 3
activate.pdf = TRUE
label.size <- 6
optional.text <- ""
slurm.loop.nb <- 1
analysis.kind <- "longit"
cross.valid.ratio <- 0.8
random.seed <- TRUE
'
# eval(parse(text = debug1)) ; cat(paste0("\n\n================\n\n================\n\n================\n\nERROR: ACTIVE DEBUG VALUES\n\n================\n\n================\n\n================\n\n")) ; stop()



debug2 <- '
rm(list = ls())
erase.objects <- TRUE
erase.graphs <- TRUE
script <- "code ini v1.0.0"
project.name <-"rogge12231"
path.lib <- "C:/Users/Gael/Documents/R/win-library/3.5/" # absolute path of the library folder. Write "none" if not required
path.in <- "C:/Users/Gael/Documents/Hub projects/20190126 Las Rogge 12231/Code VG and VR/" # absolute path of the data folder
path.out <- "C:/Users/Gael/Desktop/" # absolute path of the output folder
path.function1 <- "C:/Users/Gael/Documents/Git_versions_to_use/cute_little_R_functions-v4.5.0/" # Define the absolute pathway of the folder containing functions created by Gael Millot
file.name1 <- "supplementary_data_file_test.csv" # name of the data file to import in path.in
name.source.file1 <- "cute_little_R_functions.R"
ml.bootstrap.nb <- 3
activate.pdf = TRUE
label.size <- 6
optional.text <- ""
slurm.loop.nb <- 1
analysis.kind <- "longit"
cross.valid.ratio <- 0.8
random.seed <- TRUE
'
# eval(parse(text = debug2)) ; cat(paste0("\n\n================\n\nERROR: ACTIVE DEBUG VALUES\n\n================\n\n")) ; stop()

# data.frame(PARAM = tempo.arg.names, ARG = args) # for debug mode

################################ End DEBUG

################################ Packages verification and import
# packages are imported even if functions are used using package.name::function()
req.package.list <- c(
    "pheatmap",
    "corrplot",
    "ggplot2",
    "gridExtra",
    "lubridate"
)
if(path.lib == "none"){
    path.lib <- .libPaths() # .libPaths(new = path.lib) # or .libPaths(new = c(.libPaths(), path.lib))
}else{
  .libPaths(new = path.lib)
}
for(i0 in 1:length(req.package.list)){
    if( ! req.package.list[i0] %in% rownames(installed.packages(lib.loc =  path.lib))){
        stop(paste0("\n\n================\n\nERROR: PACKAGE ", req.package.list[i0], " MUST BE INSTALLED IN THE MENTIONNED DIRECTORY:\n", paste(path.lib, collapse = "\n"), "\n CHECK ALSO IN :\n", paste(.libPaths(), collapse = "\n"), "\n\n================\n\n"))
    }else{
        suppressPackageStartupMessages(library(req.package.list[i0], lib.loc = path.lib, quietly = TRUE, character.only = TRUE))
        # suppressPackageStartupMessages(library(req.package.list[i0], quietly = TRUE, character.only = TRUE))
    }
}
################################ End Packages verification and import

################################ Functions
if( ! (all(dir.exists(path.function1)) & length(path.function1) == 1)){
    cat(paste0("\n\n============\n\nERROR: DIRECTORY PATH INDICATED IN THE path.out PARAMETER DOES NOT EXISTS: ", paste(path.function1, collapse = " "), "\n\n============\n\n"))
}else if( ! (all(name.source.file1 %in% list.files(path.function1)) & length(name.source.file1) == 1)){
    cat(paste0("\n\n============\n\nERROR: name.source.file1 PARAMETER (", paste(name.source.file1, collapse = " "), ") DOES NOT EXIST IN THE DIRECTORY PATH INDICATED IN THE path.function1 PARAMETER: ", path.function1, "\n\n============\n\n"))
}else{
    source(paste0(path.function1, name.source.file1)) # source the fun_ functions used below
}
################################ End Functions

################################ Main code

################ Pre-ignition checking

arg.check <- NULL # for function debbuging
checked.arg.names <- NULL # for function debbuging
ee <- expression(arg.check <- c(arg.check, tempo$problem) , checked.arg.names <- c(checked.arg.names, tempo$param.name))

# initializations
tempo <- fun_param_check(data = erase.objects, class = "logical", length = 1) ; eval(ee)
tempo <- fun_param_check(data = erase.graphs, class = "logical", length = 1) ; eval(ee)
tempo <- fun_param_check(data = script, class = "character", length = 1) ; eval(ee)
tempo <- fun_param_check(data = args, class = "character", length = length(tempo.arg.names)) ; eval(ee)
tempo <- fun_param_check(data = tempo.arg.names, class = "character", length = length(tempo.arg.names)) ; eval(ee)

# imported objects
tempo <- fun_param_check(data = path.lib, class = "character", length = 1) ; eval(ee)
if(tempo$problem == FALSE & path.lib != "none"){
    if( ! dir.exists(path.lib)){
        cat(paste0("\n\n============\n\nERROR: DIRECTORY PATH INDICATED IN THE path.in PARAMETER DOES NOT EXISTS: ", path.in, "\n\n============\n\n"))
    }
}
tempo <- fun_param_check(data = path.in, class = "character", length = 1) ; eval(ee)
if(tempo$problem == FALSE & ! dir.exists(path.in)){
    cat(paste0("\n\n============\n\nERROR: DIRECTORY PATH INDICATED IN THE path.in PARAMETER DOES NOT EXISTS: ", path.in, "\n\n============\n\n"))
}
tempo <- fun_param_check(data = file.name1, mode = "character", length = 1) ; eval(ee)
if(tempo$problem == FALSE & ! (file.name1 %in% list.files(path.in))){
    cat(paste0("\n\n============\n\nERROR: file.name1 PARAMETER (", file.name1, ") DOES NOT EXIST IN THE DIRECTORY PATH INDICATED IN THE path.in PARAMETER: ", path.in, "\n\n============\n\n"))
}
tempo <- fun_param_check(data = path.out, class = "character", length = 1) ; eval(ee)
if(tempo$problem == FALSE & ! dir.exists(path.out)){
    cat(paste0("\n\n============\n\nERROR: DIRECTORY PATH INDICATED IN THE path.out PARAMETER DOES NOT EXISTS: ", path.out, "\n\n============\n\n"))
}
tempo <- fun_param_check(data = ml.bootstrap.nb, typeof = "integer", length = 1, double.as.integer.allowed = TRUE, neg.values = FALSE) ; eval(ee)
tempo <- fun_param_check(data = project.name, class = "character", length = 1) ; eval(ee)
tempo <- fun_param_check(data = activate.pdf, class = "logical", length = 1) ; eval(ee)
tempo <- fun_param_check(data = optional.text, class = "character", length = 1) ; eval(ee)
tempo <- fun_param_check(data = slurm.loop.nb, typeof = "integer", length = 1, double.as.integer.allowed = TRUE, neg.values = FALSE) ; eval(ee)
tempo <- fun_param_check(data = analysis.kind, options = c("longit", "valid_boot", "full_cross_validation"), length = 1) ; eval(ee)
tempo <- fun_param_check(data = cross.valid.ratio, typeof = "double", length = 1, prop = TRUE) ; eval(ee)
tempo <- fun_param_check(data = random.seed, class = "logical", length = 1) ; eval(ee)
if(any(arg.check) == TRUE){
    stop()
}

################ Ignition

ini.time <- as.numeric(Sys.time()) # time of process begin, converted into seconds
analysis.nb <- trunc(ini.time) # to provide a specific number ot each analysis
log.file <- paste0("loop", slurm.loop.nb,"_r_", project.name, "_", analysis.nb,"_report.txt")
# name.dir <- paste0(project.name, "_", analysis.nb)
# path.out<-paste0(path.out, name.dir)
# suppressWarnings(dir.create(path.out))
backup.name <- NULL # names of the object to save
fun_export_data(data = paste0("\n\n################################ ", log.file, " ################"), output = log.file, no.overwrite = FALSE, path = path.out, sep = 4)
fun_export_data(path = path.out, data = "################################ INITIAL DATA", output = log.file, sep = 4)
fun_export_data(path = path.out, data = paste0("SCRIPT USED: ", script), output = log.file)
fun_export_data(path = path.out, data = paste0("KIND OF ANALYSIS PERFORMED: ", analysis.kind), output = log.file)
fun_export_data(path = path.out, data = paste0("THE RESPONSE USED IS THE COLUMN: response_ASDAS_R_NR", analysis.kind), output = log.file)

################ Graphical parameter ignition

zone.ini <- matrix(1, ncol=1) # to reset the layout if required
if(erase.graphs == TRUE){
    graphics.off()
}else{
    tempo.cat <- paste0("BEWARE: GRAPHICS HAVE NOT BEEN ERASED. GRAPHICAL PARAMETERS MAY HAVE NOT BEEN REINITIALIZED")
    fun_export_data(path = path.out, data = tempo.cat, output = log.file)
}
if(optional.text == "no.txt"){
    optional.text <- ""
}else{
    fun_export_data(path = path.out, data = paste0("OPTIONAL TEXT:\n", optional.text), output = log.file)
}
par.ini <- fun_open_window(pdf.disp = activate.pdf, path.fun = path.out, pdf.name.file = paste0("loop", slurm.loop.nb, "_graphs"), width.fun = 7, height.fun = 7, paper = "special", no.pdf.overwrite = TRUE, return.output = TRUE)$ini.par
pdf.nb <- dev.cur()



################ Data import

h1 <- unname(unlist(read.table(paste0(path.in, file.name1), nrows = 1, sep=";", dec=",", stringsAsFactors = FALSE)))
h2 <- unname(unlist(read.table(paste0(path.in, file.name1), nrows = 1, skip = 1, sep=";", dec=",", stringsAsFactors = FALSE)))
h3 <- unname(unlist(read.table(paste0(path.in, file.name1), nrows = 1, skip = 12, sep=";", dec=",", stringsAsFactors = FALSE)))
df.nano <- read.table(file = paste0(path.in, file.name1), skip = 13, header=FALSE, sep=";", dec=",") # data frame clinical + nanostring data (from LPS and SEB: dim:  76 855

################ Data modification





################ Sampling step




################ 3 Differential analysis with limma


fun_export_data(path = path.out, data = "################################ LIMMA ANALYSIS", output = log.file, sep = 4)



################ 4 Machine Learning based analysis

######## 4.1 Discovery: Learning the Random Forest

fun_export_data(path = path.out, data = "################################ RANDOM FOREST LEARNING USING THE DISCOVERY SET", output = log.file, sep = 4)


    tempo <- dev.set(pdf.nb) # assign to avoid the message
    plt + geom_point(colour = "red") +
        ggtitle("Evaluating optimal number of features") +
        theme_bw() +
        labs(x="Number of selected features", y="Mean misclassification error on the test sets") +
        theme(
            plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
            axis.text = ggplot2::element_text(size = label.size), 
            axis.title = ggplot2::element_text(size = label.size), 
            legend.text = ggplot2::element_text(size = label.size), 
            legend.title = ggplot2::element_text(size = label.size), 
            strip.text = ggplot2::element_text(size = label.size)
        )
    

    tempo <- dev.set(pdf.nb) # assign to avoid the message
    ggplot2::ggplot(data = df_imp, aes(x=features, y=importance)) + geom_bar(stat = "identity") + theme_bw() + 
        theme(
            axis.text.x = element_text(angle=90, vjust=0.5, hjust=1),
            plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
            axis.text = ggplot2::element_text(size = label.size), 
            axis.title = ggplot2::element_text(size = label.size), 
            legend.text = ggplot2::element_text(size = label.size), 
            legend.title = ggplot2::element_text(size = label.size), 
            strip.text = ggplot2::element_text(size = label.size)
        )

    pheatmap(t(scale(subdat)), annotation_col = annot.rows, cluster_cols = FALSE, show_colnames = FALSE, border_color = NA,  color = colorRampPalette(c("red", "black", "green"))(499), annotation_colors = ann_colors, fontsize_row = label.size, fontsize_col = label.size)

    
    corrplot(cor(subdat), tl.col = "black", tl.cex = label.size / 10)






######## 4.2 Validate the model
# 
fun_export_data(path = path.out, data = "################################ VALIDATION", output = log.file, sep = 4)


tempo <- dev.set(pdf.nb) # assign to avoid the message
roc1.genes.rf <- plotROCCurves(generateThreshVsPerfData(pred1.genes.rf, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 1.genes (only genes) \n AUC=%.2f", performance(pred1.genes.rf, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc2.crp.rf <- plotROCCurves(generateThreshVsPerfData(pred2.crp.rf, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 2.crp (only CRP) \n AUC=%.2f", performance(pred2.crp.rf, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc3.genes.crp.rf <- plotROCCurves(generateThreshVsPerfData(pred3.genes.crp.rf, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 3.genes.crp (genes + CRP) \n AUC=%.2f", performance(pred3.genes.crp.rf, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
data.roc1.genes.rf <- ggplot2::ggplot_build(roc1.genes.rf)$data[[1]]
data.roc2.crp.rf <- ggplot2::ggplot_build(roc2.crp.rf)$data[[1]]
data.roc3.genes.crp.rf <- ggplot2::ggplot_build(roc3.genes.crp.rf)$data[[1]]
backup.name <- c(backup.name, "data.roc1.genes.rf", "data.roc2.crp.rf", "data.roc3.genes.crp.rf")

gridExtra::grid.arrange(roc1.genes.rf, roc2.crp.rf, roc3.genes.crp.rf, nrow = 2)
# ```

######## 4.4 Logistic regression

fun_export_data(path = path.out, data = "################ LOGISTIC REGRESSION", output = log.file)



tempo <- dev.set(pdf.nb) # assign to avoid the message
roc1.genes.logreg <- plotROCCurves(generateThreshVsPerfData(pred1.genes.logreg, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 1.genes (only genes) \n AUC=%.2f", performance(pred1.genes.logreg, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc2.crp.logreg <- plotROCCurves(generateThreshVsPerfData(pred2.crp.logreg, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 2.crp (only CRP) \n AUC=%.2f", performance(pred2.crp.logreg, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc3.genes.crp.logreg <- plotROCCurves(generateThreshVsPerfData(pred3.genes.crp.logreg, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 3.genes.crp (genes + CRP) \n AUC=%.2f", performance(pred3.genes.crp.logreg, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
data.roc1.genes.logreg <- ggplot2::ggplot_build(roc1.genes.logreg)$data[[1]]
data.roc2.crp.logreg <- ggplot2::ggplot_build(roc2.crp.logreg)$data[[1]]
data.roc3.genes.crp.logreg <- ggplot2::ggplot_build(roc3.genes.crp.logreg)$data[[1]]
backup.name <- c(backup.name, "data.roc1.genes.logreg", "data.roc2.crp.logreg", "data.roc3.genes.crp.logreg")

gridExtra::grid.arrange(roc1.genes.logreg, roc2.crp.logreg, roc3.genes.crp.logreg, nrow = 2)
# ```
# 
######## 4.5 RPART

fun_export_data(path = path.out, data = "################ RPART", output = log.file)



tempo <- dev.set(pdf.nb) # assign to avoid the message
roc1.genes.rpart <- plotROCCurves(generateThreshVsPerfData(pred1.genes.rpart, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 1.genes (only genes) \n AUC=%.2f", performance(pred1.genes.rpart, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc2.crp.rpart <- plotROCCurves(generateThreshVsPerfData(pred2.crp.rpart, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 2.crp (only CRP) \n AUC=%.2f", performance(pred2.crp.rpart, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
roc3.genes.crp.rpart <- plotROCCurves(generateThreshVsPerfData(pred3.genes.crp.rpart, measures = list(fpr, tpr, mmce))) + theme_bw() + ggtitle(sprintf("Model 3.genes.crp (genes + CRP) \n AUC=%.2f", performance(pred3.genes.crp.rpart, auc))) +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
data.roc1.genes.rpart <- ggplot2::ggplot_build(roc1.genes.rpart)$data[[1]]
data.roc2.crp.rpart <- ggplot2::ggplot_build(roc2.crp.rpart)$data[[1]]
data.roc3.genes.crp.rpart <- ggplot2::ggplot_build(roc3.genes.crp.rpart)$data[[1]]
backup.name <- c(backup.name, "data.roc1.genes.rpart", "data.roc2.crp.rpart", "data.roc3.genes.crp.rpart")

gridExtra::grid.arrange(roc1.genes.rpart, roc2.crp.rpart, roc3.genes.crp.rpart, nrow = 2)


######## 4.6 Plot top feature boxplots


ggbox <- ggplot(data = boxdat_melt, aes(x=Y, y=value, colour=Y, shape = CV, linetype = CV)) +
    geom_beeswarm(dodge.width = 0.75, alpha = 0.7) +
    geom_boxplot(outlier.shape = NA, fill = NA) +
    facet_wrap(~ Gene, ncol = 5) +
    theme_bw() +
    theme(
        plot.title = ggplot2::element_text(hjust=1, vjust=1, size = label.size), 
        axis.text = ggplot2::element_text(size = label.size), 
        axis.title = ggplot2::element_text(size = label.size), 
        legend.text = ggplot2::element_text(size = label.size), 
        legend.title = ggplot2::element_text(size = label.size), 
        strip.text = ggplot2::element_text(size = label.size)
    )
tempo <- dev.set(pdf.nb) # assign to avoid the message
ggbox


######## 4.7 Frequencies associated to each predictor



################################ End Main code

################################ Post Main code

save(list=c(backup.name), file = paste0(path.out, "loop", slurm.loop.nb, "_res_data.RData"))

############ Pdf window closing

fun_close_specif_window()

############ total computing time

fin.time <- as.numeric(Sys.time()) # time of process end
cat("TOTAL COMPUTATION TIME: ", as.character(lubridate::seconds_to_period(round(fin.time - ini.time))), "\n\n")
fun_export_data(path = path.out, data = paste0("\n\n\n\n################################ TOTAL COMPUTING TIME\n\n", as.character(lubridate::seconds_to_period(round(fin.time - ini.time)))), output = log.file, sep = 4)

############ Parameter printing

fun_export_data("\n\n\n\n################################ INITIAL SETTINGS OF PARAMETERS", output = log.file, path = path.out)
fun_export_data(path = path.out, data = param.ini.settings, output = log.file, vector.cat = TRUE)
fun_export_data("\n\n\n\n################################ SYSTEM AND PACKAGES", output = log.file, path = path.out)
fun_export_data(path = path.out, data = sessionInfo(), output = log.file, vector.cat = TRUE)

################################ End Post Main code