-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnextflow
executable file
·314 lines (283 loc) · 9.25 KB
/
nextflow
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
#!/bin/bash
#
# Copyright (c) 2013-2015, Centre for Genomic Regulation (CRG).
# Copyright (c) 2013-2015, Paolo Di Tommaso and the respective authors.
#
# This file is part of Nextflow.
#
# Nextflow 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.
#
# Nextflow 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.
#
# You should have received a copy of the GNU General Public License
# along with Nextflow. If not, see <http://www.gnu.org/licenses/>.
if [[ $TERM && $TERM != 'dumb' ]]; then
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
NORMAL=$(tput sgr0)
fi
function echo_red() {
echo -e "$RED$*$NORMAL"
}
function echo_green() {
echo -e "$GREEN$*$NORMAL"
}
function echo_yellow() {
echo -e "$YELLOW$*$NORMAL"
}
function die() {
echo_red "$*"
exit 1
}
get_abs_filename() {
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}
function get() {
if command -v wget &>/dev/null; then
GET="wget -q $1 -O $2"
elif command -v curl &>/dev/null; then
GET="curl -fsSL $1 -o $2"
else
echo_red "Error: cannot find 'curl' nor 'wget' utility -- please install one of them"
exit 1
fi
printf "Downloading nextflow dependencies. It may require some seconds, please wait .. "
$GET; status=$?
printf "\r\033[K"
if [ $status -ne 0 ]; then
echo_red "Error: cannot download nextflow required file -- make sure you can connect the internet"
echo ""
echo "Alternatively you can download the file:"
echo " $1"
echo ""
echo "And save it as:"
echo " ${3:-$2}"
echo ""
exit 1
fi
}
function install() {
if [ "$(uname)" = 'Darwin' ]; then tmpfile=$(mktemp $PWD/XXXXX) || exit $?
else tmpfile=$(mktemp -t XXXXX -p $PWD) || exit $?
fi
get "http://www.nextflow.io/releases/latest/nextflow" "$tmpfile" "$1" || exit $?
mv $tmpfile $1 || exit $?
chmod +x $1 || exit $?
bash $1 -download || exit $?
echo ''
echo -e $'Nextflow installation completed. Please note:'
echo -e $'- the executable file \'nextflow\' has been created in the folder:' $(dirname $1)
echo -e $'- you may complete the installation copying it to directory in your $PATH'
echo ''
}
function launch_nextflow() {
# the launch command line
local cmdline="${launcher[@]} ${args[@]}"
# start in daemon mode
if [[ "$bg" ]]; then
local pid_file="${NXF_PID_FILE:-.nextflow.pid}"
bash -c "exec $cmdline" &
disown
printf $! > "$pid_file"
exit 0
fi
# trampoline syntax -- https://github.com/puniverse/capsule/pull/71
exec bash -c "exec $cmdline"
exit 1
}
# check self-install
if [ "$0" = "bash" ] || [ "$0" = "/bin/bash" ]; then
if [ -d nextflow ]; then
echo 'Please note:'
echo "- The install procedure needs to create a file named 'nextflow' in this folder, but a directory with this name already exists."
echo "- Please renamed/delete that directory, or execute the Nextflow install procedure in another folder."
echo ''
exit 1
fi
install "$PWD/nextflow"
exit 0
fi
NXF_HOME=${NXF_HOME:-$HOME/.nextflow}
NXF_VER=${NXF_VER:-'0.15.6'}
NXF_ORG=${NXF_ORG:-'nextflow-io'}
NXF_ASSETS=${NXF_ASSETS:-$NXF_HOME/assets}
NXF_CLI="$0 $@"
export NXF_CLI
export NXF_ORG
export NXF_HOME
# Check if it is required to run in background
bg=''
declare -a jvmopts=()
declare -a args=("$@")
declare -a cli=(clone config drop help history info ls pull run view node console)
cmd=''
while [[ $# != 0 ]]; do
case $1 in
-D*)
if [[ ! "$cmd" ]]; then
jvmopts+=("$1")
fi
;;
-bg)
bg=1
;;
-download)
if [[ ! "$cmd" ]]; then
rm -rf $NXF_HOME/framework/$NXF_VER || exit $?
$0 -version || exit $?
exit 0
fi
;;
-self-update|self-update)
if [[ ! "$cmd" ]]; then
install $0;
exit 0
fi
;;
-process.executor|-executor.name)
if [[ $2 && $2 == 'gridgain' ]]; then
NXF_MODE='gridgain'; shift;
fi
;;
-with-extrae)
export EXTRAE_CONFIG_FILE=${EXTRAE_CONFIG_FILE:-$NXF_HOME/extrae/config}
rm -f TRACE.*
rm -rf set-0
;;
-with-drmaa)
if [[ $2 && $2 != -* ]];
then NXF_DRMAA=$2; shift;
else NXF_DRMAA='us.levk:drmaa-gridengine:6.2u5'; fi
;;
*)
[[ $1 && $1 != -* && ! "$cmd" && ${cli[*]} =~ $1 ]] && cmd=$1
;;
esac
shift
done
CAPSULE_LOG=${CAPSULE_LOG:=''}
CAPSULE_RESET=${CAPSULE_RESET:=''}
CAPSULE_CACHE_DIR=${CAPSULE_CACHE_DIR:="$NXF_HOME/capsule"}
NXF_PACK=one
NXF_MODE=${NXF_MODE:-''}
NXF_JAR=${NXF_JAR:-nextflow-$NXF_VER-$NXF_PACK.jar}
NXF_BIN=${NXF_BIN:-$NXF_HOME/framework/$NXF_VER/$NXF_JAR}
NXF_BASE=${NXF_BASE:-http://www.nextflow.io/releases}
NXF_PATH=$(dirname "$NXF_BIN")
NXF_URL=${NXF_URL:-$NXF_BASE/v$NXF_VER/$NXF_JAR}
NXF_GRAB=${NXF_GRAB:-''}
NXF_CLASSPATH=${NXF_CLASSPATH:-''}
NXF_LAUNCHER=${NXF_HOME}/tmp/launcher/nextflow-${NXF_PACK}_${NXF_VER}
# Determine the path to this file
if [[ $NXF_PACK = 'all' ]]; then
NXF_BIN=$(which "$0" 2>/dev/null)
[ $? -gt 0 -a -f "$0" ] && NXF_BIN="./$0"
fi
# Determine the Java command to use to start the JVM.
if [ ! -x "$JAVA_CMD" ] ; then
if [ -d "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVA_CMD="$JAVA_HOME/jre/sh/java"
else
JAVA_CMD="$JAVA_HOME/bin/java"
fi
elif [ -x /usr/libexec/java_home ]; then
JAVA_CMD="$(/usr/libexec/java_home -v 1.7+)/bin/java"
else
JAVA_CMD="$(which java)"
fi
fi
# Verify installed Java version
if [ ! -d "$NXF_LAUNCHER" ]; then # <-- only the first time
$JAVA_CMD -version 2>&1 | awk '/version/ {print $3}' | grep '"1\.[7|8]\..*"' > /dev/null
if [ $? -ne 0 ]; then
echo_red "Error: cannot find Java or it's a wrong version -- please make sure that Java 7 or higher it's installed"
echo_red "Note: Nextflow is trying to use the Java VM defined by the following environment variables:\n JAVA_CMD: $JAVA_CMD\n JAVA_HOME: $JAVA_HOME\n"
exit 1
fi
fi
# Verify nextflow jar is available
if [ ! -f "$NXF_BIN" ]; then
[ -f "$NXF_PATH" ] && rm "$NXF_PATH"
mkdir -p $NXF_PATH || exit $?
get "$NXF_URL" "$NXF_BIN"
fi
check=".+:.+:.+"
if [[ "$NXF_DRMAA" =~ $check ]]; then
# add drmaa library downloadable from maven to dependencies list
NXF_GRAB+=" $NXF_DRMAA"
NXF_MODE='drmaa'
elif [[ "$NXF_DRMAA" && -f "$NXF_DRMAA" ]]; then
# add drmaa jar file to custom classpath
NXF_CLASSPATH+=":$NXF_DRMAA"
NXF_MODE='drmaa'
elif [[ "$NXF_DRMAA" ]]; then
echo_red "Cannot find specified DRMAA library file: $NXF_DRMAA"
exit 1
fi
[[ "$cmd" == "console" ]] && NXF_MODE='console'
[[ "$cmd" == "node" && ! "$NXF_MODE" ]] && NXF_MODE='gridgain'
COLUMNS=${COLUMNS:-`tty -s && tput cols 2>/dev/null || true`}
JAVA_OPTS="-noverify -Dcapsule.trampoline -Dcapsule.java.cmd=$JAVA_CMD"
if [[ $cmd == console ]]; then bg=1;
else JAVA_OPTS+=" -Djava.awt.headless=true"
fi
[[ "$NXF_MODE" ]] && JAVA_OPTS+=" -Dcapsule.mode=$NXF_MODE"
[[ "$JAVA_HOME" ]] && JAVA_OPTS+=" -Dcapsule.java.home=$JAVA_HOME"
[[ "$CAPSULE_LOG" ]] && JAVA_OPTS+=" -Dcapsule.log=$CAPSULE_LOG"
[[ "$CAPSULE_RESET" ]] && JAVA_OPTS+=" -Dcapsule.reset=true"
[[ "$cmd" != "run" && "$cmd" != "node" ]] && JAVA_OPTS+=" -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
[[ "$NXF_OPTS" ]] && JAVA_OPTS+=" $NXF_OPTS"
[[ "$NXF_CLASSPATH" ]] && export NXF_CLASSPATH
[[ "$NXF_GRAB" ]] && export NXF_GRAB
[[ "$COLUMNS" ]] && export COLUMNS
[[ "${jvmopts[@]}" ]] && JAVA_OPTS+=" ${jvmopts[@]}"
# use drip to speedup startup time -- https://github.com/ninjudd/drip
[[ "$NXF_DRIP" ]] && export DRIP_INIT='' && export DRIP_INIT_CLASS='nextflow.cli.DripMain'
export JAVA_CMD
export CAPSULE_CACHE_DIR
# lookup the a `md5` command
if hash md5sum 2>/dev/null; then MD5=md5sum;
elif hash gmd5sum 2>/dev/null; then MD5=gmd5sum;
elif hash md5 2>/dev/null; then MD5=md5;
else MD5=''
fi
# when no md5 command is available fallback on default execution
if [ ! "$MD5" ] || [ "$CAPSULE_RESET" ]; then
launcher=($("$JAVA_CMD" $JAVA_OPTS -jar "$NXF_BIN"))
launch_nextflow
exit 1
fi
# creates a md5 unique for the given variables
env_md5() {
cat <<EOF | $MD5 | cut -f1 -d' '
$JAVA_CMD
$JAVA_OPTS
$NXF_VER
$NXF_OPTS
$NXF_GRAB
$NXF_CLASSPATH
$NXF_DRIP
EOF
}
# checked if a cached classpath file exists and it newer that the nextflow boot jar file
LAUNCH_FILE="${NXF_LAUNCHER}/classpath-$(env_md5)"
if [ -s "$LAUNCH_FILE" ] && [ "$LAUNCH_FILE" -nt "$NXF_BIN" ]; then
launcher=($(cat "$LAUNCH_FILE"))
else
# otherwise run the capsule and get the result classpath in the 'launcher' and save it to a file
launcher=($("$JAVA_CMD" $JAVA_OPTS -jar "$NXF_BIN"))
[[ $? -ne 0 ]] && echo 'Unable to initialize nextflow environment' && exit $?
mkdir -p ${NXF_LAUNCHER}
echo "${launcher[@]}" > "$LAUNCH_FILE"
fi
# finally run it
launch_nextflow