forked from ac812/XWAS-FUSION
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigChrScheduler.R
141 lines (125 loc) · 8.24 KB
/
ConfigChrScheduler.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
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
#' ----------------------------------------------------------------
#' Configures the commands to be executed to get the weights for
#' each marker by parallelizing over chromosomes
#' args[1] is the path to the config file
#' args[2] is the path to the source code
#'-----------------------------------------------------------------
#' Creates the submission file that submits Config_compute_weights.R to SGE scheduler.
#' @param chrSchedulerFile Full path of job submission file.
#' @param chrLogOut Full path of job .out file.
#' @param chrLogError Full path of job .error file.
#' @param queue Queue name of where job is to be submitted.
#' @param pathRLIBS RLIBS environmental variable.
#' @param codePath Full path of the source code directory.
#' @param configPath Full path of configuration file.
createSGEChrSchedulerSubmissionFile <- function(chrSchedulerFile, chrLogOut, chrLogError, queue, pathRLIBS, codePath, configPath){
cat(paste0("#!/bin/bash", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -S /bin/bash", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -o ", chrLogOut, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -e ", chrLogError, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -N FUSIONChr", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -q ", queue, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#$ -t 1-22", "\n\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("export R_LIBS=", pathRLIBS, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("Rscript ", codePath, "/Config_compute_weights.R ", configPath, " ", codePath, " ", "$SGE_TASK_ID", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("exit 0", "\n"), file=chrSchedulerFile, append=TRUE)
}
#' Creates the submission file that submits Config_compute_weights.R to SLURM scheduler.
#' @param chrSchedulerFile Full path of job submission file.
#' @param chrLogOut Full path of job .out file.
#' @param chrLogError Full path of job .error file.
#' @param queue Queue name of where job is to be submitted.
#' @param pathRLIBS RLIBS environmental variable.
#' @param codePath Full path of the source code directory.
#' @param configPath Full path of configuration file.
createSLURMChrSchedulerSubmissionFile <- function(chrSchedulerFile, chrLogOut, chrLogError, queue, pathRLIBS, codePath, configPath){
cat(paste0("#!/bin/bash", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#SBATCH --output=", chrLogOut, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#SBATCH --error=", chrLogError, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#SBATCH --job_name=FUSIONChr", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#SBATCH --ntasks=1", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("#SBATCH --array=1-22", "\n\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("export R_LIBS=", pathRLIBS, "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("Rscript ", codePath, "/Config_compute_weights.R ", configPath, " ", codePath, " ", "$SLURM_ARRAY_TASK_ID", "\n"), file=chrSchedulerFile, append=TRUE)
cat(paste0("exit 0", "\n"), file=chrSchedulerFile, append=TRUE)
}
#' Creates the submission file that submits Schedule_compute_weights.R to SGE scheduler.
#' @param holdChrFile Full path of job submission file.
#' @param holdChrOut Full path of job .out file.
#' @param holdChrError Full path of job .error file.
#' @param queue Queue name of where job is to be submitted.
#' @param pathRLIBS RLIBS environmental variable.
#' @param codePath Full path of the source code directory.
#' @param configPath Full path of configuration file.
createSGEHoldSubmissionFile <- function(holdChrFile, holdChrOut, holdChrError, queue, pathRLIBS, codePath, configPath){
cat(paste0("#!/bin/bash", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#$ -S /bin/bash", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#$ -q ", queue, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#$ -o ", holdChrOut, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#$ -e ", holdChrError, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#$ -N FUSIONChrHold", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("export R_LIBS=", pathRLIBS, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("Rscript ", codePath, "/Schedule_compute_weights_SGE.R ", configPath, " ", codePath, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("exit 0", "\n"), file=holdChrFile, append=TRUE)
}
#' Creates the submission file that submits Schedule_compute_weights.R to SLURM scheduler.
#' @param holdChrFile Full path of job submission file.
#' @param holdChrOut Full path of job .out file.
#' @param holdChrError Full path of job .error file.
#' @param queue Queue name of where job is to be submitted.
#' @param pathRLIBS RLIBS environmental variable.
#' @param codePath Full path of the source code directory.
#' @param configPath Full path of configuration file.
createSLURMHoldSubmissionFile <- function(holdChrFile, holdChrOut, holdChrError, queue, pathRLIBS, codePath, configPath){
cat(paste0("#!/bin/bash", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#SBATCH --output=", holdChrOut, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#SBATCH --error=", holdChrError, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#SBATCH --job_name=FUSIONChr", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("#SBATCH --ntasks=1", "\n"), file=holdChrFile, append=TRUE)
cat(paste0("export R_LIBS=", pathRLIBS, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("Rscript ", codePath, "/Schedule_compute_weights_SLURM.R ", configPath, " ", codePath, "\n"), file=holdChrFile, append=TRUE)
cat(paste0("exit 0", "\n"), file=holdChrFile, append=TRUE)
}
#=========================================================
# Main code
#=========================================================
args <- commandArgs(trailingOnly=TRUE)
#load config (using same arguments are ConfigChrScheduler.R)
source(paste0(args[2], "/Config.R"))
#create temp directory to save temp files
unlink(paste0(config$workingDir, "/temp"), recursive=TRUE)
unlink(paste0(config$workingDir, "/temp/tmp_weights"), recursive=TRUE)
unlink(paste0(config$workingDir, "/PLINK"), recursive=TRUE)
unlink(paste0(config$workingDir, "/weights"), recursive=TRUE)
unlink(paste0(config$workingDir, "/temp/ChrPLINK"), recursive=TRUE)
dir.create(paste0(config$workingDir, "/temp"))
dir.create(paste0(config$workingDir, "/temp/tmp_weights"),recursive=TRUE)
dir.create(paste0(config$workingDir, "/temp/ChrPLINK"), recursive=TRUE)
dir.create(paste0(config$workingDir, "/weights"))
dir.create(paste0(config$workingDir, "/PLINK"))
#create submission file
message("Parallelising over chromosomes")
chrSchedulerFile <- paste0(config$workingDir,"/temp/tmp_weights/ChrScheduler.sh")
chrLogOut <- paste0(config$workingDir,"/temp/tmp_weights/ChrScheduler.o")
chrLogError <- paste0(config$workingDir,"/temp/tmp_weights/ChrScheduler.e")
#submission script to be executed after all chromosomes have been processed
holdChrFile <- paste0(config$workingDir, "/temp/tmp_weights/holdChrScheduler.sh")
holdChrOut <- paste0(config$workingDir, "/temp/tmp_weights/holdChrScheduler.o")
holdChrError <- paste0(config$workingDir, "/temp/tmp_weights/holdChrScheduler.e")
#create submission script depending on scheduler
if(config$scheduler == "SGE"){
createSGEChrSchedulerSubmissionFile(chrSchedulerFile, chrLogOut, chrLogError, config$queue, config$pathRLIBS, args[2], args[1])
system(paste0(config$path_qsub, " ", chrSchedulerFile))
#wait for all the chromosomes to be processed and then run Schedule_compute_weights.R
createSGEHoldSubmissionFile(holdChrFile, holdChrOut, holdChrError, config$queue, config$pathRLIBS, args[2], args[1])
system(paste0(config$path_qsub, " -hold_jid FUSIONChr ", holdChrFile))
}
if(config$scheduler == "SLURM")
{
createSLURMChrSchedulerSubmissionFile(chrSchedulerFile, chrLogOut, chrLogError, config$queue, config$pathRLIBS, args[2], args[1])
system(paste0(config$path_sbatch, " ", chrSchedulerFile))
#wait for all the chromosomes to be processed and then run Schedule_compute_weights.R -
#NOTE Array jobs and job to run after array jobs are complete have to be the same name for singleton to work
createSLURMHoldSubmissionFile(holdChrFile, holdChrOut, holdChrError, config$queue, config$pathRLIBS, args[2], args[1])
system(paste0(config$path_sbatch, " --dependency=singleton ", holdChrFile))
}