-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmysql-q.sh
executable file
·193 lines (167 loc) · 4.68 KB
/
mysql-q.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
#! /usr/bin/bash
db_location='/home/common/babel'
export db_location
array_opt=( Pstv Ngtv abonds atoms bonds cansmi cansmiNS dbonds formula HBA1
HBA2 HBD InChI InChIKey logP MP MR MW nF sbonds tbonds TPSA heavya)
help_txt="To search the databases you need:
1. Specify the database(s) by using the --db $(echo -e "\e[4mnameofdb\e[0m") arguement, one or multiple times
2. Optionally use filters with --max-$(echo -e "\e[4mSUFFIX\e[0m") or --min-$(echo -e "\e[4mSUFFIX\e[0m"). Available suffixes:
$(echo ${array_opt[*]} | fold -s -w 80 | sed -e "s|^|\t- |g")
When run without enough valid vina options, you will only receive the results of your query.
Otherwise the script will automatically run the resulting ligands to your specified receptor.
Vina Options:
--zinc-mode
--vina-threads
--vina-log
--vina-cfg
--vina-rcp
--vina-rlt
"
mysql_q() {
echo Searching $I 1>&2
if [ ! "$I" = 'Zinc' ] && [ ! "$I" = 'Ambinter' ]
then mysql --login-path=local -N -e "use BABEL" -e "
SELECT IF(Zinc_ext.ID IS NULL,Frog.ID,Zinc_ext.ID)
FROM ${I}
LEFT JOIN Zinc_ext ON ${I}.ID = Zinc_ext.EXT_ID
LEFT JOIN Frog ON ${I}.ID = Frog.EXT_ID
$(cat -)
;
"
else mysql --login-path=local -N -e "use BABEL" -e "
SELECT ID
FROM ${I}
$(cat -)
;"
fi
}
query_writer() {
line_start=WHERE
for i in ${array_opt[*]}
do
max_i=max_$i
min_i=min_$i
if [ "${!max_i}" ]
then if [ "${!min_i}" ]
then echo $line_start $I.\`$i\` BETWEEN ${!min_i} AND ${!max_i}
else echo $line_start $I.\`$i\` \<\= ${!max_i}
fi
line_start=AND
elif [ "${!min_i}" ]
then echo $line_start $I.\`$i\` \>\= ${!min_i}
line_start=AND
fi
done
echo $line_start $I.\`Halo\` $halo
}
vina_fun() {
mkdir "$1"
cd "$1"
obabel -ipdbqt "$db_location/pdbqt/$1.pdbqt" -opdbqt -O $1\_out.pdbqt -m &> /dev/null
for i in $(find -name \*pdbqt | sed 's/\.pdbqt//g' )
do $vina --cpu 4 --config $vina_cfg --ligand "$i.pdbqt" $vina_rcp --out "$i_out.pdbqt" &> /dev/null
rm "$i.pdbqt"
done
}
score() {
mv "$*" $(sed '2q;d' "$*" | cut -d '-' -f 2 | cut -d ' ' -f1)_$*
}
vina_wrapper() {
export vina_cfg vina_log vina_rcp out_dir vina
export -f vina_fun
(
cd $out_dir
echo Starting Docking:
parallel --eta --progress -j $((threads/4)) --joblog ../vina.job vina_fun {}
)
export -f score
(
cd $out_dir || exit 5
echo Renaming results per score:
find . -type f -printf "%f\n" |
parallel --progress -j $threads score {/}
echo Tarring $results best results.
find . -type f -printf "%f\n" | sort -h |
tail -n $results | tar zcfv ../$vina\-result_$(date +'%s').tar.gz \
--files-from -
)
echo Deleting temporary files
#rm -rf $out_dir #results
echo Results are in vina-result_$(date +'%s').tar.gz
}
results=1000
if [ -z "$*" ] 2> /dev/null
then echo --help for help
exit 2
fi
creategetargs() {
echo 'function getargs() {'
echo ' while true
do case $1 in'
for i in $*
do for I in min max
do echo -e ' '--$I-$i' \t'\) $I\_$i=\$2 ';' shift 2 ';;'
done
done
echo ' --help ) echo "$help_txt" ; exit 2 ;;
--db ) DB+=($2) ; shift 2 ;;
--zinc-mode ) zinc_mode=1 ; shift 1 ;;
--vina-threads ) threads=$2 ; export threads ; shift 2 ;;
--vina-cfg ) vina_cfg=$2 ; shift 2 ;;
--vina-rcp ) vina_rcp="--receptor $2" ; shift 2 ;;
--vina-rlt ) results="$2" ; shift 2 ;;
'\'\'' ) break ;;
* ) echo error, what is: $1 ; exit 1 ;;
esac
done'
echo '}'
}
eval "$(creategetargs ${array_opt[*]})"
getargs $*
db_loop() {
for I in ${DB[*]}
do halo='= 0'
query_writer | tee mysql | mysql_q
done > query
for I in ${DB[*]}
do halo='> 0'
query_writer | tee hmysql | mysql_q
done > haloquery
}
if [ "$vina_cfg" ]
then findoutput="$(find query -maxdepth 1 2> /dev/null)"
if [ "$findoutput" ]
then read -p "$(echo $findoutput) found, do you want to use it?" -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then echo 'Searching - this could take a lot of time (see mysql threads)'
db_loop
fi
else
echo 'Searching - this could take a lot of time (see mysql threads)'
db_loop
fi
echo
if [ -e ./query ]
then
out_dir=$(mktemp -d -p .)
vina='vina'
cat query | vina_wrapper
vina='vinaSH'
cat haloquery | vina_wrapper
fi
else
echo 'Searching - this could take a lot of time (see mysql threads)'
db_loop
read -p "Do you want the resulting pdbqts?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
out_dir=$(mktemp -d -p .)
(
cd $out_dir || exit 5
cat ../query | xargs -I{} cp $db_location/pdbqt/{}.pdbqt .
tar zcfv ../queryresults_$(date +'%s').tar.gz .
)
rm -rf $out_dir
fi
fi