-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAF3_filter.sh
More file actions
138 lines (116 loc) · 4.14 KB
/
Copy pathAF3_filter.sh
File metadata and controls
138 lines (116 loc) · 4.14 KB
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
#!/bin/bash
OUTPUT="results.csv"
DIR=""
IPTM_THRESHOLD=""
PTM_THRESHOLD=""
SCORE_THRESHOLD=""
PAE_THRESHOLD=""
MAX_OUTPUT=""
CHAIN_ID=""
# Option parsing
while [[ $# -gt 0 ]]; do
case $1 in
--dir) DIR="$2"; shift 2 ;;
--out) OUTPUT="$2"; shift 2 ;;
--iptm) IPTM_THRESHOLD="$2"; shift 2 ;;
--ptm) PTM_THRESHOLD="$2"; shift 2 ;;
--score) SCORE_THRESHOLD="$2"; shift 2 ;;
--pae) PAE_THRESHOLD="$2"; shift 2 ;;
--max_output) MAX_OUTPUT="$2"; shift 2 ;;
--chain_id) CHAIN_ID="$2"; shift 2 ;;
--help)
echo "Usage: $0 --dir <json directory> [--out <output filename>] [--iptm <threshold>] [--ptm <threshold>] [--score <threshold>] [--pae <threshold>] [--chain_id <A-E>] [--max_output <N>] "
echo ""
echo "Options:"
echo " --dir Root directory containing JSON files (required)"
echo " --out Output CSV filename (optional, default: results.csv)"
echo " --iptm Minimum iptm value (optional)"
echo " --ptm Minimum ptm value (optional)"
echo " --score Minimum ranking_score value (optional)"
echo " --pae Maximum allowed chain_pair_pae_min value (optional)"
echo " --chain_id Chain ID (A–E) to select diagonal chain_pair_pae_min value"
echo " --max_output Limit output to top N entries sorted by average(iptm, ptm, score)"
echo " --help Show this help message"
exit 0
;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
if [ -z "$DIR" ]; then
echo "You must specify a directory."
exit 1
fi
# chain_id → index (A=0, B=1, ..., E=4)
if [ -n "$CHAIN_ID" ]; then
IDX=$(printf "%d" "'$CHAIN_ID")
IDX=$((IDX - 65))
fi
if [ -n "$CHAIN_ID" ] && { [ "$IDX" -lt 0 ] || [ "$IDX" -gt 4 ]; }; then
echo "Invalid --chain_id: $CHAIN_ID (must be A–E)"
exit 1
fi
TMPFILE=$(mktemp)
echo " --------------------------------- "
echo "|Filter AlphaFold 3 Server Outputs|"
echo "|Last modified 2026.01.26. v1.1.0|"
echo "|GIST jinlab Choi, Seung Hun|"
echo " --------------------------------- "
echo "Now processing..."
echo " --------------------------------- "
# Collect data
find "$DIR" -type f -name "*summary_confidences*.json" \
| grep -vE '_job_[0-9]+_summary_confidences\.json$' \
| while read FILE; do
iptm=$(jq '.iptm' "$FILE")
ptm=$(jq '.ptm' "$FILE")
ranking_score=$(jq '.ranking_score' "$FILE")
if [ -n "$CHAIN_ID" ]; then
pae_second=$(jq ".chain_pair_pae_min[$IDX][$IDX]" "$FILE")
else
pae_second=$(jq '.chain_pair_pae_min[0][1]' "$FILE")
fi
pass=true
if [ -n "$IPTM_THRESHOLD" ] && (( $(echo "$iptm < $IPTM_THRESHOLD" | bc -l) )); then pass=false; fi
if [ -n "$PTM_THRESHOLD" ] && (( $(echo "$ptm < $PTM_THRESHOLD" | bc -l) )); then pass=false; fi
if [ -n "$SCORE_THRESHOLD" ] && (( $(echo "$ranking_score < $SCORE_THRESHOLD" | bc -l) )); then pass=false; fi
if [ -n "$PAE_THRESHOLD" ] && (( $(echo "$pae_second >= $PAE_THRESHOLD" | bc -l) )); then pass=false; fi
if [ "$pass" = true ]; then
avg=$(echo "($iptm + $ptm + $ranking_score)/3" | bc -l | tr -d ' \n')
# keep avg only for sorting, not in final output
echo "$(basename "$FILE"),$iptm,$ptm,$ranking_score,$pae_second,$avg" >> "$TMPFILE"
fi
done
# Sort by average desc, limit, then sort by filename asc
{
FINAL=$(mktemp)
if [ -n "$MAX_OUTPUT" ]; then
awk -F',' '{print $6 "," $0}' "$TMPFILE" \
| sort -t',' -k1,1nr \
| head -n "$MAX_OUTPUT" > "$FINAL"
else
awk -F',' '{print $6 "," $0}' "$TMPFILE" \
| sort -t',' -k1,1nr > "$FINAL"
fi
echo "Final jobs"
awk -F',' '{print $2}' "$FINAL" \
| sed -n 's/^\(.*_job_\([0-9]\+\)\).*/\1 \2/p' \
| awk '{
job=$1
num=$2
sub(/_job_[0-9]+$/, "", job)
print job, num, $1
}' \
| sort -k1,1 -k2,2n \
| awk '{print $3}' \
| uniq
echo "-----------------------------------------------------------------"
echo "filename,avg,iptm,ptm,ranking_score,pae_second"
awk -F',' '{
printf "%s,%.2f,%s,%s,%s,%s\n",
$2,$7,$3,$4,$5,$6
}' "$FINAL"
rm "$FINAL"
} | column -t -s, > "$OUTPUT"
rm "$TMPFILE"
echo "Results saved to $OUTPUT"
echo " --------------------------------- "