-
Notifications
You must be signed in to change notification settings - Fork 10
/
install_darkhorse.sh
178 lines (154 loc) · 4.98 KB
/
install_darkhorse.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
#!/bin/bash
# ----------------------------------------------------------------------------
# Copyright (c) 2015--, The WGS-HGT Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------
# automated installation script for DarkHorse2
# this script will install:
# MySQL 5.7.18
# NCBI nr, taxdump and prot.accession2taxid (up-to-date)
# DarkHorse 2.0_rev07
# the whole system (including MySQL) will run in a local directory and won't
# affect anything outside
# usage:
# bash install_darkhorse.sh /target/directory/to/install
set -eu
# confirm target install directory
if [ $# -eq 0 ]
then
echo "usage: bash install_darkhorse.sh /target/install/directory"
exit 1
fi
appdir=$(readlink -m $1)
# download and compile MySQL source code
mkdir -p $appdir/mysql
url=https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz; wget $url || curl -O $url
tar -zxvf mysql-boost-5.7.18.tar.gz
cd mysql-5.7.18
cmake -D MYSQL_DATADIR=$appdir/mysql/data \
-D SYSCONFDIR=$appdir/mysql/etc \
-D CMAKE_INSTALL_PREFIX=$appdir/mysql \
-D WITH_BOOST=./boost .
make
make install
# clean up installation files
cd ..
rm mysql-boost-5.7.18.tar.gz
rm -rf mysql-5.7.18
# find an unused port number
# the default MySQL port is 3306
# to avoid conflict with system-wide MySQL (if any), search from 3307
port=3307
while true
do
netstat -tlnp | grep $port && ((port++)) || break
done
# create MySQL configuration file
mkdir -p $appdir/mysql/etc
echo "
[client]
port = $port
socket = $appdir/mysql/mysql.sock
[mysqld]
port = $port
socket = $appdir/mysql/mysql.sock
basedir = $appdir/mysql
datadir = $appdir/mysql/data
sql_mode = NO_ENGINE_SUBSTITUTION
[mysqld_safe]
log-error = $appdir/mysql/data/mysql.err
pid-file = $appdir/mysql/mysql.pid
" > $appdir/mysql/etc/my.cnf
export PATH=$appdir/mysql/bin:$PATH
# initialize MySQL serivce
mysqld --initialize-insecure
sleep 60
# start MySQL serivce
mysqld &
sleep 60
# set up MySQL account
# username: root, password: password
mysql -u root --skip-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';"
# download NCBI database
mkdir -p $appdir/ncbi
cd $appdir/ncbi
url=ftp://ftp.ncbi.nih.gov/blast/db/FASTA/nr.gz; wget $url || curl -O $url
url=ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz; wget $url || curl -O $url
url=ftp://ftp.ncbi.nih.gov/pub/taxonomy/accession2taxid/prot.accession2taxid.gz; wget $url || curl -O $url
gunzip nr.gz
mkdir -p taxdump
tar -zxvf taxdump.tar.gz -C taxdump
rm taxdump.tar.gz
gunzip prot.accession2taxid.gz
# install required Perl modules
export PERL_MM_USE_DEFAULT=1
perl -MCPAN -e 'install App::cpanminus'
cpanm DBI DBD::mysql
# download DarkHorse 2-rev07
dhv=rev07
mkdir -p $appdir/darkhorse
cd $appdir/darkhorse
url=https://github.com/spodell/Darkhorse2/archive/$dhv.tar.gz; wget $url || curl -O $url
tar -zxvf $dhv.tar.gz
mv Darkhorse2-$dhv 2-$dhv
rm $dhv.tar.gz
# patch DarkHorse scripts
# let DarkHorse connect MySQL via a custom socket
before='my $db_path = "DBI:$db_program:$db_name:$db_host:";'
after1='my $db_path = "DBI:$db_program:$db_name:$db_host;mysql_socket=".$config_params{db_socket};'
after2='my $db_path = "DBI:$db_program:$db_name:$db_host;mysql_socket=".$dh_config{db_socket};'
cd $appdir/darkhorse/2-$dhv
while read pl
do
chmod +x $pl
grep -q "%config_params" $pl \
&& sed -i "s/$before/$after1/g" $pl \
|| sed -i "s/$before/$after2/g" $pl
done <<< "$(find . -name '*.pl' -type f)"
# create DarkHorse configuration file
echo "
# DarkHorse2 configuration file for the WGS-HGT pipeline
# installation parameters
[program_directory]=$appdir/darkhorse/2-$dhv
[genbank_nr_fasta_path]=$appdir/ncbi/nr
[names_dmp_path]=$appdir/ncbi/taxdump/names.dmp
[nodes_dmp_path]=$appdir/ncbi/taxdump/nodes.dmp
[protid_taxid_dmp_path]=$appdir/ncbi/prot.accession2taxid
# database access parameters
[db_name]=dh2nr
[db_program]=mysql
[db_host]=localhost
[db_user]=root
[db_user_password]=password
[db_socket]=$appdir/mysql/mysql.sock
[max_lines_per_packet]=4000
[min_lineage_terms]=2
[min_align_coverage]=0.7
" > $appdir/darkhorse/config.txt
# create DarkHorse database
mysql -u root -ppassword -e "CREATE DATABASE dh2nr;"
# run DarkHorse installation script
perl install_darkhorse2.pl -c $appdir/darkhorse/config.txt
# stop MySQL service
mysqladmin -u root -ppassword shutdown
# finish up
echo "
Summary:
MySQL 5.7.18 has been installed at: $appdir/mysql.
user: root
password: password
port: $port
socket: $appdir/mysql/mysql.sock
DarkHorse 2-$dhv has been installed at: $appdir/darkhorse.
NCBI nr database has been downloaded at: $appdir/ncbi.
MySQL database dh2nr has been created.
To use DarkHorse, start MySQL first:
export PATH=$appdir/mysql/bin:\$PATH
mysqld &
When completed, shut down MySQL:
mysqladmin -u root -ppassword shutdown
"
echo "Task completed."