-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvip.sh
executable file
·244 lines (221 loc) · 6.65 KB
/
vip.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
#!/bin/bash
# Retrieve directory containing the collection of scripts (allows using other scripts with & without Slurm).
if [[ -n "${SLURM_JOB_ID}" ]]; then SCRIPT_DIR=$(dirname "$(scontrol show job "${SLURM_JOB_ID}" | awk -F= '/Command=/{print $2}' | cut -d ' ' -f 1)"); else SCRIPT_DIR=$(dirname "$(realpath "$0")"); fi
SCRIPT_NAME="$(basename "$0")"
# SCRIPT_DIR is incorrect when vip.sh is submitted as a Slurm job that is submitted as part of another Slurm job
VIP_DIR="${VIP_DIR:-"${SCRIPT_DIR}"}"
VIP_VERSION="8.1.1"
display_version() {
echo -e "${VIP_VERSION}"
}
usage() {
echo -e "usage: ${SCRIPT_NAME} [-w <arg> -i <arg> -o <arg>]
-w, --workflow <arg> workflow to execute. allowed values: cram, fastq, gvcf, vcf
-i, --input <arg> path to sample sheet .tsv
-o, --output <arg> output folder
-c, --config <arg> path to additional nextflow .cfg (optional)
-p, --profile <arg> nextflow configuration profile (optional)
-r, --resume resume execution using cached results (default: false)
-s, --stub quickly prototype workflow logic using process script stubs
-h, --help display this help and exit
-v, --version display version information and exit
For complete documentation, visit <https://molgenis.github.io/vip/>"
}
validate() {
local -r workflow="${1}"
local -r input="${2}"
local -r output="${3}"
local -r config="${4}"
local -r profile="${5}"
local -r resume="${6}"
local -r stub="${7}"
if [[ -z "${workflow}" ]]; then
>&2 echo -e "error: missing required -w / --workflow"
usage
exit 2
fi
if [[ ! "${workflow}" =~ cram|fastq|gvcf|vcf ]]; then
>&2 echo -e "error: workflow '${workflow}'. allowed values are [cram, fastq, gvcf, vcf]"
usage
exit 2
fi
if [[ -z "${input}" ]]; then
>&2 echo -e "error: missing required -i / --input"
usage
exit 2
fi
if [[ ! -f "${input}" ]]; then
>&2 echo -e "error: input '${input}' does not exist"
exit 2
fi
if [[ -z "${output}" ]]; then
>&2 echo -e "error: missing required -o / --output"
usage
exit 2
fi
if [[ "${resume}" == "false" ]] && [[ -d "${output}" ]] && [[ $(find "${output}" -mindepth 1 -maxdepth 1 | read) ]]; then
>&2 echo -e "error: output '${output}' already exists. remove or use -r / --resume to resume execution"
exit 2
fi
if [[ -n "${config}" ]] && [[ ! -f "${config}" ]]; then
>&2 echo -e "error: config '${config}' does not exist"
exit 2
fi
# detect java, try to load module with name 'java' or 'Java' otherwise
if ! command -v java &> /dev/null; then
if command -v module &> /dev/null; then
if module is_avail java; then
module load java
elif module is_avail Java; then
module load Java
else
>&2 echo -e "error: missing required 'java'. could not find a module with name 'java' or 'Java' to load"
exit 2
fi
else
>&2 echo -e "error: missing required 'java'"
exit 2
fi
fi
}
execute_workflow() {
local -r paramWorkflow="${1}"
local -r paramInput="${2}"
local -r paramOutput="${3}"
local -r paramConfig="${4}"
local -r paramProfile="${5}"
local -r paramResume="${6}"
local -r paramStub="${7}"
rm -f "${paramOutput}/nxf_report.html"
rm -f "${paramOutput}/nxf_timeline.html"
local configs="${VIP_DIR}/config/nxf_${paramWorkflow}.config"
if [[ -n "${paramConfig}" ]]; then
configs+=",${paramConfig}"
fi
local binds=()
binds+=("/$(realpath "${paramInput}" | cut -f 2 -d "/")")
local envBind="$(IFS=, ; echo "${binds[*]}")"
local envCacheDir="${VIP_DIR}/images"
local envHome
if [[ -z "${NXF_HOME}" ]]; then
envHome="${paramOutput}/.nxf.home"
else
envHome="${NXF_HOME}"
fi
local envTemp
if [[ -z "${NXF_TEMP}" ]]; then
envTemp="${paramOutput}/.nxf.tmp"
else
envTemp="${NXF_TEMP}"
fi
local envWork
if [[ -z "${NXF_WORK}" ]]; then
envWork="${paramOutput}/.nxf.work"
else
envWork="${NXF_WORK}"
fi
if [[ -z "${NXF_JVM_ARGS}" ]]; then
envJvm="-Xmx512m"
else
envJvm="${NXF_JVM_ARGS}"
fi
local envStrict="true"
local args=()
args+=("-C" "${configs}")
args+=("-log" "${paramOutput}/.nxf.log")
args+=("run")
args+=("${VIP_DIR}/vip_${paramWorkflow}.nf")
args+=("-offline")
args+=("-profile" "${paramProfile}")
args+=("-with-report" "${paramOutput}/nxf_report.html")
args+=("-with-timeline" "${paramOutput}/nxf_timeline.html")
args+=("--input" "${paramInput}")
args+=("--output" "${paramOutput}")
if [[ "${paramResume}" == "true" ]]; then
args+=("-resume")
fi
if [[ "${paramStub}" == "true" ]]; then
args+=("-stub")
fi
(cd "${paramOutput}" && APPTAINER_BIND="${APPTAINER_BIND-${envBind}}" APPTAINER_CACHEDIR="${envCacheDir}" NXF_VER="24.10.3" NXF_HOME="${envHome}" NXF_TEMP="${envTemp}" NXF_WORK="${envWork}" NXF_ENABLE_STRICT="${envStrict}" NXF_JVM_ARGS="${envJvm}" VIP_VERSION="${VIP_VERSION}" "${VIP_DIR}/nextflow" "${args[@]}")
}
main() {
local args=$(getopt -a -n pipeline -o w:i:o:c:p:rsvh --long workflow:,input:,output:,config:,profile:,resume,stub,version,help -- "$@")
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
usage
exit 2
fi
local workflow=""
local input=""
local output=""
local config=""
local profile=""
if command -v sbatch &> /dev/null; then
profile="slurm"
else
profile="local"
fi
local resume="false"
local stub="false"
eval set -- "${args}"
while :; do
case "$1" in
-v | --version)
display_version
exit 0
shift
;;
-h | --help)
usage
exit 0
shift
;;
-w | --workflow)
workflow="$2"
shift 2
;;
-i | --input)
if [[ "$2" = /* ]]; then input="$2"; else input="${PWD}/$2"; fi
shift 2
;;
-o | --output)
if [[ "$2" = /* ]]; then output="$2"; else output="${PWD}/$2"; fi
shift 2
;;
-c | --config)
if [[ "$2" = /* ]]; then config="$2"; else config="${PWD}/$2"; fi
shift 2
;;
-p | --profile)
profile="$2"
shift 2
;;
-r | --resume)
resume="true"
shift
;;
-s | --stub)
stub="true"
shift
;;
--)
shift
break
;;
*)
usage
exit 2
;;
esac
done
validate "${workflow}" "${input}" "${output}" "${config}" "${profile}" "${resume}" "${stub}"
if [[ "${resume}" == "true" ]] && ! [[ -d "${output}" ]]; then
resume="false"
fi
if ! [[ -d "${output}" ]]; then
mkdir -p "${output}"
fi
execute_workflow "${workflow}" "${input}" "${output}" "${config}" "${profile}" "${resume}" "${stub}"
}
main "${@}"