-
Notifications
You must be signed in to change notification settings - Fork 14
/
virify.sh
executable file
·338 lines (309 loc) · 7.46 KB
/
virify.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
#!/usr/bin/env bash
set -e
usage () {
echo ""
echo "Wrapper script to run the virify workflow using toil-cwl-runner."
echo ""
echo "-e Environemnt init script [mandatory]: "
echo " * conda env activation"
echo " * Batch system (lsf or slurm)"
echo " * Add scripts folder to PATH"
echo " * Full paths for:"
echo " . VIRSORTER_DATA"
echo " . ADDITIONAL_HMMS_DATA"
echo " . HMMSCAN_DATABASE * aux files need to be in the same directory"
echo " . NCBI_TAX_DB_FILE"
echo " . IMGVR_BLAST_DB"
echo " . VIRFINDER_MODEL"
echo " * CLUSTER_BATCH_SYSTEM: The cluster batch system (default slurm)"
echo "-n the name for the job *a timestamp will be added to folder* [mandatory]"
echo "-j toil job store folder path [mandatory]"
echo "-o output folder [mandatory]"
echo "-c number of cores for the job [mandatory]"
echo "-m memory in *megabytes* [mandatory]"
echo "-i intput fasta contigs [mandatory]"
echo "-f Length threshold in kb of selected sequences [default: 1.0]"
echo "-v virome mode for virsorter (default if OFF)"
echo "-s mashmap reference file fasta or fastq (.gz) (optional)"
echo "-r Restart workdir path. "
echo " Path to the job work dir for restart.Toil will raise an expection if the work directory doesn't exist"
echo "-p Execution profile:"
echo " LOCAL to run the pipeline locally with no batch scheduler."
echo " EMBASSY to run it using Slurm and Docker"
echo " CODON to run it using LSF and Singularity"
echo ""
echo ""
echo "-t Use cwltool to run the pipeline."
echo ""
echo "Example:
virify.sh -e init.sh -n test-run -m 1024 -c 12 -j JOB_DIR_path -o /data/results/ -i input.fasta
NOTE:
- The results folder will be /data/results/{job_name}.
- The logs will be stored in /data/results/{job_name}/logs"
echo ""
}
# mandatory
NAME_RUN=""
JOB_DIR=""
OUT_DIR=""
CORES=""
MEMORY=""
INPUT_FASTA=""
VIROME=""
MASHMAP_REFERENCE=""
ENV_SCRIPT=""
LEN_FILTER="1.0"
RESTART=""
PROFILE=""
CWLTOOL=false
while getopts "e:n:j:o:c:m:i:vs:r:f:p:th" opt; do
case $opt in
e)
ENV_SCRIPT="$OPTARG"
if [ ! -f "$ENV_SCRIPT" ];
then
echo ""
echo "ERROR -e cannot be empty." >&2
usage;
exit 1
fi
;;
n)
NAME_RUN="$OPTARG"
if [ -z "$NAME_RUN" ];
then
echo ""
echo "ERROR -n cannot be empty." >&2
usage;
exit 1
fi
;;
j)
JOB_DIR="$OPTARG"
;;
o)
OUT_DIR="$OPTARG"
if [ -z "$OUT_DIR" ];
then
echo ""
echo "ERROR -o cannot be empty." >&2
usage;
exit 1
fi
mkdir -p "$OUT_DIR"
;;
c)
CORES="$OPTARG"
if ! [[ "$CORES" =~ ^[0-9]+$ ]]
then
echo ""
echo "ERROR (-c): $CORES is not a number." >&2
usage;
exit 1
fi
;;
m)
MEMORY="$OPTARG"
if ! [[ "$MEMORY" =~ ^[0-9]+$ ]]
then
echo ""
echo "ERROR (-m): $MEMORY is not a number." >&2
usage;
exit 1
fi
;;
i)
INPUT_FASTA="${OPTARG}"
if [ -z "${INPUT_FASTA}" ];
then
echo ""
echo "ERROR -i cannot be empty." >&2
usage;
exit 1
fi
;;
v)
VIROME="-v true"
;;
s)
if [ -z "${OPTARG}" ];
then
echo ""
echo "ERROR mashmap (-s) cannot be empty." >&2
usage;
exit 1
fi
MASHMAP_REFERENCE="${OPTARG}"
;;
h)
usage;
exit 0
;;
f)
LEN_FILTER="${OPTARG}"
;;
r)
RESTART="${OPTARG}"
;;
p)
PROFILE="${OPTARG^^}"
if [[ "${PROFILE}" =~ ^(LOCAL|EMBASSY|CODON)$ ]]; then
echo "Profile selected: ${PROFILE}"
else
echo "Invalid profile, please select one of LOCAL, EMBASSY or CODON"
usage;
exit 1;
fi
;;
t)
CWLTOOL=true
;;
:)
usage;
exit 1
;;
\?)
echo ""
echo "Invalid option -${OPTARG}" >&2
usage;
exit 1;
;;
esac
done
if ((OPTIND == 1))
then
echo ""
echo "ERROR: No options specified"
usage;
exit 1
fi
shift $((OPTIND - 1))
# mandatory params
if [ -z "${NAME_RUN}" ] || \
[ -z "${JOB_DIR}" ] || \
[ -z "${OUT_DIR}" ] || \
[ -z "${CORES}" ] || \
[ -z "${MEMORY}" ] || \
[ -z "${INPUT_FASTA}" ] || \
[ -z "${ENV_SCRIPT}" ]
then
echo ""
echo "ERROR: Missing mandatory parameter."
usage;
exit 1
fi
# shellcheck source=/dev/null
source "${ENV_SCRIPT}"
set -u
YML_INPUT=""
LOG_DIR=""
if [ -z "${RESTART}" ];
then
echo "Configuration and folders"
set -x
TS="$(date +"%Y-%m-%d_%H-%M")"
# Prefix the path to make it easier to clean
TMPDIR="${TMPDIR:-/scratch}/${NAME_RUN}_${TS}"
JOB_DIR="${JOB_DIR}/${NAME_RUN}_${TS}"
LOG_DIR="${OUT_DIR}/${NAME_RUN}_${TS}/logs"
OUT_DIR="${OUT_DIR}/${NAME_RUN}_${TS}"
# Prepare folders
mkdir -p "${LOG_DIR}"
mkdir -p "${OUT_DIR}"
set +x
# Prepare the yaml file
YML_INPUT="${OUT_DIR}/${NAME_RUN}_${TS}_input.yaml"
CWL_PARAMS=(
-i "${INPUT_FASTA}"
-f "${LEN_FILTER}"
-s "${VIRSORTER_DATA}"
-a "${ADDITIONAL_HMMS_DATA}"
-j "${HMMSCAN_DATABASE}"
-n "${NCBI_TAX_DB_FILE}"
-b "${IMGVR_BLAST_DB}"
-d "${VIRFINDER_MODEL}"
-o "${YML_INPUT}"
)
if [ -n "${MASHMAP_REFERENCE}" ];
then
CWL_PARAMS+=(-m "${MASHMAP_REFERENCE}")
fi
if [ -n "${VIROME}" ];
then
CWL_PARAMS+=("${VIROME}")
fi
set -x
cwl_input.py "${CWL_PARAMS[@]}"
set +x
fi
# assume CWL is src/pipeline.cwl relative to this script
SCRIPT_DIR="$(dirname "$0")"
TOIL_PARAMS=(
"--cleanWorkDir=onSuccess"
"--clean=never"
--defaultCores "$CORES"
--defaultMemory "$MEMORY"M
--retryCount 0
--disableProgress
)
# Profiles #
if [ "${PROFILE}" = "EMBASSY" ];
then
TOIL_PARAMS+=(
--batchSystem slurm
--disableCaching
)
fi
if [ "${PROFILE}" = "CODON" ];
then
TOIL_PARAMS+=(
--singularity
--batchSystem lsf
--disableCaching
)
fi
if [ "${PROFILE}" = "LOCAL" ];
then
TOIL_PARAMS+=(--no-container)
fi
if [ -z "${RESTART}" ];
then
# regular execution
TOIL_PARAMS+=(
--stats
--logWarning
--writeLogs "${LOG_DIR}"
--maxLogFileSize 50000000
--clusterStats "${LOG_DIR}/stats.json"
--outdir "${OUT_DIR}"
--logFile "${LOG_DIR}/${NAME_RUN}.log"
--rotatingLogging
--jobStore "${JOB_DIR}"
"${SCRIPT_DIR}/src/pipeline.cwl"
"${YML_INPUT}"
)
else
# restart previuos job
TOIL_PARAMS+=(
--jobStore "${RESTART}"
--restart
--enable-dev
"${RESTART}"
)
fi
set -x
if [ "${CWLTOOL}" = true ];
then
echo "CWL tool runner."
cwltool \
--preserve-entire-environment \
--leave-container \
--timestamps \
--disable-color \
--outdir "${OUT_DIR}" \
"${SCRIPT_DIR}/src/pipeline.cwl" \
"${YML_INPUT}" | tee "${LOG_DIR}"/"${NAME_RUN}".log
else
echo "Toil runner"
toil-cwl-runner "${TOIL_PARAMS[@]}"
fi