-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_pipeline.sh
executable file
·322 lines (272 loc) · 6.75 KB
/
execute_pipeline.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
#!/bin/bash
usage() {
echo "Usage: $0 [OPTIONS] file"
echo " -k, --keep-alive keep alive"
echo " --sleep=N pause number seconds before exiting"
#echo " -t N, --threads N, --threads=N set number of threads"
echo " -h, --help display this help and exit"
}
create_rnaseq_command() {
# Example JSON
# {
# "sample_file":"/opt/input/sample.info",
# "config_file":"/opt/input/euk_rnaseq.config",
# "reffile":"/opt/input/referense.fasta",
# "quality":"40", # 'No' if not using qual value
# "gtffile":"/opt/input/annotation.gtf",
# "build_indexes":"yes",
# "quality_stats":"no",
# "quality_trimming":"no",
# "split":"no",
# "alignment":"yes",
# "idxfile":"no", # Filepath if wanting to use idxfile
# "visualization":"yes",
# "rpkm_analysis":"no",
# "annotation_format":"gtf",
# "diff_gene_expr":"yes",
# "comparison_groups":"experiementvscontrol",
# "count":"no",
# "file_type":"SAM", # 'No' if not needed
# "sorted":"position", # 'No' if not needed
# "isoform_analysis":"yes",
# "include_novel":"yes",
# "diff_isoform_analysis":"yes",
# "use_ref_gtf":"no",
# "repository_root":"/opt/projects/rnaseq", # Constant
# "ergatis_ini":"/var/www/html/ergatis/cgi/ergatis.ini", # Constant
# "outdir":"/opt/projects/rnaseq", # Constant
# "template_dir":"/opt/projects/ergatis/package-rnaseq/pipeline_templates/Eukaryotic_RNA_Seq_Analysis", # Constant... either Euk path or Prok path
# "cufflinks_legacy":"no",
# "tophat_legacy":"no"
# }
# Assign file types from directory to variables
sample_info=$(find $1 -type f -name "*.info")
config_file=$(find $1 -type f -name "*.config")
reference=$(find $1 -type f \(-name "*.fasta" -o -name "*.fa" -o -name "*.fsa" -o -name "*.fna"\) )
annotation=$(find $1 -type f \(-name "*.gtf" -o -name "*.gff" -o -name "*.gff3"\) )
json_file=$(find $1 -type f -name "*.json")
# Parse JSON file with python JSON module
json_opts=$(echo $json_file | python -mjson.tool | grep ":" | grep -ve "\"no\"")
rnaseq_cmd=""
# Does template dir have Prok or Euk?
if [[ $json_optis =~ .*Prok.* ]]; then
rnaseq_cmd="/opt/ergatis/package-rnaseq/bin/create_prok_rnaseq_config.pl"
else
rnaseq_cmd="/opt/ergatis/package-rnaseq/bin/create_euk_rnaseq_config.pl"
fi
while read -r line; do
param=$(echo $line | cut -f1 -d:)
val=$(echo $line | cut -f2 -d:)
rnaseq_cmd+=" --$param"
# If param has a value, add value to cmd
if [[ ! $val =~ .*yes.* && ! $val =~ .*Yes.* ]]; then
rnaseq_cmd+="=$val"
fi
done <<< $json_opts
return $rnaseq_cmd
}
#--------------------------------------------------------------------------------
# Process parameters
opt_a=0
opt_k=0
opt_s=0
#opt_t=0
max_threads=1
while true
do
case $1 in
--help|-h)
usage
exit
;;
--start-web-server)
opt_a=1
;;
--keep-alive|-k)
opt_k=1
;;
--aws-secret|-S)
if [ "$2" ]
then
secret=$2
shift
else
echo "$0: missing argument to '$1' option"
usage
exit 1
fi
;;
--aws-key|-K)
if [ "$2" ]
then
key=$2
shift
else
echo "$0: missing argument to '$1' option"
usage
exit 1
fi
;;
--sleep=?*)
opt_s=1
seconds=${1#*=}
;;
--sleep|sleep=)
echo "$0: missing argument to '$1' option"
usage
exit 1
;;
# --threads=?*)
# opt_t=1
# threads=${1#*=}
# ;;
# --threads=)
# echo "$0: missing argument to '$1' option"
# usage
# exit 1
# ;;
# --threads|-t)
# if [ "$2" ]
# then
# opt_t=1
# threads=$2
# shift
# else
# echo "$0: missing argument to '$1' option"
# usage
# exit 1
# fi
# ;;
--)
shift
break
;;
-?*)
echo "$0: invalid option: $1"
usage
exit 1
;;
*)
break
esac
shift
done
if [ $# != 1 -a $opt_a -eq 0 ]
then
usage
exit 1
fi
# Archived file either in an S3 bucket or a local directory
input_zip=$1
#--------------------------------------------------------------------------------
# Verify sleep seconds
if [ $opt_s -eq 1 ]
then
if [ $seconds -lt 1 ]
then
echo "$0: invalid sleep number: $seconds"
exit 1
fi
fi
#--------------------------------------------------------------------------------
# Verify threads
# if [ $opt_t -eq 1 ]
# then
# if [ $threads -lt 1 ]
# then
# echo "$0: invalid thread number: $threads"
# exit 1
# fi
# max_threads=${threads}
# fi
#--------------------------------------------------------------------------------
# Detect host environment
if [ -f /sys/hypervisor/uuid ] && [ `head -c 3 /sys/hypervisor/uuid` == ec2 ]
then
host_type=ec2
else
host_type=local
fi
#--------------------------------------------------------------------------------
# Verify input/output/database directories
if [ $host_type = "ec2" -o $host_type = "local" ]
then
if [ ! -d /opt/input ]
then
mkdir -p /opt/input
fi
if [ ! -d /opt/output ]
then
mkdir -p /opt/output
fi
fi
#--------------------------------------------------------------------------------
# Amazon EC2 host instance
if [ $host_type = "ec2" ]
then
# Download input files
cd /opt/input
AWS_SECRET_ACCESS_KEY=$secret
AWS_ACCESS_KEY_ID=$key
aws --no-sign-request s3 cp --recursive --quiet $input_zip .
retcode=$?
if [ $retcode -ne 0 ]
then
echo "$0: aws s3 cp failed: aws return code: $retcode"
exit 1
fi
unzip $(basename $input_zip)
input_dir=/opt/input
fi
#--------------------------------------------------------------------------------
# Local host instance
if [ $host_type = "local" ]
then
# If going this route, ensure input_dir is mounted via volume
input_dir=/opt/input/
fi
#--------------------------------------------------------------------------------
# Start apache
if [ $opt_a -eq 1 ]
then
/usr/sbin/apachectl start
fi
#--------------------------------------------------------------------------------
# Configure/run rnaseq pipeline
export PERL5LIB=/opt/ergatis/lib/perl5
create_rnaseq_command "$input_dir"
# Some last minute modifications before running the cmd would go here
rnaseq_cmd+=" --block"
`rnaseq_cmd`
status=$?
if [ $status -ne 0 ]
then
echo "$0: pipeline error: $status"
fi
#--------------------------------------------------------------------------------
# Verify sleep and keep-alive options - mutually exclusive
if [ $opt_s -eq 1 -a $opt_k -eq 1 ]
then
echo "$0: specifying both sleep and keep-alive options not allowed"
exit 1
fi
#--------------------------------------------------------------------------------
# Sleep
if [ $opt_s -eq 1 ]
then
echo "sleeping $seconds seconds before exiting..."
sleep $seconds
fi
#--------------------------------------------------------------------------------
# Keepalive
if [ $opt_k -eq 1 ]
then
echo "keep alive..."
while true
do
sleep 60
done
fi
#--------------------------------------------------------------------------------
# Exit
exit $status