-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetabomodules
executable file
·420 lines (386 loc) · 13.2 KB
/
metabomodules
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
#! /bin/bash -
# Copyright 2019 Bergmann's Lab UNIL <[email protected]>
#
# This file is part of METABOMODULES Tool.
#
# METABOMODULES Tool is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# METABOMODULES Tool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# GNU General Public License: <https://www.gnu.org/licenses/>.
working_dir=$PWD
install_dir="$HOME/.metabomodules"
###################################################################################################
# HELP USAGE MESSAGE
###################################################################################################
usage() {
echo ""
echo "USAGE: metabomodules --input=[...] --container=[...] [OPTIONS]"
echo ""
echo " MANDATORY:"
echo " --input= path to file: 1H NMR dataset to be analysed"
echo " --container= [docker|singularity] container type"
echo ""
echo " OPTIONL:"
echo " --output= directory in which to output results (default=current direcotry)"
echo " --method= [acp|isa|pca] method to be run (default=all methods will be run)"
echo " --number_pseudospectra= integer: number of pseudospectra to generate (default=179)"
echo " --number_permutations= integer: number of metabomatching permutations (default=9999, recommended: 9999+)"
echo " (method-specific options: ACP)"
echo " --ACP_remNeigbPairsFlag= [true|false] remove feature pairs in the same neighborhood as other pairs"
echo " --ACP_OffDiagDist= float: off diagonal distance for correlation matrixi (default=0.1)"
echo " (method-specific options: ISA)"
echo " --ISA_seedmatrix path to file: file containing ISA seeds"
echo " --ISA_dsame float (default=0.8)"
echo " --ISA_dconv float (default=0.99)"
echo " --ISA_nseed int (default=500)"
echo " --ISA_seedsparsity int (default=3)"
echo " --ISA_maxiter int (default=50)"
echo " --ISA_sgc int (default=0)"
echo " --ISA_sgr int (default=1)"
echo " --ISA_thc list of int (default \"1,2,3,4,5,6\")"
echo " --ISA_thr list of int (default \"1,2,3,4,5,6\")"
echo " --ISA_norm string (default=\"double\")"
echo " --ISA_nt [true|false] "
echo " --ISA_inputhasheaders [true|false] "
echo " --ISA_inputhaslabels [true|false] "
echo " --ISA_nopurge [true|false] "
echo " --ISA_quiet [true|false] "
echo " --ISA_nosweep [true|false] "
echo " --ISA_onefile [true|false] "
echo " --ISA_gopseudo [true|false] "
echo " (filter-specific options)"
echo " --FILTER_z_score_th int (default 4)"
echo " --FILTER_adj_score_th int (default 2)"
echo " --FILTER_redo [true|false]"
}
###################################################################################################
# PARAMETERS
###################################################################################################
# DEFAULTS
input="not_set"
output="not_set"
method="not_set"
container="not_set"
number_pseudospectra=179
number_permutations=9999
ACP_OffDiagDist="0.1"
ACP_remNeigbPairsFlag="true"
ISA_seedmatrix="not_set"
ISA_dsame="0.80"
ISA_dconv="0.99"
ISA_nseed=500
ISA_seedsparsity=3
ISA_maxiter=50
ISA_sgc=0
ISA_sgr=1
ISA_thc="1,2,3,4,5,6"
ISA_thr="1,2,3,4,5,6"
ISA_norm="double"
ISA_nt="true"
ISA_inputhasheaders="false"
ISA_inputhaslabels="false"
ISA_nopurge="true"
ISA_quiet="false"
ISA_nosweep="true"
ISA_onefile="false"
ISA_gopseudo="false"
FILTER_z_score_th=4
FILTER_adj_score_th=2
FILTER_redo="false"
# READ USER INPUT #################################################################################
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
exit
;;
--input)
input=$VALUE
;;
--container)
container=$VALUE
;;
--output)
output=$VALUE
;;
--method)
method=$VALUE
;;
--number_pseudospectra)
number_pseudospectra=$VALUE
;;
--number_permutations)
number_permutations=$VALUE
;;
--ACP_OffDiagDist)
ACP_OffDiagDist=$VALUE
;;
--ACP_remNeigbPairsFlag)
ACP_remNeigbPairsFlag=$VALUE
;;
--ISA_seedmatrix)
ISA_seedmatrix=$VALUE
;;
--ISA_dsame)
ISA_dsame=$VALUE
;;
--ISA_dconv)
ISA_dconv=$VALUE
;;
--ISA_nseed)
ISA_nseed=$VALUE
;;
--ISA_seedsparsity)
ISA_seedsparsity=$VALUE
;;
--ISA_maxiter)
ISA_maxiter=$VALUE
;;
--ISA_sgc)
ISA_sgc=$VALUE
;;
--ISA_sgr)
ISA_sgr=$VALUE
;;
--ISA_thc)
ISA_thc=$VALUE
;;
--ISA_thr)
ISA_thr=$VALUE
;;
--ISA_norm)
ISA_norm=$VALUE
;;
--ISA_nt)
ISA_nt=$VALUE
;;
--ISA_inputhasheaders)
ISA_inputhasheaders=$VALUE
;;
--ISA_inputhaslabels)
ISA_inputhaslabels=$VALUE
;;
--ISA_nopurge)
ISA_nopurge=$VALUE
;;
--ISA_quiet)
ISA_quiet=$VALUE
;;
--ISA_nosweep)
ISA_nosweep=$VALUE
;;
--ISA_onefile)
ISA_onefile=$VALUE
;;
--ISA_gopseudo)
ISA_gopseudo=$VALUE
;;
--FILTER_z_score_th)
FILTER_z_score_th=$VALUE
;;
--FILTER_adj_score_th)
FILTER_adj_score_th=$VALUE
;;
--FILTER_redo)
FILTER_redo=$VALUE
;;
*)
echo ""
echo "ERROR: unknown parameter \"$PARAM\""
echo ""
usage
exit 1
;;
esac
shift
done
# HANDLE MANDATORY AND DEFAULT PARAMETERS #########################################################
if [ "$input" != "not_set" ]; then
if [ ! -f "$input" ]; then
echo "ERROR: please provide a valid file for the --input option."
" the file $input does not exist."
exit 1
else
# copy input file to designated input location
rm -f "$install_dir/code/input.csv";
cp $input "$install_dir/code/input.csv";
fi
else
echo "ERROR: you must provide an input file (--input option)"
usage
exit 1
fi
if [ "$container" != "docker" -a "$container" != "singularity" ]; then
echo "ERROR: you must specify a container type (--container option)"
usage
exit 1
fi
if [ "$container" = "docker" ]; then
docker --help > /tmp/docker_test
if ! grep -q "Usage: docker" /tmp/docker_test; then
echo "ERROR: you specified --container=docker, but docker is not installed."
echo " Please visit https://www.docker.com"
exit 1
fi
fi
if [ "$container" = "singularity" ]; then
singularity --help > /tmp/singularity_test
if ! grep -q "Usage:" /tmp/singularity_test; then
echo "ERROR: you specified --container=singularity, but singularity is not installed."
echo " Please visit http://singularity.lbl.gov"
exit 1
fi
fi
if [ "$output" != "not_set" ]; then
# create dir if it does not exist
if [ ! -d "$output" ]; then
mkdir $output
fi
# remove trailing slash if present
if [[ $output == */ ]]; then
#output=${output::-1}
output=${output::${#output}-1}
fi
else
output=$working_dir
fi
if [ "$method" != "not_set" ]; then
if [ "$method" != "isa" ]; then
if [ "$method" != "acp" ]; then
if [ "$method" != "pca" ]; then
echo "ERROR: you specified --method=$method: $method is not a valid method"
exit 1
fi
fi
fi
fi
# WRITE PARAMETERS TO FILE ########################################################################
addToParametersFile() {
echo "$1"="$2" >> "$install_dir/code/parameters.txt"
}
rm -f "$install_dir/code/parameters.txt"
touch "$install_dir/code/parameters.txt"
addToParametersFile method "$method"
addToParametersFile number_pseudospectra "$number_pseudospectra"
addToParametersFile number_permutations "$number_permutations"
addToParametersFile ACP_OffDiagDist "$ACP_OffDiagDist"
addToParametersFile ACP_remNeigbPairsFlag "$ACP_remNeigbPairsFlag"
addToParametersFile ISA_seedmatrix "$ISA_seedmatrix"
addToParametersFile ISA_dsame "$ISA_dsame"
addToParametersFile ISA_dconv "$ISA_dconv"
addToParametersFile ISA_nseed "$ISA_nseed"
addToParametersFile ISA_seedsparsity "$ISA_seedsparsity"
addToParametersFile ISA_maxiter "$ISA_maxiter"
addToParametersFile ISA_sgc "$ISA_sgc"
addToParametersFile ISA_sgr "$ISA_sgr"
addToParametersFile ISA_thc "$ISA_thc"
addToParametersFile ISA_thr "$ISA_thr"
addToParametersFile ISA_norm "$ISA_norm"
addToParametersFile ISA_nt "$ISA_nt"
addToParametersFile ISA_inputhasheaders "$ISA_inputhasheaders"
addToParametersFile ISA_inputhaslabels "$ISA_inputhaslabels"
addToParametersFile ISA_nopurge "$ISA_nopurge"
addToParametersFile ISA_quiet "$ISA_quiet"
addToParametersFile ISA_nosweep "$ISA_nosweep"
addToParametersFile ISA_onefile "$ISA_onefile"
addToParametersFile ISA_gopseudo "$ISA_gopseudo"
addToParametersFile FILTER_z_score_th "$FILTER_z_score_th"
addToParametersFile FILTER_adj_score_th "$FILTER_adj_score_th"
addToParametersFile FILTER_redo "$FILTER_redo"
###################################################################################################
# INVOKE DOCKER/SINGULARITY TO RUN THE CHOSEN METHOD
###################################################################################################
checkDockerBuildSuccess() {
if ! grep -q "Successfully built" /tmp/docker_build_output; then
echo "ERROR: docker build returned an error"
echo " - is an internet connection available?"
echo " - is the docker daemon running?"
echo "see /tmp/docker_build_output for details"
exit 1
fi
}
checkSingularityBuildSuccess() {
if ! grep -q "Finalizing Singularity container" /tmp/singularity_build_output; then
echo "ERROR: singularity build returned an error"
echo " - is an internet connection available?"
echo " - is singularity running?"
echo "see /tmp/singularity_build_output for details"
rm -f "$install_dir/containers/"$method"/singularity/"$method"-image.img"
exit 1
fi
}
# take initial timestamp
begin=$(date +%s)
timestamp=`date '+%Y-%m-%d-%H%M%S'`
# increase stack memory limit
# clear previous run (this is a precation, in the case errors occurred)
rm -rf "$install_dir"/code/output/2*
default_ulimit=$(ulimit -s) #ulimit -s 32768 > /dev/null 2>&1
# if redoing the filtering, make output of previous runs available
if [ "$FILTER_redo" = "true" ]
then
echo cp -R "$output"/ "$install_dir"/code/output/
cp -R "$output"/ "$install_dir"/code/output/
fi
# RUN THE METHOD ##################################################################################
echo "" && echo "--------------------------------------------------------------------------------"
echo "METABOMODULES"
if [ "$container" = "singularity" ]
then
# build the singularity image (if image already exists, skip this step)
echo "Preparing container, please wait..."
if [ ! -f "$install_dir"/containers/singularity/image.img ]; then
cd "$install_dir"/containers/singularity/
singularity image.create --size 1500 ./image.img > \
/tmp/singularity_create_output 2>&1
singularity build ./image.img Singularity > \
/tmp/singularity_build_output 2>&1
cd ../../..
checkSingularityBuildSuccess
cd $working_dir
fi
# run container
echo "Running container, please wait..."
singularity run \
-B "$install_dir"/code:/metabomodules_code/ \
"$install_dir"/containers/singularity/image.img > \
"$output"/"$timestamp"__metabomodules__console-output 2>&1
fi
if [ "$container" = "docker" ]
then
# build the docker image (if image already exists, this command does nothing)
echo "Preparing container, please wait..."
sudo docker build -t metabomodules-image "$install_dir"/containers/docker \
> /tmp/docker_build_output 2>&1
checkDockerBuildSuccess
# remove (old) container (if exists)
sudo docker rm -f metabomodules-container > /tmp/docker_rm_output 2>&1
# run (new) container
echo "Running container, please wait..."
sudo docker run --name="metabomodules-container" \
-v "$install_dir"/code:/metabomodules_code/ metabomodules-image > \
"$output"/"$timestamp"__metabomodules__console-output 2>&1
fi
ulimit -s $default_ulimit
end=$(date +%s) # calculate execution time
tottime=$(expr $end - $begin)
echo "" && echo "Exectution took $tottime seconds"
# PREPARE OUTPUT AND CLEAN UP TEMP FILES ##########################################################
output_file="$output"/"$timestamp"__metabomodules__results
mv "$install_dir"/code/output/2* $output_file
if [ -z "$(ls -A $output_file)" ]; then
echo "ERROR: no output was generated. "
echo " see "$output"/"$timestamp"__metabomodules__console-output"
rm -rf $output_file
else
echo "DONE: output can be found in $output"
fi