-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
executable file
·845 lines (709 loc) · 25.6 KB
/
install.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
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#!/usr/bin/env bash
set -euo pipefail
ISSUES_URL="https://github.com/ccdmb/predector/issues"
MAINTAINER="Darcy Jones <[email protected]>"
REPOBASE="https://raw.githubusercontent.com/ccdmb/predector"
DOCUMENTATION_URL="https://github.com/ccdmb/predector/wiki"
### DEFAULT PARAMETERS
VERSION=1.2.7
SIGNALP3= #signalp-3.0.Linux.tar.Z
SIGNALP4= #signalp-4.1g.Linux.tar.gz
SIGNALP5= #signalp-5.0b.Linux.tar.gz
SIGNALP6= #signalp-6.0e.fast.tar.gz
TARGETP2= #targetp-2.0.Linux.tar.gz
DEEPLOC= #deeploc-1.0.All.tar.gz
TMHMM= #tmhmm-2.0c.Linux.tar.gz
PHOBIUS= #phobius101_linux.tar.gz
# Depending on the value of ENVIRONMENT,
# NAME sets the conda environment name, docker tag, or singularity filename
# We set defaults separately
NAME=
CONDA_DEFAULTNAME="predector"
DOCKER_DEFAULTNAME="predector/predector:${VERSION}"
DOCKER_DEFAULTNAME="predector/predector:${VERSION}"
SINGULARITY_DEFAULTNAME="predector.sif"
# Only valid for CONDA, use this path prefix instead of a name.
CONDA_COMMAND="conda"
CONDA_ENV_DIR=
CONDA_TEMPLATE=
# Only valid for Singularity
SINGULARITY_DEFFILE=
# Only docker
DOCKERFILE=
# This sets -x
DEBUG=false
# Required argument
ENVIRONMENT=
### GET COMMAND LINE PARAMETERS
usage() {
echo -e 'USAGE:
$ install.sh [conda|docker|singularity] \\
-3 signalp-3.0.Linux.tar.Z \\
-4 signalp-4.1g.Linux.tar.gz \\
-5 signalp-5.0b.Linux.tar.gz \\
-6 signalp-6.0e.fast.tar.gz \\
-t targetp-2.0.Linux.tar.gz \\
-d deeploc-1.0.All.tar.gz \\
-m tmhmm-2.0c.Linux.tar.gz \\
-p phobius101_linux.tar.gz
Please select only one of conda, docker, or singularity.'
}
usage_err() {
usage
echo -e '
Run "install.sh --help" for extended usage information.'
}
help() {
echo -e "
This script installs the dependencies for the predector pipeline into one
of the supported runtime dependency systems (i.e. conda or a container).
To use the script, you will need:
1. An internet connection and a posix compatible OS.
2. conda, docker, or singularity installed
3. The source files for the proprietary dependencies.
- https://services.healthtech.dtu.dk/services/SignalP-3.0/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/SignalP-4.1/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/SignalP-5.0/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/SignalP-6.0/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/TargetP-2.0/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/DeepLoc-1.0/9-Downloads.php#
- https://services.healthtech.dtu.dk/services/TMHMM-2.0/9-Downloads.php#
- http://software.sbc.su.se/cgi-bin/request.cgi?project=phobius
If your installation of singularity or docker requires sudo to build,
you may need to enter your root password at some point.
We can only support Conda based installations on Linux, if you are running
MacOS, Windows, or Cygwin, this script should fail if you try to install with conda.
Positional arguments:
singularity|conda|mamba|docker -- The environment that you want to install into or build.
Required parameters:
-3|--signalp3 -- The path to the signalp v3 source archive.
-4|--signalp4 -- The path to the signalp v4 source archive.
-5|--signalp5 -- The path to the signalp v5 source archive.
-6|--signalp6 -- The path to the signalp v6 source archive.
-t|--targetp2 -- The path to the signalp v5 source archive.
-d|--deeploc -- The path to the deeploc v1 source archive.
-m|--tmhmm -- The path to the tmhmm v2 source archive.
-p|--phobius -- The path to the phobius v1 source archive.
Optional parameters:
-v|--version -- The version of the pipeline that you want to
setup dependencies for. Note that this may not work in
general, and you're recommended to use the install.sh
script for the targeted version.
Default: '${VERSION}'.
-n|--name -- For conda, sets the environment name (default: '${CONDA_DEFAULTNAME}').
For docker, sets the image tag (default: '${DOCKER_DEFAULTNAME}').
For singularity, sets the output image filename (default: './${SINGULARITY_DEFAULTNAME}').
-c|--conda-prefix -- If set, use this as the location to store the built conda
environment instead of setting a name and using the default
prefix.
--conda-template -- Use this conda environment.yml file instead of downloading it from github.
Only affects conda installs.
--singularity-deffile -- Use this singularity .def file instead of downloading it from github.
Only affects singularity installs.
--dockerfile -- Use this dockerfile instead of downloading it from github.
Only affects docker installs.
Flags:
--debug -- Increased verbosity for developer use.
-h|--help -- Show this message and exit.
If you encounter any issues with this script, please contact the authors at:
- ${MAINTAINER}
- GitHub issues: ${ISSUES_URL}
"
}
check_nodefault_param() {
FLAG="${1}"
PARAM="${2}"
VALUE="${3}"
[ ! -z "${PARAM:-}" ] && (echo "Argument ${FLAG} supplied multiple times" 1>&2; exit 1)
[ -z "${VALUE:-}" ] && (echo "Argument ${FLAG} requires a value" 1>&2; exit 1)
true
}
check_param() {
FLAG="${1}"
VALUE="${2}"
[ -z "${VALUE:-}" ] && (echo "Argument ${FLAG} requires a value" 1>&2; exit 1)
true
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
usage
help
exit 0
;;
-3|--signalp3)
check_param "-3|--signalp3" "${2:-}"
SIGNALP3="$2"
shift # past argument
shift # past value
;;
-4|--signalp4)
check_param "-4|--signalp4" "${2:-}"
SIGNALP4="$2"
shift # past argument
shift # past value
;;
-5|--signalp5)
check_param "-5|--signalp5" "${2:-}"
SIGNALP5="$2"
shift # past argument
shift # past value
;;
-6|--signalp6)
check_param "-6|--signalp6" "${2:-}"
SIGNALP6="$2"
shift # past argument
shift # past value
;;
-t|--targetp2)
check_param "-t|--targetp2" "${2:-}"
TARGETP2="$2"
shift # past argument
shift # past value
;;
-d|--deeploc)
check_param "-d|--deeploc" "${2:-}"
DEEPLOC="$2"
shift # past argument
shift # past value
;;
-m|--tmhmm)
check_param "-m|--tmhmm" "${2:-}"
TMHMM="$2"
shift # past argument
shift # past value
;;
-p|--phobius)
check_param "-p|--phobius" "${2:-}"
PHOBIUS="$2"
shift # past argument
shift # past value
;;
-v|--version)
check_param "-v|--version" "${2:-}"
VERSION="$2"
shift # past argument
shift # past value
;;
-n|--name)
check_nodefault_param "-n|--name" "${NAME:-}" "${2:-}"
NAME="$2"
shift # past argument
shift # past value
;;
-c|--conda-prefix)
check_nodefault_param "-c|--conda-prefix" "${NAME:-}" "${2:-}"
CONDA_ENV_DIR="$2"
shift # past argument
shift # past value
;;
--conda-template)
check_nodefault_param "--conda-template" "${CONDA_TEMPLATE}" "${2:-}"
CONDA_TEMPLATE="$2"
shift
shift
;;
--singularity-deffile)
check_nodefault_param "--singularity-deffile" "${SINGULARITY_DEFFILE}" "${2:-}"
SINGULARITY_DEFFILE="$2"
shift
shift
;;
--dockerfile)
check_nodefault_param "--dockerfile" "${DOCKERFILE}" "${2:-}"
DOCKERFILE="$2"
shift
shift
;;
--debug)
DEBUG=true
shift # past argument
;;
conda|mamba|docker|singularity) # required positional subcommand
if [ ! -z "${ENVIRONMENT:-}" ]
then
echo "You specified to setup both '${ENVIRONMENT}' and '${1}'." 1>&2
echo "We can only setup one at a time." 1>&2
exit 1
fi
ENVIRONMENT="$1"
shift # past argument
;;
*) # unknown option
echo "ERROR: Encountered an unknown parameter '${1:-}'." 1>&2
usage_err
exit 1
;;
esac
done
if [ "${DEBUG:-}" = "true" ]
then
set -x
fi
if [ "${ENVIRONMENT:-}" = "mamba" ]
then
ENVIRONMENT="conda"
CONDA_COMMAND="mamba"
fi
### CHECK USER ARGUMENTS
FAILED=false
[ -z "${SIGNALP3:-}" ] && echo "Please provide the source for signalp3." 1>&2 && FAILED=true
[ -z "${SIGNALP4:-}" ] && echo "Please provide the source for signalp4." 1>&2 && FAILED=true
[ -z "${SIGNALP5:-}" ] && echo "Please provide the source for signalp5." 1>&2 && FAILED=true
# [ -z "${SIGNALP6:-}" ] && echo "Please provide the source for signalp6." 1>&2 && FAILED=true
[ -z "${TARGETP2:-}" ] && echo "Please provide the source for targetp2." 1>&2 && FAILED=true
[ -z "${DEEPLOC:-}" ] && echo "Please provide the source for deeploc." 1>&2 && FAILED=true
[ -z "${TMHMM:-}" ] && echo "Please provide the source for tmhmm." 1>&2 && FAILED=true
[ -z "${PHOBIUS:-}" ] && echo "Please provide the source for phobius." 1>&2 && FAILED=true
[ -z "${ENVIRONMENT:-}" ] && (echo "Please tell us which environment you'd like to install: conda, docker or singularity." 1>&2; FAILED=true)
if [ "${FAILED}" = true ]
then
echo
usage_err
exit 1;
fi
### CHECK THAT THE TARBALLS EXIST
[ ! -f "${SIGNALP3:-}" ] && echo "The specified archive for signalp3 '${SIGNALP3}' does not exist." 1>&2 && FAILED=true
[ ! -f "${SIGNALP4:-}" ] && echo "The specified archive for signalp4 '${SIGNALP4}' does not exist." 1>&2 && FAILED=true
[ ! -f "${SIGNALP5:-}" ] && echo "The specified archive for signalp5 '${SIGNALP5}' does not exist." 1>&2 && FAILED=true
if [ ! -z "${SIGNALP6:-}" ]
then
[ ! -f "${SIGNALP6:-}" ] && echo "The specified archive for signalp6 '${SIGNALP6}' does not exist." 1>&2 && FAILED=true
fi
[ ! -f "${TARGETP2:-}" ] && echo "The specified archive for targetp2 '${TARGETP2}' does not exist." 1>&2 && FAILED=true
[ ! -f "${DEEPLOC:-}" ] && echo "The specified archive for deeploc '${DEEPLOC}' does not exist." 1>&2 && FAILED=true
[ ! -f "${TMHMM:-}" ] && echo "The specified archive for tmhmm '${TMHMM}' does not exist." 1>&2 && FAILED=true
[ ! -f "${PHOBIUS:-}" ] && echo "The specified archive for phobius '${PHOBIUS}' does not exist." 1>&2 && FAILED=true
if [ ! -z "${CONDA_TEMPLATE:-}" ]
then
[ ! -f "${CONDA_TEMPLATE:-}" ] && echo "The specified alternate conda template '${CONDA_TEMPLATE}' does not exist." 1>&2 && FAILED=true
fi
if [ ! -z "${SINGULARITY_DEFFILE:-}" ]
then
[ ! -f "${SINGULARITY_DEFFILE:-}" ] && echo "The specified alternate singularity .def file '${SINGULARITY_DEFFILE}' does not exist." 1>&2 && FAILED=true
fi
if [ ! -z "${DOCKERFILE:-}" ]
then
[ ! -f "${DOCKERFILE:-}" ] && echo "The specified alternate singularity .def file '${DOCKERFILE}' does not exist." 1>&2 && FAILED=true
fi
if [ "${FAILED}" = "true" ]
then
echo 1>&2
echo "Please check that the filename you've provided are correct." 1>&2
echo "Note that the archive must be in it's compressed form rather than as an uncompressed directory." 1>&2
exit 1;
fi
### Warnings
warn_signalp6_not_installed() {
echo
echo "WARNING: SignalP 6 was not installed because you didn't provide the tar-ball."
echo "WARNING: Predector will automatically skip running SignalP 6."
echo "WARNING: You may also like to specify the '--no_signalp6' flag when running the pipeline."
}
### ERROR MESSAGES
proprietary_install_error() {
echo 1>&2
echo "ERROR: One or more of the proprietary package registrations failed." 1>&2
echo "Please read the error message above, and re-run this script if you can resolve it." 1>&2
}
conda_env_create_error() {
# TODO check if it is actually an existing environment.
echo "ERROR: creating the conda environment failed" 1>&2
echo "Usually this happens if you already have an environment with the name or path prefix that we tried to use." 1>&2
echo "You can change the name we use with the '-n' flag, or the path prefix with the '-c' flag." 1>&2
echo "Otherwise you can remove the old environment with:" 1>&2
echo " conda env remove --name ${NAME:-envname}" 1>&2
echo " conda env remove --prefix ${CONDA_ENV_DIR:-path/to/your/env}" 1>&2
echo 1>&2
echo "Please rerun this script when you have fixed this" 1>&2
}
singularity_build_error() {
echo 1>&2
echo "ERROR: creating the singularity image failed" 1>&2
echo "Please read any generated errors above to see if you can resolve it." 1>&2
}
docker_build_error() {
echo 1>&2
echo "ERROR: creating the docker image failed" 1>&2
echo "Please read any generated errors above to see if you can resolve it." 1>&2
}
contact_fix_issue() {
echo "Please look at our documentation and advanced install guide for tips." 1>&2
echo "If you are unable to resolve the issue please contact the authors or create an issue on github." 1>&2
echo "We'll do our best to help you, and make updates to resolve or document the issue." 1>&2
echo 1>&2
echo "Maintainer: ${MAINTAINER}" 1>&2
echo "GitHub Issues: ${ISSUES_URL}" 1>&2
echo "Documentation: ${DOCUMENTATION_URL}" 1>&2
}
check_docker_installed() {
if ! which docker > /dev/null
then
echo "ERROR: Docker doesn't seem to be installed and available on your PATH." 1>&2
echo "Please install docker for your operating system as described here:" 1>&2
echo "- https://docs.docker.com/engine/install/" 1>&2
exit 1;
fi
}
check_singularity_installed() {
if ! which singularity > /dev/null
then
echo "ERROR: singularity doesn't seem to be installed and available on your PATH." 1>&2
echo "Please install the latest singularity v3+ as described in the user guides:" 1>&2
echo "- https://sylabs.io/docs/" 1>&2
exit 1;
fi
}
check_conda_installed() {
if ! which conda > /dev/null
then
echo "ERROR: Conda doesn't seem to be installed and available on your PATH." 1>&2
echo "Please install Miniconda (or anaconda) and follow their instructions." 1>&2
echo "- https://docs.conda.io/en/latest/miniconda.html#linux-installers" 1>&2
echo "- https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html" 1>&2
exit 1;
fi
}
get_env_path() {
NAME="$1"
# Basically we pick out the last column where the first column matches the
# environment name.
# The lines are of one of the following forms (excluding comment lines):
# envname1 /path/to/envs/envname1
# envname2 * /path/to/envs/envname2
# /path/to/custom/path/env
# The * indicates the current environment, so we have to select the last
# column instead of column 2 or 3
# Distros should have at least one of the following tools.
if which awk > /dev/null 2>&1
then
conda info -e | awk -v name="${NAME}" '$1 == name {print $NF}' | head -n 1
elif which sed > /dev/null 2>&1
then
conda info -e | sed -n "/^${NAME}[[:space:]]/s/[^[:space:]]*[[:space:]]*\**[[:space:]]*\([^[:space:]]\)/\\1/p" | head -n1
elif which python3 > /dev/null 2>&1
then
conda info -e \
| python3 -c "
import sys
lines = sys.stdin.readlines()
filtered = (k.strip() for k in lines if not (k.startswith('#') or k.strip() == ''))
extra_filtered = (k for k in filtered if k.split()[0] == '${NAME}')
e = [k.split()[-1] for k in extra_filtered]
e.append('') # Avoid an error here
print(e[0].strip())
"
fi
}
check_is_linux() {
OS=$(uname)
if [ "${OS^^}" != "LINUX" ]
then
echo "ERROR: We can only support conda on linux due to some dependency requirements." 1>&2
echo "If you are running Mac or Windows, we suggest you use a virtual machine, or use the docker or singularity containerised dependencies." 1>&2
exit 1;
fi
}
get_abs_filename() {
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
setup_conda() {
NAME="${NAME:-${CONDA_DEFAULTNAME}}"
URL="${REPOBASE}/${VERSION}/environment.yml"
check_conda_installed
check_is_linux
echo "## Setting up conda environment."
echo
TMPFILE=".predector$$.yml"
if [ -z "${CONDA_TEMPLATE:-}" ]
then
curl -o "${TMPFILE}" -s "${URL}"
CONDA_TEMPLATE_FILE="${TMPFILE}"
else
CONDA_TEMPLATE_FILE="${CONDA_TEMPLATE}"
fi
# This is to allow non-standard environment paths
if [ -z "${CONDA_ENV_DIR:-}" ]
then
"${CONDA_COMMAND:-conda}" env create --name "${NAME}" --file "${CONDA_TEMPLATE_FILE}" || RETCODE="$?"
else
"${CONDA_COMMAND:-conda}" env create --prefix "${CONDA_ENV_DIR}" --file "${CONDA_TEMPLATE_FILE}" || RETCODE="$?"
fi
if [ ! -z "${CONDA_TEMPLATE:-}" ]
then
rm -f "${TMPFILE}"
fi
if [ "${RETCODE:-0}" -ne 0 ]
then
conda_env_create_error
contact_fix_issue
exit "${RETCODE}";
fi
set +u
eval "$(conda shell.bash hook)"
if [ -z "${CONDA_ENV_DIR:-}" ]
then
conda activate "${NAME}"
else
conda activate "${CONDA_ENV_DIR}"
fi
set -u
echo
echo "## Finished creating the base environment"
echo "Registering the proprietary software."
echo
signalp3-register "${SIGNALP3}" && echo \
&& signalp4-register "${SIGNALP4}" && echo \
&& signalp5-register "${SIGNALP5}" && echo \
&& targetp2-register "${TARGETP2}" && echo \
&& deeploc-register "${DEEPLOC}" && echo \
&& phobius-register "${PHOBIUS}" && echo \
&& tmhmm2-register "${TMHMM}" && echo \
|| RETCODE="$?"
if [ "${RETCODE:-0}" -ne 0 ]
then
proprietary_install_error
contact_fix_issue
exit "${RETCODE:-1}";
fi
if [ ! -z "${SIGNALP6:-}" ]
then
signalp6-register "${SIGNALP6}" || RETCODE="$?"
fi
if [ "${RETCODE:-0}" -ne 0 ]
then
proprietary_install_error
contact_fix_issue
exit "${RETCODE:-1}";
fi
echo "The predector conda environment has been successfully installed."
if [ -z "${CONDA_ENV_DIR:-}" ]
then
CONDA_PREFIX="$(get_env_path "${NAME}")"
else
CONDA_PREFIX="$(get_abs_filename "${CONDA_ENV_DIR}")"
fi
if [ -z "${SIGNALP6:-}" ]
then
warn_signalp6_not_installed
echo
fi
if [ ! -z "${CONDA_PREFIX:-}" ]
then
echo "When you run the pipeline, please supply the parameter:"
echo " '-with-conda \"${CONDA_PREFIX}\"'"
echo
echo "You can test the pipeline on this computer now with:"
echo " 'nextflow run -profile test -with-conda \"${CONDA_PREFIX}\" -resume -r ${VERSION} ccdmb/predector'"
fi
}
check_docker_needs_sudo() {
MSG=$(docker images 2>&1) || RETCODE="$?"
if [ "${RETCODE:-0}" -ne "0" ]
then
if grep '^Got permission denied' <(echo "${MSG}") > /dev/null 2>&1
then
echo "true"
else
echo 1>&2
echo "Got unexpected error while testing your docker install with 'docker images'." 1>&2
echo "${MSG}" 1>&2
echo 1>&2
echo "Please try to resolve this issue and try running the script again." 1>&2
exit "${RETCODE}";
fi
else
echo "false"
fi
}
setup_docker() {
URL="${REPOBASE}/${VERSION}/Dockerfile"
NAME="${NAME:-${DOCKER_DEFAULTNAME}}"
check_docker_installed
echo "## Setting up docker image."
echo
# This will still fail if non-zero exit not related to permission.
NEED_SUDO=$(check_docker_needs_sudo)
if [ "${NEED_SUDO}" = "true" ]
then
echo "Your docker installation appears to require root permission."
echo "Please provide your root password for sudo when prompted."
echo
SUDO="sudo"
else
SUDO=""
fi
if [ ! -z "${SIGNALP6:-}" ]
then
SP6_FLAG=( "--build-arg" SIGNALP6="${SIGNALP6:-}" )
else
SP6_FLAG=()
fi
TMPFILE=".predector$$.Dockerfile"
if [ -z "${DOCKERFILE:-}" ]
then
curl -o "${TMPFILE}" -s "${URL}"
DOCKERFILE_FILE="${TMPFILE}"
else
DOCKERFILE_FILE="${DOCKERFILE}"
fi
${SUDO} docker build \
--build-arg SIGNALP3="${SIGNALP3}" \
--build-arg SIGNALP4="${SIGNALP4}" \
--build-arg SIGNALP5="${SIGNALP5}" \
--build-arg TARGETP2="${TARGETP2}" \
"${SP6_FLAG[@]}" \
--build-arg PHOBIUS="${PHOBIUS}" \
--build-arg TMHMM="${TMHMM}" \
--build-arg DEEPLOC="${DEEPLOC}" \
--tag "${NAME}" \
--file "${DOCKERFILE_FILE}" \
. \
|| RETCODE="$?"
if [ -z "${DOCKERFILE:-}" ]
then
rm -f "${TMPFILE}"
fi
if [ "${RETCODE:-0}" -ne 0 ]
then
docker_build_error
contact_fix_issue
exit "${RETCODE:-0}";
fi
echo
echo "The predector docker image has been successfully built."
echo "It should show in 'docker images' as '${NAME}'."
echo
if [ -z "${SIGNALP6:-}" ]
then
warn_signalp6_not_installed
echo
fi
if [ "${NEED_SUDO}" = "true" ]
then
SUDO_MSG="Your docker installation seems to require sudo to run."
else
SUDO_MSG=""
fi
if [ "${NAME}" = "${DOCKER_DEFAULTNAME}" ]
then
echo "When you run the pipeline, please use one of the following profiles:"
echo " '-profile docker'"
echo " '-profile docker_sudo'"
echo
if [ "${NEED_SUDO}" = "true" ]
then
echo "Your installation docker seems to require sudo to run."
echo "Please use the 'docker_sudo' profile if you're running on this computer."
echo
echo "You can test the pipeline now with:"
echo " 'nextflow run -profile test,docker_sudo -resume -r ${VERSION} ccdmb/predector'"
else
echo "Your installation of docker doesn't seem to require sudo to run."
echo "Please use the 'docker' profile if you're running on this computer."
echo
echo "You can test the pipeline now with:"
echo " 'nextflow run -profile test,docker -resume -r ${VERSION} ccdmb/predector'"
fi
else
echo "When you run the pipeline, please use the parameter:"
echo " '-with-docker \"${NAME}\"'"
echo
if [ "${NEED_SUDO}" = "true" ]
then
echo "Your installation of docker seems to require sudo to run."
echo "Please also use the 'docker_sudo' profile if you're running on this computer."
echo " '-profile docker_sudo'"
echo
echo "You can test the pipeline now with:"
echo " 'nextflow run -profile test,docker_sudo -with-docker \"${NAME}\" -resume -r ${VERSION} ccdmb/predector'"
else
echo "Your installation of docker doesn't seem to require sudo to run."
echo ""
echo "If you're running on a different computer that requires sudo for docker,"
echo "please also use the 'docker_sudo' profile."
echo " '-profile docker_sudo'"
echo
echo "You can test the pipeline on this computer now with:"
echo " 'nextflow run -profile test -with-docker \"${NAME}\" -resume -r ${VERSION} ccdmb/predector'"
fi
fi
}
setup_singularity() {
URL="${REPOBASE}/${VERSION}/singularity.def"
NAME="${NAME:-${SINGULARITY_DEFAULTNAME}}"
check_singularity_installed
echo "## Setting up singularity image."
echo
# This is used to emulate the --build-args functionality of docker.
# Singularity lacks this feature. You can unset the variables after you're done.
export SIGNALP3="${SIGNALP3}"
export SIGNALP4="${SIGNALP4}"
export SIGNALP5="${SIGNALP5}"
export SIGNALP6="${SIGNALP6:-}"
export TARGETP2="${TARGETP2}"
export PHOBIUS="${PHOBIUS}"
export TMHMM="${TMHMM}"
export DEEPLOC="${DEEPLOC}"
# We set this so that the /tmp doesn't fill up.
export SINGULARITY_CACHEDIR="${PWD}/.cache$$"
export SINGULARITY_TMPDIR="${SINGULARITY_CACHEDIR}"
export SINGULARITY_LOCALCACHEDIR="${SINGULARITY_CACHEDIR}"
mkdir -p "${SINGULARITY_CACHEDIR}"
# Set the output container filename with the default if user didn't specify.
export NAME
# Download the .def file
export TMPFILE=".predector$$.def"
if [ -z "${SINGULARITY_DEFFILE:-}" ]
then
curl -s -o "${TMPFILE}" "${URL}"
else
# This is necessary because singularity doesn't look
# in the local docker registry by default
sed '/^bootstrap:/s/docker[[:space:]]*$/docker-daemon/' "${SINGULARITY_DEFFILE}" > "${TMPFILE}"
fi
export SINGULARITY_DEFFILE_FILE="${TMPFILE}"
# Build the .sif singularity image.
# Note that `sudo -E` is important, it tells sudo to keep the environment variables
# that we just set.
sudo -E bash -eu -c '
singularity build "${NAME}" "${SINGULARITY_DEFFILE_FILE}" || RETCODE="$?"
rm -rf -- "${SINGULARITY_CACHEDIR}"
exit "${RETCODE:-0}"
' || RETCODE="$?"
rm -f "${TMPFILE}"
if [ "${RETCODE:-0}" -ne 0 ]
then
singularity_build_error
contact_fix_issue
exit "${RETCODE}";
fi
echo "The predector singularity image has been successfully built."
echo
if [ -z "${SIGNALP6:-}" ]
then
warn_signalp6_not_installed
fi
echo "When you run the pipeline, please supply the parameter:"
echo " '-with-singularity \"${NAME}\"'"
echo
echo "You can test the pipeline now with:"
echo " 'nextflow run -profile test -with-singularity \"${NAME}\" -resume -r ${VERSION} ccdmb/predector'"
}
if [ "${ENVIRONMENT}" = "conda" ]
then
setup_conda
elif [ "${ENVIRONMENT}" = "docker" ]
then
setup_docker
elif [ "${ENVIRONMENT}" = "singularity" ]
then
setup_singularity
else
echo "We somehow are trying to setup an environment other than conda, docker or singularity." 1>&2
echo "Please contact the authors to report this issue." 1>&2
exit 1;
fi