-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcww.sh
executable file
·343 lines (278 loc) · 6.91 KB
/
cww.sh
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
#!/usr/bin/bash
###########################################################
#
# Bash wrapper to launch wdl workflow from SINGULARITY
#
# By Nicolas SOIRAT - [email protected]
# Version 1.0.0
# ---------------------------------------------------------
#
# MoBiDiC
#
###########################################################
###########################################################
# Global
###########################################################
RED='\033[0;31m'
LIGHTRED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
VERSION="1.0.0"
# -- Script log
VERBOSITY=3
# Help
###########################################################
help() {
echo "CromWrap (version ${VERSION}) is a wrapper allowing you to start wdl workflow"
echo "Usage : ./cromwrap.sh"
echo "Mandatory arguments : "
echo " -e | --exec <cromwell[version].jar> : path to cromwell"
echo " -w | --wdl <workflowfile.wdl> : wdl file input"
echo " -i | --input <yourinpunts_inputs.json> : select your input file"
echo " "
echo "Optional arguments : "
echo " -c | --conf <file.conf> : If you want to use Database for Cromwell for example"
echo " -o | --option <options.json> : File to add in the command if you have specific options for cromwell"
echo " -v | --verbosity <integer> : decrease or increase verbosity level (ERROR : 1 | WARNING : 2 | INFO [default] : 3 | DEBUG : 4)"
echo " "
echo "General arguments : "
echo " -h | --help : show this help message"
echo " "
exit 1
}
###########################################################
# Log
###########################################################
# -- Log variables
ERROR=1
WARNING=2
INFO=3
DEBUG=4
# -- Log functions
error() { log ${ERROR} "${RED}ERROR${NC} : $1" ; }
warning() { log ${WARNING} "${YELLOW}WARNING${NC} : $1" ; }
info() { log ${INFO} "${BLUE}INFO${NC} : $1" ; }
debug() { log ${DEBUG} "${LIGHTRED}DEBUG${NC} : $1" ; }
# -- Print log
echoerr() { echo -e "$@" 1>&2 ; }
log() {
if [ ${VERBOSITY} -ge $1 ]
then
echoerr "[`date +'%Y-%m-%d %H:%M:%S'`] - CromWrap version : ${VERSION} - $2"
fi
}
###########################################################
# Extracting arguments ...
###########################################################
# -- Variables
CONFFILE=""
INPUTSFILE=""
OPTIONFILE=""
CROMWELLFILE=""
WORKFLOWFILE=""
CONFCOUNTER=0
INPUTSCOUNTER=0
OPTIONCOUNTER=0
CROMCOUNTER=0
WORKFLOWCOUNTER=0
VERBOSITYCOUNTER=0
# -- Extraction
while [ "$1" != "" ]
do
case "$1" in
-c | --conf) shift
CONFFILE=$1
((CONFCOUNTER++))
;;
-i | --input) shift
INPUTSFILE=$1
((INPUTSCOUNTER++))
;;
-o | --option) shift
OPTIONFILE=$1
((OPTIONCOUNTER++))
;;
-e | --exec) shift
CROMWELLFILE=$1
((CROMCOUNTER++))
;;
-w | --wdl) shift
WORKFLOWFILE=$1
((WORKFLOWCOUNTER++))
;;
-v | --verbosity) shift
# Check if verbosity level argument is an integer before assignment
if ! [[ "$1" =~ ^[0-9]+$ ]]
then
error "\"$1\" must be an integer !"
echo " "
help
else
VERBOSITY=$1
((VERBOSITYCOUNTER++))
fi
;;
-h | --help)
help
exit
;;
*)
echo "Unknow option encounter : \"$1\""
echo " "
help
;;
esac
shift
done
# -- DEBUG
debug "CONF COUNTER=${CONFCOUNTER}"
debug "INPUT COUNTER=${INPUTSCOUNTER}"
debug "CROMCOUNTER=${CROMCOUNTER}"
debug "OPTION COUNTER=${OPTIONCOUNTER}"
debug "WF COUNTER=${WORKFLOWCOUNTER}"
debug "VERBOSITYCOUNTER=${VERBOSITYCOUNTER}"
debug "CONF = ${CONFFILE}"
debug "INPUT = ${INPUTSFILE}"
debug "OPTION = ${OPTIONFILE}"
debug "CROM = ${CROMWELLFILE}"
debug "WF = ${WORKFLOWFILE}"
################################################@##########
# Variable checking
###########################################################
# -- Check if there isn't more than one file for each option
info "Argument checking..."
if [ ${CONFCOUNTER} -gt 1 ]
then
echo "Can't use more than one configuration file !"
echo " "
help
fi
if [ ${INPUTSCOUNTER} -ne 1 ]
then
error "You have to use only one input file !"
echo " "
help
fi
if [ ${OPTIONCOUNTER} -gt 1 ]
then
error "Can't use more than one option file !"
echo " "
help
fi
if [ ${CROMCOUNTER} -ne 1 ]
then
error "Please enter only one path to cromwell.jar !"
echo " "
help
fi
if [ ${WORKFLOWCOUNTER} -ne 1 ]
then
error "You have to select ONE workflow file !"
echo " "
help
fi
if [ ${VERBOSITYCOUNTER} -gt 1 ]
then
error "You have to use only one time -s option !"
echo " "
help
fi
info "Arguments per option : OK !"
# -- Check if files exist
if [ ! -f ${CONFFILE} ]
then
error "\"${CONFFILE}\" does not exist !"
echo " "
help
fi
if [ ! -f ${INPUTSFILE} ]
then
error "\"${INPUTSFILE}\" file does not exist !"
echo " "
help
fi
if [ ! -f ${OPTIONFILE} ]
then
error "\"${OPTIONFILE}\" does not exist !"
echo " "
help
fi
if [ ! -f ${CROMWELLFILE} ]
then
error "\"${CROMWELLFILE}\" is not valid !"
echo " "
help
fi
if [ ! -f ${WORKFLOWFILE} ]
then
error "\"${WORKFLOWFILE}\" does not exist !"
echo " "
help
fi
info "Files exist !"
# -- Check file extensions
if [[ ${CONFCOUNTER} -eq 1 && ${CONFFILE##*\.} != "conf" ]]
then
error "\"${CONFFILE}\" must be .conf file !"
echo " "
help
fi
if [ ${INPUTSFILE##*_} != "inputs.json" ]
then
error "\"${INPUTSFILE}\" must be _inputs.json file !"
echo " "
help
fi
if [[ ${OPTIONCOUNTER} -eq 1 && ${OPTIONFILE##*\.} != "json" ]]
then
error "\"${OPTIONFILE}\" must be .json file !"
echo " "
help
fi
if [ ${CROMWELLFILE##*\.} != "jar" ]
then
error "\"${CROMWELLFILE}\" must be .jar file !"
echo " "
help
fi
if [ ${WORKFLOWFILE##*\.} != "wdl" ]
then
error "\"${WORKFLOWFILE}\" must be .wdl file !"
echo " "
help
fi
info "File extension : OK !"
info "Argument checking finished"
# -- Check value of VERBOSITY LEVEL
if [ ${VERBOSITY} -gt 4 ] || [ ${VERBOSITY} -lt 1 ]
then
error "\"${VERBOSITY}\" is not a correct value for verbosity level !"
echo " "
help
fi
###########################################################
# Launching WDL command ...
###########################################################
# -- Preparation
if [ ${CONFCOUNTER} -eq 1 ]
then
CONF="-Dconfig.file=${CONFFILE}"
else
warning "CromWrap will launch cromwell command without configuration file !"
fi
if [ ${OPTIONCOUNTER} -eq 1 ]
then
OPTION="-o ${OPTIONFILE}"
else
warning "CromWrap will launch cromwell command without option file !"
fi
# -- Start
info "Launching wdl command ..."
java ${CONF} -jar ${CROMWELLFILE} run ${WORKFLOWFILE} -i ${INPUTSFILE} ${OPTION}
if [ "$?" -eq 0 ];then
info "... Done !"
else
error "Command java ${CONF} -jar ${CROMWELLFILE} run ${WORKFLOWFILE} -i ${INPUTSFILE} ${OPTION} return non-zero exit code $?"
exit 1
fi