-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_databases.sh
executable file
·166 lines (147 loc) · 5.83 KB
/
install_databases.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
#!/bin/bash
# This program 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 program 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.
# A copy of the GNU General Public License is available at
# http://www.gnu.org/licenses/gpl-3.0.html
# ------------------------------------------------------------------
# Author: Amine Ghozlane ([email protected])
# Title: 16S-18S-23S-28S-ITS pipeline
# Description : De novo 16S-18S-23S-28S-ITS pipeline assignation
# ------------------------------------------------------------------
function say {
# echo green
echo -e "\033[1;32m* $1\033[0m" >&2
}
function check_soft {
if type $1 > /dev/null 2>&1;
then
echo $1
else
echo $2
fi
}
function timer()
{
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local stime=$1
etime=$(date '+%s')
if [[ -z "$stime" ]]; then stime=$etime; fi
dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
printf '%d:%02d:%02d' $dh $dm $ds
fi
}
#############
# Variables #
#############
SCRIPTPATH=$(readlink -e $(dirname "${BASH_SOURCE[0]}"))
databases_dir="$SCRIPTPATH/databases/"
#############
# Databases #
#############
blast_databases="$SCRIPTPATH/blast_indexing.txt"
bowtie2_databases="$SCRIPTPATH/bowtie2_indexing.txt"
md5_check="$SCRIPTPATH/md5_check.txt"
NbProc=$(grep -c ^processor /proc/cpuinfo)
url_list="$SCRIPTPATH/url_list.txt"
############
# Programs #
############
bowtie2_build=$(check_soft "bowtie2-build" "$SCRIPTPATH/bowtie2-2.2.9/bowtie2-build")
makeblastdb=$(check_soft "makeblastdb" "$SCRIPTPATH/ncbi-blast-2.5.0+/bin/makeblastdb")
makembindex=$(check_soft "makembindex" "$SCRIPTPATH/ncbi-blast-2.5.0+/bin/makembindex")
########
# Main #
########
# Start timer
say "Start databases preparation for MASQUE"
wall_time=$(timer)
# Download databases
say "Download databases: 2.4GB will be download."
start_time=$(timer)
wget -i $url_list -P $databases_dir
say "Elapsed time to download : $(timer $start_time)"
# Check md5sum
say "Check md5sum"
start_time=$(timer)
cd $SCRIPTPATH/databases/ && md5sum -c $md5_check
cd $SCRIPTPATH/
say "Elapsed time to check md5 : $(timer $start_time)"
# Decompress database
say "Decompress databases"
start_time=$(timer)
gunzip $databases_dir/*.gz
for zipfiles in $(ls $databases_dir/*.zip)
do
unzip -j $zipfiles -d $databases_dir
done
say "Elapsed time to decompress databases: $(timer $start_time)"
# Homo sapiens one file
say "Prepare Homo sapiens database"
start_time=$(timer)
cat $databases_dir/hs_ref_GRCh38.p7_*.fa > $databases_dir/homo_sapiens.fna
say "Elapsed time for Homo sapiens database: $(timer $start_time)"
# Mus musculus one file
say "Prepare Mus musculus database"
start_time=$(timer)
cat $databases_dir/mm_ref_GRCm38.p4_*.fa > $databases_dir/mus_musculus.fna
say "Elapsed time for Mus musculus database: $(timer $start_time)"
# Anopheles_stephensi one file
say "Prepare Anopheles stephensi database"
start_time=$(timer)
mv $databases_dir/ALPR02.1.fsa_nt $databases_dir/anopheles_stephensi.fna
say "Elapsed time for Anopheles stephensi database: $(timer $start_time)"
# Dario rerio one file
say "Prepare Dario rerio database"
start_time=$(timer)
cat $databases_dir/dr_ref_GRCz10_*.fa > $databases_dir/danio_rerio.fna
say "Elapsed time for Dario rerio database: $(timer $start_time)"
# Homo sapiens one file
say "Prepare Unite database"
start_time=$(timer)
sed "s:|reps|: :g" $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta -i
sed "s:|refs|: :g" $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta -i
sed "s:|reps_singleton|: :g" $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta -i
sed "s:|refs_singleton|: :g" $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta -i
iconv -c -f utf-8 -t ascii//TRANSLIT $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta > $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta_ascii
mv $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta_ascii $databases_dir/sh_general_release_dynamic_s_20.11.2016.fasta
say "Elapsed time for Unite database: $(timer $start_time)"
# Blast indexing
say "Indexing databases for blast"
start_time=$(timer)
while read fasta_file
do
$makeblastdb -in $databases_dir/$fasta_file -dbtype nucl
$makembindex -input $databases_dir/$fasta_file -iformat blastdb
done < $blast_databases
say "Elapsed time to index for blast: $(timer $start_time)"
# Bowtie2 indexing
say "Indexing databases for bowtie2 require at least 50Gb of memory"
start_time=$(timer)
while read fasta_file
do
version=$($bowtie2_build --version |grep "bowtie2-build version"|cut -f 3 -d ' ')
if [ "$version" == "2.2.9" ]
then
$bowtie2_build --threads $NbProc $databases_dir/$fasta_file $databases_dir/$fasta_file
else
$bowtie2_build $databases_dir/$fasta_file $databases_dir/$fasta_file
fi
done < $bowtie2_databases
say "Elapsed time to index for bowtie2: $(timer $start_time)"
# Cleanup
say "Cleanup the installation"
start_time=$(timer)
rm -f $databases_dir/*.zip $databases_dir/sh_general_release_dynamic_31.01.2016_dev.fasta $databases_dir/README.txt $databases_dir/._README.txt $databases_dir/ITSdb.findley.taxonomy $databases_dir/._ITSdb.findley.fasta $databases_dir/._ITSdb.findley.taxonomy $databases_dir/._ITSdb_v1 $databases_dir/hs_ref_GRCh38.p7_*.fa $databases_dir/mm_ref_GRCm38.p4_*.fa $databases_dir/dr_ref_GRCz10_*.fa
say "Elapsed time to clean : $(timer $start_time)"
say "Databases preparation is done. Elapsed time: $(timer $wall_time)"