-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftdmp-form-capri-answer
executable file
·287 lines (237 loc) · 6.11 KB
/
ftdmp-form-capri-answer
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
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
function print_help_and_exit
{
cat >&2 << 'EOF'
'ftdmp-form-capri-answer' forms CAPRI answer from ordered list of files
Options:
--input-prefix string input file path prefix, default is ''
--input-suffix string input file path suffix, default is ''
--brk string * input .brk file path
--authors string * authors string
--force-top-picks string space-separated list of picks to put in front
--align-sel string selection of atoms copy to align
--rename-chains string chain renaming rule to apply
--scoring-set string scoring set file path to produce scoring answer, default is ''
--help | -h flag to display help message and exit
Standard input:
list of structure files or IDs
Standard output:
file ready for CAPRI submission
Examples:
(echo file1.pdb ; echo file2.pdb) \
| ftdmp-form-capri-answer \
--brk input/capri.brk \
--align-sel '[-chain A]' --rename-chains 'C=E,D=F' \
> ./answer.pdb
EOF
exit 1
}
if [ -z "$1" ]
then
print_help_and_exit
fi
if [ -z "$FTDMPDIR" ]
then
export FTDMPDIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
export PATH="${FTDMPDIR}/core/voronota/expansion_js:${FTDMPDIR}:${PATH}"
fi
command -v voronota-js &> /dev/null || { echo >&2 "Error: 'voronota-js' executable not in binaries path"; exit 1; }
INPUT_PREFIX=""
INPUT_SUFFIX=""
BRKFILE=""
AUTHORS=""
FORCE_TOP_PICKS=""
ALIGN_SEL=""
RENAME_CHAINS=""
SCORING_SET_FILE=""
HELP_MODE="false"
while [[ $# > 0 ]]
do
OPTION="$1"
OPTARG="$2"
shift
case $OPTION in
--input-prefix)
INPUT_PREFIX="$OPTARG"
shift
;;
--input-suffix)
INPUT_SUFFIX="$OPTARG"
shift
;;
--brk)
BRKFILE="$OPTARG"
shift
;;
--authors)
AUTHORS="$OPTARG"
shift
;;
--force-top-picks)
FORCE_TOP_PICKS="$OPTARG"
shift
;;
--align-sel)
ALIGN_SEL="$OPTARG"
shift
;;
--rename-chains)
RENAME_CHAINS="$OPTARG"
shift
;;
--scoring-set)
SCORING_SET_FILE="$OPTARG"
shift
;;
-h|--help)
HELP_MODE="true"
;;
*)
echo >&2 "Error: invalid command line option '$OPTION'"
exit 1
;;
esac
done
if [ "$HELP_MODE" == "true" ]
then
print_help_and_exit
fi
if [ -z "$SCORING_SET_FILE" ] && [ -z "$BRKFILE" ]
then
echo >&2 "Error: neither input .brk file path nor scoring set file path provided"
exit 1
fi
if [ -z "$AUTHORS" ]
then
echo >&2 "Error: authors not provided"
exit 1
fi
if [ -z "$SCORING_SET_FILE" ] && [ ! -s "$BRKFILE" ]
then
echo >&2 "Error: input .brk file '$BRKFILE' does not exist"
exit 1
fi
if [ -n "$SCORING_SET_FILE" ] && [ ! -s "$SCORING_SET_FILE" ]
then
echo >&2 "Error: input scoring set file '$SCORING_SET_FILE' does not exist"
exit 1
fi
readonly TMPLDIR=$(mktemp -d)
trap "rm -r $TMPLDIR" EXIT
cat \
| awk '{if($1!="ID"){print $1}}' \
| egrep . \
| uniq \
> "${TMPLDIR}/input_raw"
if [ ! -s "${TMPLDIR}/input_raw" ]
then
echo >&2 "Error: no input data in stdin"
exit 1
fi
if [ -n "$FORCE_TOP_PICKS" ]
then
echo "$FORCE_TOP_PICKS" | sed 's/\s\+/\n/g' > "${TMPLDIR}/force_top_picks"
{
cat "${TMPLDIR}/force_top_picks"
cat "${TMPLDIR}/input_raw" | grep -v -x -F -f "${TMPLDIR}/force_top_picks"
} \
| uniq \
> "${TMPLDIR}/input_raw_forced"
mv "${TMPLDIR}/input_raw_forced" "${TMPLDIR}/input_raw"
fi
cat "${TMPLDIR}/input_raw" \
| awk -v prefix="$INPUT_PREFIX" -v suffix="$INPUT_SUFFIX" '{print prefix $1 suffix}' \
> "${TMPLDIR}/input"
while read -r INFILE
do
if [ ! -s "$INFILE" ]
then
echo >&2 "Error: input structure file '$INFILE' does not exist"
exit 1
fi
done < "${TMPLDIR}/input"
NUMBER_OF_MODELS="$(cat "${TMPLDIR}/input" | wc -l)"
{
cat << EOF
var params={}
params.align_sel='$ALIGN_SEL';
params.rename_chains='$RENAME_CHAINS';
params.outprefix='${TMPLDIR}/';
var input_files=[];
EOF
cat "${TMPLDIR}/input" | awk -v q="'" '{print "input_files.push(" q $1 q ");"}'
cat << 'EOF'
for(var i=0;i<input_files.length;i++)
{
voronota_import("-file", input_files[i], "-title", "model"+i);
voronota_assert_full_success("Failed to import model file '"+input_files[i]+"'");
}
voronota_pick_objects();
if(params.align_sel)
{
voronota_tmalign_many("-target", "model0", "-target-sel", params.align_sel, "-model-sel", params.align_sel);
voronota_assert_full_success("Failed to run tmalign using provided selections");
}
if(params.rename_chains)
{
voronota_set_chain_name("-chain-name", params.rename_chains);
voronota_assert_full_success("Failed to rename chains");
}
for(var i=0;i<input_files.length;i++)
{
voronota_export_atoms("-on-objects", "model"+i, "-file", params.outprefix+"model"+(i+1), "-as-pdb", "-pdb-ter");
voronota_assert_full_success("Failed to export atoms");
}
EOF
} | voronota-js --no-setup-defaults
if [ ! -s "${TMPLDIR}/model1" ] || [ ! -s "${TMPLDIR}/model${NUMBER_OF_MODELS}" ]
then
echo >&2 "Error: failed to prepare model files"
exit 1
fi
if [ -z "$SCORING_SET_FILE" ]
then
{
cat "$BRKFILE" | egrep '^HEADER|^COMPND'
echo "AUTHOR $AUTHORS"
cat "$BRKFILE" | egrep '^REMARK|^SEQRES'
seq 1 "$NUMBER_OF_MODELS" \
| while read MODELNUM
do
echo " $MODELNUM" | sed 's/.*\(....\)$/MODEL \1/'
echo "PARENT N/A"
cat "${TMPLDIR}/model${MODELNUM}"
echo "ENDMDL"
done
echo "END"
} \
> "${TMPLDIR}/answer_output"
fi
if [ -n "$SCORING_SET_FILE" ]
then
cat "${TMPLDIR}/input" | xargs -L 1 basename | sed 's/[^0-9]\+/ /g' | awk '{print $NF}' > "${TMPLDIR}/selected_model_numbers"
cat "$SCORING_SET_FILE" | egrep '^REMARK ' | egrep '^REMARK .* MODEL .* MD5 ' > "${TMPLDIR}/md5_codes"
{
if [ -n "$BRKFILE" ]
then
cat "$BRKFILE" | egrep '^HEADER|^COMPND'
else
cat "$SCORING_SET_FILE" | egrep '^HEADER|^COMPND'
fi
echo "AUTHOR $AUTHORS"
cat "${TMPLDIR}/selected_model_numbers" | while read MODELNUM
do
cat "${TMPLDIR}/md5_codes" | grep " ${MODELNUM} MD5 "
done
seq 1 "$NUMBER_OF_MODELS" \
| while read MODELNUM
do
echo " $MODELNUM" | sed 's/.*\(....\)$/MODEL \1/'
cat "${TMPLDIR}/model${MODELNUM}"
echo "ENDMDL"
done
echo "END"
} \
> "${TMPLDIR}/answer_output"
fi
cat "${TMPLDIR}/answer_output"