-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreality_checks_cluster.R
78 lines (63 loc) · 2.31 KB
/
reality_checks_cluster.R
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
# ##############################################################################
#
## Scripts to check the reality of simulations using batchtools
#
# ##############################################################################
library("tidyverse")
library("batchtools")
library("devtools")
library("SIAMCAT")
library("here")
args <- commandArgs(trailingOnly = TRUE)
# load package
devtools::load_all(simba.loc)
# get parameters
simulation <- args[1]
sim.files <- list.files(here('simulations'),
full.names = TRUE, recursive = TRUE)
sim.file <- sim.files[str_detect(sim.files, pattern = simulation)]
if (length(sim.file) != 1){
stop("Cannot find the correct simulation!")
}
if (!file.exists(sim.file)){
stop("No such simulation exists!")
}
# copy simulation file to scratch for faster I/O access
file.loc <- paste0(temp.loc, 'simulations/', simulation, '.h5')
file.copy(from=sim.file, file.loc)
# start of real script :D
sim.params <- h5read(file.loc, name='simulation_parameters/sim_params')
# get groups
temp <- h5ls(file.loc, recursive=FALSE)
groups <- temp$name
groups <- setdiff(groups, c('original_data', 'simulation_parameters'))
groups <- unique(str_remove(groups, '_rep[0-9]*$'))
# create a job registry
if (!dir.exists(paste0(temp.loc, 'reality_checks_registries'))){
dir.create(paste0(temp.loc, 'reality_checks_registries'))
}
job.registry <- paste0(temp.loc, 'reality_checks_registries/', simulation)
if (!dir.exists(job.registry)){
makeRegistry(file.dir=job.registry, work.dir=here(),
conf.file=here('cluster_config', 'batchtools_reality_conf.R'))
} else {
loadRegistry(file.dir=job.registry, writeable=TRUE,
conf.file=here('cluster_config', 'batchtools_reality_conf.R'))
}
.f <- function(g, sim.file, max.iter, simba.loc){
# load SIMBA
devtools::load_all(simba.loc)
res.list <- list()
# iterate over repetitions
for (x in seq_len(max.iter)){
res.list[[x]] <- reality.check(sim.location=sim.file,
group=paste0(g, '_rep', x),
ml=TRUE)
}
return(res.list)
}
# add jobs
batchMap(.f, groups, more.args=list('sim.file'=sim.file,
'max.iter'=sim.params$repeats,
'simba.loc'=simba.loc))
submitJobs()