comparison redelacSticsTool.R @ 15:af807768332e draft default tip

"planemo upload for repository https://forgemia.inra.fr/redelac commit 179e64aac208ae8af4d7416a7d5ff4b9da572850"
author siwaa
date Fri, 06 Feb 2026 13:28:00 +0000
parents e0d592bb516e
children
comparison
equal deleted inserted replaced
14:30d7b0210581 15:af807768332e
8 library(stringr) 8 library(stringr)
9 library(readxl) 9 library(readxl)
10 library(data.table) 10 library(data.table)
11 library(readr) 11 library(readr)
12 library(tidyr) 12 library(tidyr)
13 13 library(arrow)
14 sessionInfo() 14 sessionInfo()
15 15
16 args = commandArgs(trailingOnly = TRUE) 16 args = commandArgs(trailingOnly = TRUE)
17 17
18 startTime <- Sys.time() 18 startTime <- Sys.time()
33 parallel <- (args[2] == "parallel") 33 parallel <- (args[2] == "parallel")
34 print(paste("parallel:", parallel, args[2])) 34 print(paste("parallel:", parallel, args[2]))
35 nbSlots <- as.integer(args[3]) 35 nbSlots <- as.integer(args[3])
36 print(paste("nbslots:", nbSlots)) 36 print(paste("nbslots:", nbSlots))
37 scenario <- args[4] 37 scenario <- args[4]
38 resulType <- args[5]
39
40 parquetOut <- (resulType == "parquet" || resulType == "both" )
41 baseOut <- (resulType == "rds+csv" || resulType == "both" )
38 42
39 # USMs file loading 43 # USMs file loading
40 44
41 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>% 45 usms_param <- read_params_table(file.path(workspace, USMsFile)) %>%
42 select( 46 select(
101 105
102 ids <- seq(1, nbUSMs, chunckSize) 106 ids <- seq(1, nbUSMs, chunckSize)
103 107
104 foreach (i = ids, 108 foreach (i = ids,
105 .options.future = list(packages = c("foreach", "SticsRFiles"))) %dordopar% { 109 .options.future = list(packages = c("foreach", "SticsRFiles"))) %dordopar% {
106 usmsXfolder = file.path(workspace, paste0("UXF__", i)) 110 usmsXfolder = file.path(workspace, paste0("UXF__", i))
107 dir.create(usmsXfolder) 111 dir.create(usmsXfolder)
108 gen_usms_xml(file = file.path(usmsXfolder, paste0("usms__", i, ".xml")), 112 gen_usms_xml(file = file.path(usmsXfolder, paste0("usms__", i, ".xml")),
109 param_df = usms_param[i:min(i + chunckSize - 1, nbUSMs),]) 113 param_df = usms_param[i:min(i + chunckSize - 1, nbUSMs),])
110 } 114 }
111 115
112 afterGenXmlTime <- Sys.time() 116 afterGenXmlTime <- Sys.time()
290 remove = FALSE 294 remove = FALSE
291 ) 295 )
292 296
293 #sauvegarde sous la forme d'un fichier rds 297 #sauvegarde sous la forme d'un fichier rds
294 298
295 if (dir.exists(paste0( 299 if (baseOut) {
296 workspace, 300
297 "/analyse_simulations_STICS/", 301 if (dir.exists(paste0(
298 systeme, 302 workspace,
299 "/", 303 "/analyse_simulations_STICS/",
300 rotation 304 systeme,
301 )) == FALSE) { 305 "/",
302 dir.create( 306 rotation
307 )) == FALSE) {
308 dir.create(
309 paste0(
310 workspace,
311 "/analyse_simulations_STICS/",
312 systeme,
313 "/",
314 rotation
315 ),
316 recursive = TRUE
317 )
318 }
319
320 saveRDS(
321 sim_df,
303 paste0( 322 paste0(
304 workspace, 323 workspace,
305 "/analyse_simulations_STICS/", 324 "/analyse_simulations_STICS/",
306 systeme, 325 systeme,
307 "/", 326 "/",
308 rotation 327 rotation,
309 ), 328 "/outputs-",
310 recursive = TRUE 329 rotation,
330 "-",
331 upc,
332 "-",
333 sol,
334 "-",
335 scenario,
336 ".rds"
337 )
311 ) 338 )
312 } 339 }
313 340
314 saveRDS( 341 if (parquetOut) {
315 sim_df, 342
316 paste0( 343 if (dir.exists(paste0(
317 workspace, 344 workspace,
318 "/analyse_simulations_STICS/", 345 "/analyse_simulations_STICS/",
319 systeme, 346 "/donnees_parquet_outputs/"
320 "/", 347 )) == FALSE) {
321 rotation, 348 dir.create(
322 "/outputs-", 349 paste0(
323 rotation, 350 workspace,
324 "-", 351 "/analyse_simulations_STICS/",
325 upc, 352 "/donnees_parquet_outputs/"
326 "-", 353 ),
327 sol, 354 recursive = TRUE
328 "-", 355 )
329 scenario, 356 }
330 ".rds" 357
331 ) 358 write_parquet(
332 ) 359 sim_df,
360 paste0(
361 workspace,
362 "/analyse_simulations_STICS/",
363 "/donnees_parquet_outputs/",
364 "outputs-",
365 rotation,
366 "-",
367 upc,
368 "-",
369 sol,
370 "-",
371 scenario,
372 ".parquet"
373
374 ))
375 }
333 376
334 successive_usms_tab_split[[j]]$Treatment <- NULL 377 successive_usms_tab_split[[j]]$Treatment <- NULL
335 successive_usms_tab_split[[j]]$Number_USM <- NULL 378 successive_usms_tab_split[[j]]$Number_USM <- NULL
336 379
337 list_usms <- 380 list_usms <-
415 ), 458 ),
416 sep = "-", 459 sep = "-",
417 remove = FALSE 460 remove = FALSE
418 ) 461 )
419 462
420 write_delim( 463 if (baseOut) {
421 x = rap, 464
422 file = paste0( 465 write_delim(
466 x = rap,
467 file = paste0(
468 workspace,
469 "/analyse_simulations_STICS/",
470 systeme,
471 "/",
472 rotation,
473 "/report-",
474 rotation,
475 "-",
476 upc,
477 "-",
478 sol,
479 "-",
480 scenario,
481 ".csv"
482 ),
483 delim = ";"
484 )
485 }
486
487 if (parquetOut) {
488
489 if (dir.exists(paste0(
423 workspace, 490 workspace,
424 "/analyse_simulations_STICS/", 491 "/analyse_simulations_STICS/",
425 systeme, 492 "/donnees_parquet_report/"
426 "/", 493 )) == FALSE) {
427 rotation, 494 dir.create(
428 "/report-", 495 paste0(
429 rotation, 496 workspace,
430 "-", 497 "/analyse_simulations_STICS/",
431 upc, 498 "/donnees_parquet_report/"
432 "-", 499 ),
433 sol, 500 recursive = TRUE
434 "-", 501 )
435 scenario, 502 }
436 ".csv" 503
437 ), 504 write_parquet(
438 delim = ";" 505 sim_df,
439 ) 506 paste0(
440 507 workspace,
508 "/analyse_simulations_STICS/",
509 "/donnees_parquet_report/",
510 "report-",
511 rotation,
512 "-",
513 upc,
514 "-",
515 sol,
516 "-",
517 scenario,
518 ".parquet"
519
520 ))
521 }
441 } 522 }