-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_toil.sh
85 lines (72 loc) · 2.16 KB
/
run_toil.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
#!/bin/bash
## input parameters:
CWLSCRIPT="$1" # Path to CWL workflow
INPUT="$2" # Path to folder containing multiple yaml input files
# Or path to a single yaml input file
OUTDIR="$3" # Path to output dir
## cluster infrastructure - please adapt accordingly
BATCHSYSTEM="singleMachine" # can be one of:
# - "singleMachine"
# - "LSF"
# - "Mesos"
# - "Slurm"
# - "Torque"
# - "parasol"
# - "gridEngine"
## working and temp dirs - please adapt accordingly:
BASEDIR=${HOME}/cwl_working_dir/base
WORKDIR=${HOME}/cwl_working_dir/work
TMPDIR=${HOME}/cwl_working_dir/tmp
TMPOUTDIR=${HOME}/cwl_working_dir/tmp_out
## create dirs if don't exist
if [ ! -d "$OUTDIR" ]
then
mkdir -p "$OUTDIR"
fi
if [ ! -d "$BASEDIR" ]
then
mkdir -p "$BASEDIR"
fi
if [ ! -d "$WORKDIR" ]
then
mkdir -p "$WORKDIR"
fi
if [ ! -d "$TMPDIR" ]
then
mkdir -p "$TMPDIR"
fi
if [ ! -d "$TMPOUTDIR" ]
then
mkdir -p "$TMPOUTDIR"
fi
## get input files:
if [ -d "$INPUT" ]
then
## input is a directory containing multiple yml files
YAML_INPUTS=($( ls "${INPUT}"/*.y*ml ))
else
## a single yml file was given as input
YAML_INPUTS=( "$INPUT" )
fi
## Start running:
echo ">>> Working with $CWLSCRIPT"
echo "> Starting jobs:"
for((i=0; i<"${#YAML_INPUTS[@]}"; i++))
do
echo "- ${YAML_INPUTS[i]}"
RANDOM_HASH=`date | md5sum | head -c10`
cwltoil --singularity --logDebug --clean always --cleanWorkDir always \
--tmp-outdir-prefix "$TMPOUTDIR" --tmpdir-prefix "$TMPDIR" --jobStore "${JOBSTORE}/${RANDOM_HASH}_${YAML_INPUTS[i]##*/}" \
--workDir "$WORKDIR" --basedir "$BASEDIR" --outdir "$OUTDIR" \
"$CWLSCRIPT" "${YAML_INPUTS[i]}" >> "${OUTDIR}/${YAML_INPUTS[i]##*/}".log 2>&1 &
echo -e "${YAML_INPUTS[i]}\t$!" >> "${OUTDIR}/cwl_background_job_ids.log"
echo " job id: $!"
disown %-
done
## packed copy of the workflow to output dir
cwltool --pack "$CWLSCRIPT" > "${OUTDIR}/workflow.cwl" 2> /dev/null
echo "> done"
echo "> jobs are running in the background and are detached from this terminal session"
echo "> for checking the progress please have a look at the \".yaml.log\" files in the output directory"
echo "> OUTPUT DIR: $OUTDIR"
echo "> You can close the terminal now."