This repository has been archived by the owner on May 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
wrapper.sh
210 lines (169 loc) · 5.99 KB
/
wrapper.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
#!/bin/bash
###############################################################################
#### Helper Functions ####
###############################################################################
## ****************************************************************************
## Usage description should match command line arguments defined below
usage () {
echo "Usage: $(basename "$0")"
echo " --docker => Docker Image"
echo " --r1 => Forward Reads"
echo " --r2 => Reverse Reads"
echo " --isolate => Isolate to Process"
echo " --output => Output Directory"
echo " --help => Display this help message"
}
## ****************************************************************************
###############################################################################
## SCRIPT_DIR: directory of current script
###############################################################################
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
## ****************************************************************************
###############################################################################
#### Parse Command-Line Arguments ####
###############################################################################
getopt --test > /dev/null
if [ $? -ne 4 ]; then
echo "`getopt --test` failed in this environment."
exit 1
fi
## ****************************************************************************
## Command line options should match usage description
OPTIONS=
LONGOPTIONS=help,docker:,r1:,r2:,isolate:,output:,
## ****************************************************************************
# -temporarily store output to be able to check for errors
# -e.g. use "--options" parameter by name to activate quoting/enhanced mode
# -pass arguments only via -- "$@" to separate them correctly
PARSED=$(\
getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@"\
)
if [ $? -ne 0 ]; then
# e.g. $? == 1
# then getopt has complained about wrong arguments to stdout
usage
exit 2
fi
# read getopt's output this way to handle the quoting right:
eval set -- "$PARSED"
## ****************************************************************************
## Set any defaults for command line options
DOCKER=lp_serogroup:0.1
## ****************************************************************************
## ****************************************************************************
## Handle each command line option. Lower-case variables, e.g., ${file}, only
## exist if they are set as environment variables before script execution.
## Environment variables are used by Agave. If the environment variable is not
## set, the Upper-case variable, e.g., ${FILE}, is assigned from the command
## line parameter.
while true; do
case "$1" in
--help)
usage
exit 0
;;
--docker)
DOCKER=$2
shift 2
;;
--r1)
R1=$2
shift 2
;;
--r2)
R2=$2
shift 2
;;
--isolate)
ISOLATE=$2
shift 2
;;
--output)
OUTPUT=$2
shift 2
;;
--)
shift
break
;;
*)
echo "Invalid option"
usage
exit 3
;;
esac
done
## ****************************************************************************
## ****************************************************************************
## Log any variables passed as inputs
echo "Docker: ${DOCKER}"
echo "R1: ${R1}"
echo "R2: ${R2}"
echo "Isolate: ${ISOLATE}"
echo "Output: ${OUTPUT}"
## ****************************************************************************
###############################################################################
#### Validate and Set Variables ####
###############################################################################
## ****************************************************************************
## Add app-specific logic for handling and parsing inputs and parameters
# DOCKER parameter
if [ -z "${DOCKER}" ]; then
echo "Docker required"
echo
usage
exit 1
fi
# R1 input
if [ -z "${R1}" ]; then
echo "R1 required"
echo
usage
exit 1
fi
R1_FULL=$(readlink -f "${R1}")
R1_DIR=$(dirname "${R1_FULL}")
R1_BASE=$(basename "${R1_FULL}")
# R2 input
if [ -z "${R2}" ]; then
echo "R2 required"
echo
usage
exit 1
fi
R2_FULL=$(readlink -f "${R2}")
R2_DIR=$(dirname "${R2_FULL}")
R2_BASE=$(basename "${R2_FULL}")
# ISOLATE parameter
if [ -z "${ISOLATE}" ]; then
echo "Isolate required"
echo
usage
exit 1
fi
# OUTPUT parameter
if [ -z "${OUTPUT}" ]; then
echo "Output required"
echo
usage
exit 1
fi
OUTPUT_FULL=$(readlink -f "${OUTPUT}")
OUTPUT_DIR=$(dirname "${OUTPUT_FULL}")
OUTPUT_BASE=$(basename "${OUTPUT_FULL}")
## ****************************************************************************
###############################################################################
#### App Execution Preparation ####
###############################################################################
## ****************************************************************************
## Add logic to prepare environment for execution
mkdir -p ${OUTPUT_FULL}
ulimit -s 5248800
## ****************************************************************************
###############################################################################
#### App Execution ####
###############################################################################
## ****************************************************************************
## Add logic to execute app
docker run -v ${R1_DIR}:/data1 -v ${R2_DIR}:/data2 -v ${OUTPUT_FULL}:/output --rm --privileged ${DOCKER} --r1=/data1/${R1_BASE} --r2=/data2/${R2_BASE} --isolate=${ISOLATE} 2>&1 | tee ${OUTPUT_FULL}/pipeline-${ISOLATE}.log
## ****************************************************************************