-
Notifications
You must be signed in to change notification settings - Fork 14
/
install.sh
executable file
·319 lines (292 loc) · 10.2 KB
/
install.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
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# INTRO
# ------------------------------------------------------------------------------
set -e
echo '--------------------------------------------------------------------------------'
echo 'Read Origin Protocol: Installer'
echo '--------------------------------------------------------------------------------'
DIR=`dirname $(readlink -f "$0")`
sed '/##/ q' "$DIR/README.md" | head -n -2 | tail -n +3
echo '--------------------------------------------------------------------------------'
# ------------------------------------------------------------------------------
# CONSTANTS
# ------------------------------------------------------------------------------
declare -A DB_ID_HUMAN=(
['viral_vipr']='1ISkC9Z4oYgtxlitMbB-C3T9tZgErjR8_'
['fungi']='1NH4bx1ZpDpiv_wqYcxwR02kBalVdMF2f'
['BWAindex']='13H20BSdp6JMG3BzDSL0JE3m9X12Jaj6n'
['protozoa']='1X5ElXNkkTBxd9Wui6ttvi3LhdcfDzTMc'
['metaphlan']='1RnhchW875-DqED7xkWV5W1oFFESKLE1r'
['repeats']='1W4wMCUSTgVgnUxVocYy1CqCSmEYWJyuF'
['ribosomal.DNA']='1T4JdkSJUZVvOZdZcWgmk_u0XSfLdxqdF'
['viral']='1ZzCuwW-38yU6igoIJYKwi8KFPwSxcvsg'
)
declare -A DB_ID_MOUSE=(
['viral_vipr']='1ISkC9Z4oYgtxlitMbB-C3T9tZgErjR8_' # same as human
['fungi']='1NH4bx1ZpDpiv_wqYcxwR02kBalVdMF2f' # same as human
['BWAindex']='1L9fMlRjGcB85_orar1ObK_VVE3IfbUsd'
['protozoa']='1X5ElXNkkTBxd9Wui6ttvi3LhdcfDzTMc' # same as human
['metaphlan']='1RnhchW875-DqED7xkWV5W1oFFESKLE1r' # same as human
['repeats']='1z888jreCH3HSUfbn-DvkBdNdeZ34tLLe'
['ribosomal.DNA']='1YtPRdUciVl2K0GybH4VPs_mf-l-LvUsX'
['viral']='1ZzCuwW-38yU6igoIJYKwi8KFPwSxcvsg' # same as human
)
declare -A DB_MD5_HUMAN=(
['viral_vipr']='3b5d1e88e8fd64db2fd997283e06c7ea'
['fungi']='99dff18fae92549b1b7e92fa3fede4ff'
['BWAindex']='1bdaba6c5987a0bdb37657b6fb33a2fc'
['protozoa']='33751a0312882dbbd9699cb53d78459d'
['metaphlan']='a07a407ce7071df373af9d6795704bc9'
['repeats']='c6939256a21dd166c9c38380afbd9f7c'
['ribosomal.DNA']='f339943ddfff31533e749dc28b70065c'
['viral']='6a16fc9726ebad359a6b3719703dba83'
)
declare -A DB_MD5_MOUSE=(
['viral_vipr']='3b5d1e88e8fd64db2fd997283e06c7ea' # same as human
['fungi']='99dff18fae92549b1b7e92fa3fede4ff' # same as human
['BWAindex']='6acd8bb77687dcd139a27d1bcab72eca'
['protozoa']='33751a0312882dbbd9699cb53d78459d' # same as human
['metaphlan']='a07a407ce7071df373af9d6795704bc9' # same as human
['repeats']='8988a4b1c671bcf2bbce8a4b08d564ef'
['ribosomal.DNA']='78b73b3548feb7113cf56a5fd61d3ce2'
['viral']='6a16fc9726ebad359a6b3719703dba83' # same as human
)
# ------------------------------------------------------------------------------
# PARSE OPTIONS
# ------------------------------------------------------------------------------
# Test for getopt availability.
set +e
getopt --test
if [ $? -ne 4 ]; then
echo "Error: Environment doesn't support getopt." >&2
exit 1
fi
set -e
# Call getopt.
SHORT_OPTIONS='cfnl:d:o:rs:h'
LONG_OPTIONS='clean,force,native,link:,db-dest:,organism:,reinstall,select-db:,help'
set +e
PARSED=`getopt --options="$SHORT_OPTIONS" --longoptions="$LONG_OPTIONS" --name "$0" -- "$@"`
if [ $? -ne 0 ]; then
exit 1 # getopt will have printed the error message
fi
set -e
eval set -- "$PARSED"
# Set default options.
CLEAN_ONLY=false
FORCE=false
NATIVE=false
LINK=''
DB_DEST="$DIR"
ORGANISM='human'
REINSTALL=false
SELECT_DB='all'
# Review parsed options. -c and -l override conflicting options.
while true; do
case "$1" in
-c|--clean-only)
# Just remove installed tools.
CLEAN_ONLY=true
shift
;;
-f|--force)
# Unlink databases.
FORCE=true
shift
;;
-n|--native)
# Use native python.
NATIVE=true
shift
;;
-l|--link)
# Link databases instead of downloading.
LINK="$2"
shift 2
;;
-d|--db-dest)
# Change database download location.
DB_DEST="$2"
shift 2
;;
-o|--organism)
# Organism to download databases for.
ORGANISM="$2"
shift 2
;;
-r|--reinstall)
# Reinstall tools, even if they're already present.
REINSTALL=true
shift
;;
-s|--select-db)
# Database(s) to download for the specified organism.
SELECT_DB=`tr ',' ' ' <<<"$2"`
shift 2
;;
-h|--help)
echo "Usage: $0 [-cfnrh] [-l LINK] [-d DB_DEST] [-o ORGANISM]"\
'[-s SELECT_DB]' >&2
exit 0
;;
--)
# End of options.
shift
break
;;
*)
echo "Error parsing options." >&2
exit 1
;;
esac
done
# ------------------------------------------------------------------------------
# DOWNLOAD TOOLS
# ------------------------------------------------------------------------------
cd "$DIR/tools"
# Skip this section if neither -c nor -r are selected and there is a previous
# installation (as indicated by the presence of the imrep directory).
echo '----- Checking for existing installations --------------------------------------'
if [ $CLEAN_ONLY = false ] && [ $REINSTALL = false ] && [ -d 'imrep' ]; then
echo 'Existing installation found. Skipping tools download. To reinstall,' \
'please use the -r option.'
else
echo '----- Removing previous versions -----------------------------------------------'
rm -fr imrep metaphlan2 MiniConda
if [ $CLEAN_ONLY = true ]; then
echo 'Done: Cleaning complete.'
exit 0
fi
# Download ImReP.
echo '----- Downloading ImRep --------------------------------------------------------'
git clone https://github.com/mandricigor/imrep.git
cd imrep
./install.sh
cd ..
# Download MetaPhlAn 2.
echo '----- Downloading MetaPhlAn 2 --------------------------------------------------'
git clone https://github.com/biobakery/metaphlan2
cd metaphlan2
ln -s ../../db_human/databases db_v20
cd ..
# Download MiniConda.
echo '----- Setting up Python environment --------------------------------------------'
if [ $NATIVE = false ]; then
./install-MiniConda.sh
cd MiniConda/lib
ln -s libncursesw.so.5 libtinfow.so.5
cd ../..
MiniConda="$PWD/MiniConda/bin/python"
fi
fi
# ------------------------------------------------------------------------------
# LINK/UNLINK DATABASES
# ------------------------------------------------------------------------------
cd "$DIR"
echo '----- Checking for existing databases ------------------------------------------'
if [ -h "db_$ORGANISM" ] || [ -d "db_$ORGANISM" ]; then
if [ $FORCE = true ]; then
echo 'Unlinking existing database.'
if [ -h "db_$ORGANISM" ]; then
rm "db_$ORGANISM"
else
rm -r "db_$ORGANISM"
fi
else
echo 'Existing database found. Skipping database download.' \
'To unlink the current database, please use the -f option.'
exit 0
fi
fi
if [ "$LINK" != '' ]; then
echo '----- Linking database -----------------------------------------------------'
if [ -d "$LINK" ]; then
ln -s "$LINK"
echo 'Done: Database linked.'
exit 0
else
echo "Error: Link target doesn't exist." >&2
exit 1
fi
fi
# ------------------------------------------------------------------------------
# DOWNLOAD DATABASES
# ------------------------------------------------------------------------------
cd "$DB_DEST"
mkdir "db_$ORGANISM"
cd "db_$ORGANISM"
download_list=$'ribosomal.DNA\nBWAindex'
for database in $SELECT_DB; do
case "$database" in
basic)
;;
repeats)
download_list+=$'\nrepeats'
;;
microbiome)
download_list+=$'\nmetaphlan\nviral\nviral_vipr\nfungi\nprotozoa'
;;
metaphlan)
download_list+=$'\nmetaphlan'
;;
viral)
download_list+=$'\nviral\nviral_vipr'
;;
fungi)
download_list+=$'\nfungi'
;;
protozoa)
download_list+=$'\nprotozoa'
;;
all)
download_list+=$'\nrepeats'
download_list+=$'\nmetaphlan\nviral\nviral_vipr\nfungi\nprotozoa'
;;
*)
echo 'Error: Unknown database.' >&2
exit 1
;;
esac
done
download_list=`echo "$download_list" | sort -u`
echo '----- Downloading databases ----------------------------------------------------'
for download in $download_list; do
echo "Downloading item: $download for $ORGANISM"
success=false
while [ $success = false ]; do
case "$ORGANISM" in
human)
db_id="${DB_ID_HUMAN[$download]}"
db_md5="${DB_MD5_HUMAN[$download]}"
;;
mouse)
db_id="${DB_ID_MOUSE[$download]}"
db_md5="${DB_MD5_MOUSE[$download]}"
;;
*)
echo 'Error: Unknown ORGANISM.' >&2
exit 1
;;
esac
confirm_code=`curl --silent --insecure --cookie-jar cookies.txt \
"https://docs.google.com/uc?export=download&id=$db_id" \
| sed -rn 's .*confirm=([0-9A-Za-z_]+).* \1\n p'`
curl --location --insecure --cookie cookies.txt -o "$download.tar.gz" \
"https://docs.google.com/uc?export=download&confirm=$confirm_code&id=$db_id"
rm -f cookies.txt
if [ `md5sum "$download.tar.gz" | sed 's \(.*\)\ .* \1 '` = "$db_md5" ]; then
tar -zxvf "$download.tar.gz"
rm "$download.tar.gz"
success=true
else
echo "Download of $download for $ORGANISM failed (checksum" \
'mismatch. Retrying.'
fi
done
done
cd "$DIR"
if [ `readlink -e "$DB_DEST"` != "$DIR" ]; then
ln -s "$DB_DEST/db_$ORGANISM"
fi
echo "Done: Reference databases are ready"