-
Notifications
You must be signed in to change notification settings - Fork 17
/
dfam-tetools.sh
executable file
·135 lines (117 loc) · 2.9 KB
/
dfam-tetools.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
#!/bin/sh
# Dfam TE Tools container wrapper script.
# See https://github.com/Dfam-consortium/TETools for more information
# about the Dfam TE Tools container.
set -eu
die() {
printf "%s\n" "$*" >&2
exit 1
}
usage() {
printf "%s\n" "Usage: dfam-tetools.sh [-h|--help]
[--container=/path/to/dfam-tetools.sif | --container=dfam/tetools:tag]
[--docker | --singularity]
[--library]
[-- command [arg1 [arg2 [...]]]]
--container Choose a specific container to use (a .sif file or a docker image ID or tag)
--docker Run the container via docker
--singularity Run the container via singularity
--library A directory containing modified RepeatMasker/Libraries files
command A command to run in the container instead of an interactive shell
If neither --docker nor --singularity is specified and both
programs are available, singularity is preferred."
}
## Parse command-line arguments ##
container="dfam/tetools:1.89.2"
use_docker=0
use_singularity=0
use_lib=0
workdir=""
bind_cmd=""
while [ $# -ge 1 ]; do
opt="$1"
shift
case "$opt" in
--)
break
;;
--*=*)
# Normalize "--x=y" format to "--x" "y" and try again
set -- "${opt%%=*}" "${opt#*=}" "$@"
;;
--container)
container="$1"
shift
;;
-h|--help)
usage >&2
exit 0
;;
--trf_prgm)
echo "Notice: Since Dfam TE Tools 1.2, TRF is included in the container.
The --trf_prgm parameter was ignored." >&2
shift
;;
--docker)
use_docker=1
;;
--singularity)
use_singularity=1
;;
--library)
use_lib=1
workdir="$1"
shift
;;
*)
die "Unrecognized argument: $opt
A command to run in the container must be preceded by a --"
;;
esac
done
## Check argument validity ##
# Ensure exactly one of docker or singularity is used
case $(( use_docker + use_singularity )) in
0) if command -v singularity >/dev/null 2>&1; then
use_singularity=1
elif command -v docker >/dev/null 2>&1; then
use_docker=1
else
die "Error: This script requires singularity or docker to be installed and available in PATH."
fi;;
1) ;;
*) die "Only one of --docker or --singularity can be specified.";;
esac
# Ensure the container name makes sense
if [ "$use_singularity" = 1 ] && ! [ -e "$container" ]; then
# If a file named "$container" does not exist,
# we assume that "container" is a docker image reference.
# Singularity uses docker:// syntax for these
container="docker://$container"
fi
## Run the container ##
if [ "$use_docker" = 1 ]; then
if [ "$use_lib" = 1 ]; then
bind_cmd="--mount type=bind,source=$workdir,target=/opt/RepeatMasker/Libraries"
fi
docker run -it --rm \
--init \
$bind_cmd \
--user "$(id -u):$(id -g)" \
--workdir "/opt" \
"$container" \
"$@"
elif [ "$use_singularity" = 1 ]; then
if [ "$use_lib" = 1 ]; then
bind_cmd="-B $workdir:/opt/RepeatMasker/Libraries"
fi
if [ $# -eq 0 ]; then
set -- "/bin/bash"
fi
export LANG=C
singularity exec \
$bind_cmd \
"$container" \
"$@"
fi
# vi: noet ts=8 sw=0 sts=-1