-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·275 lines (226 loc) · 6.82 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
#!/usr/bin/env bash
#######################################################################
# Nuno A. Fonseca (nuno dot fonseca at gmail dot com)
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
########################################################################
set -e -o pipefail
## default installation folder
INSTALL_DIR=/opt/
###########################################
ALL_TOOLS="taxonkit blast metabinkit R_packages taxonomy_db"
SYSTEM_DEPENCIES="R bash"
blast_VERSION=2.10.1
blast_URL=ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/${blast_VERSION}/ncbi-blast-${blast_VERSION}+-x64-linux.tar.gz
TAXONKIT_VERSION=0.6.0
TAXONKIT_URL=https://github.com/shenwei356/taxonkit/releases/download/v${TAXONKIT_VERSION}/taxonkit_linux_amd64.tar.gz
###########################################
#
function pinfo {
echo "[INFO] $*"
}
###########################################
#
function check_system_deps {
local bin
pinfo "Checking dependencies..."
local MISSING=0
for bin in $SYSTEM_DEPS; do
local PATH2BIN=`which $bin 2> /dev/null`
if [ "$PATH2BIN-" == "-" ]; then
pinfo " $bin not found!"
#
MISSING=1
else
pinfo " $bin found: $PATH2BIN"
fi
done
pinfo "Checking dependencies...done."
if [ $MISSING == 1 ]; then
pinfo "ERROR: Unable to proceed"
exit 1
fi
}
check_system_deps
###########################################
function install_taxonkit {
pinfo "Installing taxonkit.."
rm -f tmp.tar.gz
wget -c $TAXONKIT_URL -O tmp.tar.gz
tar xzvf tmp.tar.gz
mkdir -p $INSTALL_DIR/bin
chmod +x taxonkit
mv taxonkit $INSTALL_DIR/bin
rm -f tmp.tar.gz
pinfo "Installing taxonkit..done."
}
function install_taxonomy_db {
pinfo "Installing taxonomy database..."
rm -f taxdump.tar.gz
wget ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
mkdir -p $INSTALL_DIR/db
tar xzvf taxdump.tar.gz -C $INSTALL_DIR/db
echo Downloaded `date` > $INSTALL_DIR/db/taxonomy.info
rm -f taxdump.tar.gz
pinfo "Installing taxonomy database...done"
}
function install_blast {
pinfo "Installing blast to $BLAST_IDIR..."
pushd $TMP_DIR
rm -f tmp.tar.gz
set +e
if [ ! -e $BLAST_IDIR/bin ]; then
mkdir -p $BLAST_IDIR/bin
fi
if [ ! -e $BLAST_IDIR/db ]; then
mkdir -p $BLAST_IDIR/db
fi
set -e
wget -c $blast_URL -O tmp.tar.gz
tar zxvpf tmp.tar.gz
rm -f tmp.tar.gz
cp ncbi-blast-${blast_VERSION}+/bin/* $BLAST_IDIR/bin
## taxonomy
wget -c ftp://ftp.ncbi.nlm.nih.gov/blast/db/taxdb.tar.gz
mv taxdb.tar.gz $BLAST_IDIR/db
pushd $BLAST_IDIR/db
tar xzvf taxdb.tar.gz
rm -f taxdb.tar.gz
popd
popd
##
pinfo "Installing blast...done."
}
function install_R_packages {
pinfo "Installing R packages to $INSTALL_DIR/Rlibs ..."
mkdir -p $INSTALL_DIR/Rlibs
R_LIBS_USER=$INSTALL_DIR/Rlibs R --vanilla <<EOF
repo<-"http://www.stats.bris.ac.uk/R/"
########################
# Check if version is ok
version <- getRversion()
currentVersion <- sprintf("%d.%d", version\$major, version\$minor)
message("R version:",version)
usebiocmanager<-TRUE
if ( version\$major < 3 || (version\$major==3 && version\$minor<5) ) {
cat("ERROR: R version should be 3.5 or above\n")
q(status=1)
}
########################
# Where to install the packages
assign(".lib.loc",.libPaths()[1],envir=environment(.libPaths))
message("Using library: ", .libPaths()[1])
##print(.libPaths())
message("_____________________________________________________")
if (version\$major > 3 || (version\$major == 3 && version\$minor>5)) {
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager",repo=repo)
BiocManager::install()
} else {
usebiocmanager<-FALSE
source("http://bioconductor.org/biocLite.R")
}
message("_____________________________________________________")
message("Installing packages")
packages2install<-c("Matrix","data.table","optparse","stringr")
for (p in packages2install ) {
message("PACKAGE:",p,"\n")
if ( usebiocmanager ) BiocManager::install(p,ask=FALSE)
else biocLite(p,ask=FALSE)
}
EOF
pinfo "Installing R packages to $INSTALL_DIR/Rlibs ...done."
}
function create_metabinkit_env {
pinfo "Creating $INSTALL_DIR/metabinkit_env.sh..."
cat <<EOF > $INSTALL_DIR/metabinkit_env.sh
export PATH=$BLAST_IDIR/bin:\$PATH
export PATH=$INSTALL_DIR/python/bin/:$INSTALL_DIR/bin:$INSTALL_DIR/exe:\$PATH
export LD_LIBRARY_PATH=$INSTALL_DIR/lib:\$LD_LIBRARY_PATH
export R_LIBS_USER=$INSTALL_DIR/Rlibs:$R_LIBS_USER
export BLASTDB=$BLAST_IDIR/db
EOF
cat <<EOF
You may want to consider adding the following line to your .bash_profile file.
source $INSTALL_DIR/metabinkit_env.sh
EOF
pinfo "Creating $INSTALL_DIR/metabinkit_env.sh...done."
}
function install_metabinkit {
pinfo "Installing metabinkit..."
cp -vrua R exe $INSTALL_DIR
create_metabinkit_env
pinfo "Installing metabinkit...done."
}
function usage {
echo "Usage: install.sh [-i toplevel_folder_to_install_mbk -x soft name -h -H]
Options:
-C - Conda installation mode
-T - skip installation of taxonkit
-h - print this help information"
}
## by default install all software
MODE=all
DEBUG=0
SKIP_taxonkit=0
SKIP_R_packages=0
SKIP_blast=0
SKIP_taxonomy_db=0
CONDA_INSTALL=0
while getopts "i:x:CThH" Option
do
case $Option in
i ) INSTALL_DIR=$OPTARG;;
x ) MODE=$OPTARG;;
T ) SKIP_taxonkit=1;;
C ) CONDA_INSTALL=1;;
h ) usage; exit;;
H ) usage; exit;;
* ) usage; exit 1;;
esac
done
if [ ! -e $INSTALL_DIR ]; then
echo "Creating $INSTALL_DIR..."
mkdir -p $INSTALL_DIR
echo "Creating $INSTALL_DIR...done."
fi
if [ "x`uname`" == "xLinux" ] ; then
## readlink does not work in MacOS
##
INSTALL_DIR=$(readlink -f $INSTALL_DIR)
fi
TMP_DIR=$(mktemp -d)
mkdir -p $TMP_DIR
#BLAST_IDIR=$INSTALL_DIR/blast/${blast_VERSION}
BLAST_IDIR=$INSTALL_DIR
if [ "$CONDA_INSTALL-" == "1-" ]; then
SKIP_taxonkit=1
SKIP_R_packages=1
SKIP_blast=1
fi
if [ "$MODE-" == "all-" ]; then
for t in $ALL_TOOLS; do
varn="SKIP_$t"
case ${!varn} in
1 ) echo "skipping installation of $t ";;
* ) install_$t
esac
done
else
install_$MODE
fi
echo "---------------------------------------------------"
echo "metabinkit and dependecies installed on $INSTALL_DIR"
echo "All done."
exit 0