-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheckinstall
executable file
·503 lines (439 loc) · 17.8 KB
/
checkinstall
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#!/usr/bin/env bash
#
# PEPPRO pipeline installation check
#
if [ $# -gt 0 ] ; then
echo "Usage: checkinstall"
exit 1
fi
set -o pipefail
# set -e
echo -e "-----------------------------------------------------------"
echo -e " "
echo -e " PEPPRO installation check "
echo -e " "
echo -e "-----------------------------------------------------------"
################################################################################
# Helpful functions
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
is_executable() {
if [ -x "$(command -v $1)" ]; then
return 0
else
return 1
fi
}
pip_show() {
if pip show -q $1; then
return 0
else
return 1
fi
}
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
fail() {
printf "${RED}\u2716 $@${NC}\n"
}
success() {
printf "${GREEN}\xE2\x9C\x94 $@${NC}\n"
}
warn() {
printf "${YELLOW}\u26A0 $@${NC}\n"
}
################################################################################
echo -e "Checking base requirements... "
BASE_REQS=0
declare -a requiredPkgs=("looper")
for package in ${requiredPkgs[@]}; do
if ! pip_show $package; then
echo $(fail "ERROR: PEPPRO requires the Python package, $package. Try pip install $package.")
printf "\n"
exit 1
fi
done
if [ $BASE_REQS -eq 0 ]; then
echo $(success "SUCCESS: Minimum requirements met.")
fi
################################################################################
echo -e "-----------------------------------------------------------"
echo -e "Checking native installation... "
NATIVE_INSTALL=0
# Check Python
if ! is_executable "python"; then
echo $(warn "WARNING: PEPPRO requires python 3.0 or greater. Install python and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
else
ver=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
if [ "$ver" -lt "30" ]; then
echo $(warn "WARNING: PEPPRO requires python 3.0 or greater. Update python and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
fi
fi
# Check Python packages
if ! is_executable "pip"; then
echo $(warn "WARNING: Please install pip and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
fi
if [ -f "requirements.txt" ]; then
REQS="requirements.txt"
else
curl https://raw.githubusercontent.com/databio/peppro/master/requirements.txt --silent --output requirements.txt && mv requirements.txt curl_requirements.txt
REQS="curl_requirements.txt"
fi
while IFS= read -r line; do
[ "${line:0:1}" = "#" ] && continue
IFS='>=' read -r -a array <<< "$line"
package=${array[0]}
required=${array[2]}
required=$(trim ${required})
IFS='.' read -r -a required_version <<< "$required"
declare -i rmajor
declare -i rminor
declare -i rpatch
rmajor=$(echo "${required_version[0]}" | awk '{ print $1+0; exit }')
rminor=$(echo "${required_version[1]}" | awk '{ print $1+0; exit }')
rpatch=$(echo "${required_version[2]}" | awk '{ print $1+0; exit }')
if ! pip_show "${package}"; then
echo $(warn "WARNING: PEPPRO requires the Python package, $package, >= $required. Try pip install $package and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
else
if [ $package == "cutadapt" ]; then
installed=$(cutadapt --version)
installed=$(trim ${installed})
else
installed=$(pip show ${package} | grep -iw 'Version' | awk -F':' '{print $2}' | tr -d '\n')
installed=$(trim ${installed})
fi
IFS='.' read -r -a installed_version <<< "$installed"
declare -i imajor
declare -i iminor
declare -i ipatch
imajor=$(echo "${installed_version[0]}" | awk '{ print $1+0; exit }')
iminor=$(echo "${installed_version[1]}" | awk '{ print $1+0; exit }')
ipatch=$(echo "${installed_version[2]}" | awk '{ print $1+0; exit }')
if ! [ -z "$required" ]; then
if [ $imajor -lt $rmajor ]; then
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
elif [ $imajor -eq $rmajor ] && [ $iminor -lt $rminor ]; then
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
elif [ $imajor -eq $rmajor ] && [ $iminor -eq $rminor ] && [ $ipatch -lt $rpatch ]; then
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
BULKER_INSTALL=1
else
echo -e $(success "SUCCESS: Python package ${package}\trequired: ${required}\tinstalled: ${installed}")
fi
else
echo -e $(success "SUCCESS: Python package ${package}\trequired: any\tinstalled: ${installed_version}")
fi
fi
done < $REQS
if [ -f "curl_requirements.txt" ]; then
rm "curl_requirements.txt"
fi
# Check tool installation
declare -a requiredCommands=("perl" "awk" "grep" "sed" "bedtools" "bigWigCat" "wigToBigWig" "bowtie2" "fastp" "fastq_pair" "flash" "preseq" "samtools" "seqtk" "seqkit" "Rscript")
for cmd in ${requiredCommands[@]}; do
if ! is_executable $cmd; then
echo $(warn "WARNING: Install $cmd and checkinstall again.")
# printf "\n"
NATIVE_INSTALL=1
else
echo -e $(success "SUCCESS: ${cmd}")
fi
done
## Check R packages
if ! is_executable "R"; then
echo $(warn "WARNING: PEPPRO requires R 3.5 or greater. Install R and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
else
rVer=$(R --version 2>&1 | grep 'R version' | awk '{print $3}')
rVer=$(echo "${rVer//.}")
if [ "$rVer" -lt "350" ]; then
echo $(warn "WARNING: Please update R to >=3.5 and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
fi
fi
declare -a requiredRPackages=("argparser" "optigrab" "devtools" "GenomicDistributions" "GenomicDistributionsData" "R.utils" "PEPPROr" "data.table" "pepr" "gplots" "grid" "ggplot2" "scales" "IRanges" "GenomicRanges")
for package in ${requiredRPackages[@]}; do
cmd=$(echo "Rscript -e 'library(\"$package\")'")
packageInstalled=$(eval $cmd 2>&1)
if [[ "$packageInstalled" == *Error* ]]; then
echo $(warn "WARNING: Please install the R package, $package, and checkinstall again.")
printf "\n"
NATIVE_INSTALL=1
else
echo -e $(success "SUCCESS: R package: ${package}")
fi
done
################################################################################
echo -e "-----------------------------------------------------------"
echo -e "Checking conda installation... "
CONDA_INSTALL=0
if ! is_executable "conda"; then
echo $(warn "WARNING: Install conda to use conda environments and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
eval "$(conda shell.bash hook)"
conda activate peppro
unset PYTHONPATH
unset R_LIBS
# Check Python
if ! is_executable "python"; then
echo $(warn "WARNING: PEPPRO requires python 3.0 or greater. Install python and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
#echo "which python: $(which python)"
ver=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
if [ "$ver" -lt "30" ]; then
echo $(warn "WARNING: PEPPRO requires python 3.0 or greater. Update python and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
fi
fi
# Check Python packages
if ! is_executable "pip"; then
echo $(warn "WARNING: PEPPRO requires pip. Please install pip and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
fi
if [ -f "requirements.txt" ]; then
REQS="requirements.txt"
else
curl https://raw.githubusercontent.com/databio/peppro/master/requirements.txt --silent --output curl_requirements.txt && mv requirements.txt curl_requirements.txt
REQS="curl_requirements.txt"
fi
while IFS= read -r line; do
[ "${line:0:1}" = "#" ] && continue
IFS='>=' read -r -a array <<< "$line"
package=${array[0]}
required=${array[2]}
required=$(trim ${required})
IFS='.' read -r -a required_version <<< "$required"
declare -i rmajor
declare -i rminor
declare -i rpatch
rmajor=$(echo "${required_version[0]}" | awk '{ print $1+0; exit }')
rminor=$(echo "${required_version[1]}" | awk '{ print $1+0; exit }')
rpatch=$(echo "${required_version[2]}" | awk '{ print $1+0; exit }')
if ! pip_show "${package}"; then
echo $(warn "WARNING: PEPPRO requires the Python package, $package, >= $required. Try pip install $package and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
if [ $package == "cutadapt" ]; then
installed=$(cutadapt --version)
installed=$(trim ${installed})
else
installed=$(pip show ${package} | grep -iw 'Version' | awk -F':' '{print $2}' | tr -d '\n')
installed=$(trim ${installed})
fi
IFS='.' read -r -a installed_version <<< "$installed"
declare -i imajor
declare -i iminor
declare -i ipatch
imajor=$(echo "${installed_version[0]}" | awk '{ print $1+0; exit }')
iminor=$(echo "${installed_version[1]}" | awk '{ print $1+0; exit }')
ipatch=$(echo "${installed_version[2]}" | awk '{ print $1+0; exit }')
if ! [ -z "$required" ]; then
if [ $imajor -lt $rmajor ]; then
#echo -e "Installed major: ${imajor}\tRequired major: ${rmajor}"
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
elif [ $imajor -eq $rmajor ] && [ $iminor -lt $rminor ]; then
#echo -e "Installed minor: ${iminor}\tRequired minor: ${rminor}"
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
elif [ $imajor -eq $rmajor ] && [ $iminor -eq $rminor ] && [ $ipatch -lt $rpatch ]; then
#echo -e "Installed patch: ${ipatch}\tRequired patch: ${rpatch}"
echo $(warn "WARNING: PEPPRO requires the python package, $package, >= $required. Try pip install --upgrade $package and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
echo -e $(success "SUCCESS: Python package ${package}\trequired: ${required}\tinstalled: ${installed}")
fi
else
echo -e $(success "SUCCESS: Python package ${package}\trequired: any\tinstalled: ${installed_version}")
fi
fi
done < $REQS
if [ -f "curl_requirements.txt" ]; then
rm "curl_requirements.txt"
fi
# Check tool installation
declare -a requiredCommands=("perl" "awk" "grep" "sed" "bedtools" "bigWigCat" "wigToBigWig" "bowtie2" "fastp" "fastq_pair" "flash" "preseq" "samtools" "seqtk" "seqkit" "Rscript")
for cmd in ${requiredCommands[@]}; do
if ! is_executable $cmd; then
echo $(warn "WARNING: Please install $cmd and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
echo -e $(success "SUCCESS: ${cmd}")
fi
done
## Check R packages
if ! is_executable "R"; then
echo $(warn "WARNING: PEPPRO requires R 3.5 or greater.\n Please install R>=3.5 and checkinstall again.")
printf "\n"
exit 1
else
rVer=$(R --version 2>&1 | grep 'R version' | awk '{print $3}')
rVer=$(echo "${rVer//.}")
if [ "$rVer" -lt "350" ]; then
echo $(warn "WARNING: PEPPRO requires R 3.5 or greater. Update R and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
fi
fi
declare -a requiredRPackages=("optigrab" "devtools" "argparser" "R.utils" "GenomicDistributions" "GenomicDistributionsData" "PEPPROr" "data.table" "pepr" "gplots" "grid" "ggplot2" "scales" "IRanges" "GenomicRanges")
for package in ${requiredRPackages[@]}; do
cmd=$(echo "Rscript -e 'library(\"$package\")'")
packageInstalled=$(eval $cmd 2>&1)
if [[ "$packageInstalled" == *Error* ]]; then
echo $(warn "WARNING: Please install the R package, $package, and checkinstall again.")
printf "\n"
CONDA_INSTALL=1
else
echo -e $(success "SUCCESS: R package: ${package}")
fi
done
conda deactivate
fi
################################################################################
echo -e "-----------------------------------------------------------"
echo -e "Checking bulker installation... "
BULKER_INSTALL=0
if ! is_executable "docker"; then
DOCKER=1
else
DOCKER=0
fi
if ! is_executable "singularity"; then
SINGULARITY=1
else
SINGULARITY=0
fi
if [ "$DOCKER" -eq 0 ]; then
CMD_CHECK=$(docker --help)
if [ $? -eq 0 ]; then
echo -e $(success "SUCCESS: docker.")
else
echo -e $(warn "WARNING: Docker is a recognized command, but does not appear to be active. Please ensure docker is running and checkinstall again.")
DOCKER=1
fi
fi
if [ "$SINGULARITY" -eq 0 ]; then
echo -e $(success "SUCCESS: singularity.")
fi
if [ "$DOCKER" -eq 1 ] && [ "$SINGULARITY" -eq 1 ]; then
echo -e $(fail "ERROR: bulker")
BULKER_INSTALL=1
else
if ! is_executable "bulker"; then
echo $(warn "WARNING: To use bulker, pip install bulker and checkinstall again.")
printf "\n"
BULKER_INSTALL=1
else
BULKER_INSTALL=0
echo -e $(success "SUCCESS: bulker")
fi
CWD=$(pwd)
if [ -f "sample_pipeline_interface.yaml" ]; then
IFACE="sample_pipeline_interface.yaml"
CRATE=$(cat $IFACE | grep 'bulker_crate' | tr " " "\n" | tail -n 1)
else
curl https://raw.githubusercontent.com/databio/peppro/master/sample_pipeline_interface.yaml --silent --output sample_pipeline_interface.yaml && mv sample_pipeline_interface.yaml curl_sample_pipeline_interface.yaml
IFACE="$CWD/curl_sample_pipeline_interface.yaml"
CRATE=$(echo $IFACE | tr " " "\n" | grep -A1 'bulker_crate' | tail -n 1)
rm "$IFACE"
fi
yes n | bulker load $CRATE
if [ $? -eq 0 ]; then
echo $(warn "WARNING: Could not bulker load ${CRATE}. Check out https://bulker.databio.org/en/latest/install/.")
printf "\n"
BULKER_INSTALL=1
fi
if [ -f "$CWD/pipelines/peppro.py" ]; then
PIPELINE="$CWD/pipelines/peppro.py"
else
curl https://raw.githubusercontent.com/databio/peppro/master/pipelines/peppro.py --silent --output peppro.py && mv peppro.py curl_peppro.py
PIPELINE="$CWD/curl_peppro.py"
fi
CMD_CHECK=$(bulker run ${CRATE} $PIPELINE --help)
EXIT_CODE=$(echo $?)
isActivatable=$(echo "${EXIT_CODE}" | awk '{ print $1+0; exit }')
if [ "$isActivatable" -eq 0 ]; then
BULKER_INSTALL=0
echo -e $(success "SUCCESS: bulker run ${CRATE}")
else
echo $(warn "WARNING: Could not activate the bulker crate, ${CRATE}. Check out https://bulker.databio.org/en/latest/install/.")
printf "\n"
BULKER_INSTALL=1
fi
if [ -f "$CWD/curl_peppro.py" ]; then
rm "$CWD/curl_peppro.py"
fi
fi
################################################################################
echo -e "-----------------------------------------------------------"
echo -e " PEPPRO checkinstall results "
if [ "$NATIVE_INSTALL" -eq 0 ]; then
echo -e $(success "SUCCESS: PEPPRO can be run using native installations!")
else
echo -e $(fail "ERROR: PEPPRO cannot be run using native installations.")
fi
if [ "$CONDA_INSTALL" -eq 0 ]; then
echo -e $(success "SUCCESS: PEPPRO can be run using conda installation!")
else
echo -e $(fail "ERROR: PEPPRO cannot be run via conda.")
fi
if [ "$DOCKER" -eq 0 ]; then
echo -e $(success "SUCCESS: PEPPRO can be run using docker!")
else
echo -e $(fail "ERROR: PEPPRO cannot be run using docker.")
fi
if [ "$SINGULARITY" -eq 0 ]; then
echo -e $(success "SUCCESS: PEPPRO can be run using singularity!")
else
echo -e $(fail "ERROR: PEPPRO cannot be run using singularity.")
fi
if [ "$BULKER_INSTALL" -eq 0 ]; then
echo -e $(success "SUCCESS: PEPPRO can be run using bulker!")
else
echo -e $(fail "ERROR: PEPPRO cannot be run using bulker.")
fi
if [ "$NATIVE_INSTALL" -eq 1 ] && [ "$CONDA_INSTALL" -eq 1 ] && [ "$BULKER_INSTALL" -eq 1 ]; then
echo -e "ERROR: PEPPRO is not successfully installed. Check the above output for direction on missing tools or packages."
fi
echo -e "-----------------------------------------------------------"