-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvoronota-volumes
executable file
·201 lines (176 loc) · 4.34 KB
/
voronota-volumes
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
#!/bin/bash
function print_help_and_exit
{
cat >&2 << EOF
'voronota-volumes' script provides a way for calculating and querying atomic volumes
with just one command (without the need to construct a pipeline from 'voronota' calls).
Basic options:
--input | -i string * input structure file in PDB or mmCIF format
--input-filter-query string input atoms filtering query parameters
--cache-dir string path to cache directory
--sum-at-end flag to print sum of areas as the last line in output
--help | -h flag to display help message and exit
Advanced options:
--atoms-query string atoms query parameters
--per-residue flag to output per-residue results
--multiple-models flag to handle multiple models in PDB file
Standard output (multiple lines):
{name} {volume}
EOF
exit 1
}
readonly ZEROARG=$0
if [[ $ZEROARG == *"/"* ]]
then
cd "$(dirname ${ZEROARG})"
export PATH="$(pwd):${PATH}"
cd - &> /dev/null
fi
export LC_ALL=C
command -v voronota &> /dev/null || { echo >&2 "Error: 'voronota' executable not in binaries path"; exit 1; }
command -v voronota-resources &> /dev/null || { echo >&2 "Error: 'voronota-resources' executable not in binaries path"; exit 1; }
INFILE=""
INPUT_FILTER_QUERY_PARAMETERS=""
ATOMS_QUERY_PARAMETERS=""
CACHE_DIRECTORY=""
MULTIPLE_MODELS_CHAINS_OPTION=""
SUM_AT_END=false
PER_RESIDUE=false
HELP_MODE=false
while [[ $# > 0 ]]
do
OPTION="$1"
OPTARG="$2"
shift
case $OPTION in
-i|--input)
INFILE="$OPTARG"
shift
;;
--input-filter-query)
INPUT_FILTER_QUERY_PARAMETERS="$OPTARG"
shift
;;
--atoms-query)
ATOMS_QUERY_PARAMETERS="$OPTARG"
shift
;;
--cache-dir)
CACHE_DIRECTORY="$OPTARG"
shift
;;
--multiple-models)
MULTIPLE_MODELS_CHAINS_OPTION="--multimodel-chains"
;;
--sum-at-end)
SUM_AT_END=true
;;
--per-residue)
PER_RESIDUE=true
;;
-h|--help)
HELP_MODE=true
;;
*)
echo >&2 "Error: invalid command line option '$OPTION'"
exit 1
;;
esac
done
if [ -z "$INFILE" ] || $HELP_MODE
then
print_help_and_exit
fi
MD5SUM_COMMAND="md5sum"
if command -v md5sum &> /dev/null
then
MD5SUM_COMMAND="md5sum"
else
MD5SUM_COMMAND="md5"
fi
command -v $MD5SUM_COMMAND &> /dev/null || { echo >&2 "Error: 'md5sum' or 'md5' executable not in binaries path"; exit 1; }
if [ ! -s "$INFILE" ]
then
echo >&2 "Error: input file does not exist"
exit 1
fi
readonly TMPLDIR=$(mktemp -d)
trap "rm -r $TMPLDIR" EXIT
voronota-resources radii > "$TMPLDIR/radii"
if [ ! -s "$TMPLDIR/radii" ]
then
echo >&2 "Error: failed to get the predefined atomic radii"
exit 1
fi
{
if [[ "$INFILE" == *".gz" ]]
then
zcat "$INFILE"
else
cat "$INFILE"
fi
} \
| voronota get-balls-from-atoms-file \
--input-format detect \
--annotated $MULTIPLE_MODELS_CHAINS_OPTION \
--radii-file $TMPLDIR/radii \
--include-heteroatoms \
| voronota query-balls \
--drop-altloc-indicators \
| voronota query-balls $INPUT_FILTER_QUERY_PARAMETERS \
> $TMPLDIR/balls
if [ ! -s "$TMPLDIR/balls" ]
then
echo >&2 "Error: no atoms in input file"
exit 1
fi
BALLS_MD5=""
if [ -n "$CACHE_DIRECTORY" ]
then
BALLS_MD5=$(cat $TMPLDIR/balls | $MD5SUM_COMMAND | awk '{print $1}')
if [ -n "$BALLS_MD5" ]
then
BALLS_MD5="${BALLS_MD5}.voronota.volumes"
if [ -s "$CACHE_DIRECTORY/$BALLS_MD5" ]
then
cp $CACHE_DIRECTORY/$BALLS_MD5 $TMPLDIR/all_volumes
fi
fi
fi
if [ ! -s "$TMPLDIR/all_volumes" ]
then
cat $TMPLDIR/balls \
| voronota calculate-contacts \
--annotated \
--volumes-output $TMPLDIR/all_volumes \
> /dev/null
if [ -n "$CACHE_DIRECTORY" ] && [ -n "$BALLS_MD5" ]
then
mkdir -p $CACHE_DIRECTORY
cp $TMPLDIR/all_volumes $CACHE_DIRECTORY/$BALLS_MD5
fi
fi
cat $TMPLDIR/all_volumes \
| awk '{print $1 " c<volume> " $2 " 1 . ."}' \
| voronota query-contacts \
--match-external-first <(cat $TMPLDIR/balls | voronota query-balls $ATOMS_QUERY_PARAMETERS) \
| \
{
if $PER_RESIDUE
then
voronota query-contacts --inter-residue --match-second 'c<volume>'
else
voronota query-contacts --match-second 'c<volume>'
fi
} \
> $TMPLDIR/result_as_contacts
{
cat $TMPLDIR/result_as_contacts
if $SUM_AT_END
then
cat $TMPLDIR/result_as_contacts \
| voronota query-contacts --summarize
fi
} \
| awk '{print $1 " " $3}' \
| column -t