-
Notifications
You must be signed in to change notification settings - Fork 44
/
dssp2gp.bsh
339 lines (298 loc) · 12.6 KB
/
dssp2gp.bsh
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
usage="\
>>>>>>>>>>>>>>>> dssp2gp <<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>> Jicun Li <<<<<<<<<<<<<<<<
>>>>>>>>>> 2024-09-21 23:50:22 <<<<<<<<<
Usage: dssp2gp <file.dat|file.xpm> [-DRAW] [-COLOR] [RANGE]
[-t0 t0] [-dt dt] [-tu tu]
Default: dssp2gp dssp.dat -xyz -pdb 1:1E9:1 -t0 0 -dt 1 -tu ps
option: DRAW:
-xyz: xyz data
-box: plain box
-fancy: fancy helix and beta sheet
COLOR: gmx, vmd, pdb, rcsb, taylor, p1, p2, p3, p4
RANGE: [minRes:maxRes:ystart]
minRes: start from #residue
maxRes: end with #residue
ystart: y value of minRes
-t0: starting time
-dt: timestep
-tu: unit of time, fs, ps, ns
--------------------------------------------------------------------------------
Log:
2024-09-21: fix bugs of color
add 2 more ss~count plots
2024-03-06: option bugs for -t0 -dt -tu
--------------------------------------------------------------------------------"
# H = "A-Helix" 4-turn RH helix (α helix). Min length 4 residues.
# G = "3-Helix" 3-turn RH helix (3_10 helix). Min length 3 residues.
# I = "5-Helix" 5-turn RH helix (π helix). Min length 5 residues.
# P = "PPII-Helix" LH
# E = "B-Sheet" extended strand (in beta ladder) in parallel
# and/or anti-parallel β-sheet conformation. Min length 2 residues.
# B = "B-Bridge" beta-bridge residue. residue in isolated β-bridge
# (single pair β-sheet hydrogen bond formation)
# T = "Turn" H-bonded turn (3, 4 or 5 turn)
# S = "Bend" bend (the only non-hydrogen-bond based assignment)
# ~ = "Coil" C, loops/coil (residues which are not in any of the above conformations)
[[ $# -lt 1 ]] && { echo "$usage"; exit; }
ssmode="xyz"; color="pdb"
minRes=1; maxRes=1E9; ystart=1;
t0=0; dt=1; tu=ps
opt=($@); N=${#opt[@]};
for((i=0; i<N; i++)); do
arg=${opt[$i]}; j=$((i+1)); val=${opt[$j]}
[[ $arg =~ (-xyz)|(-box)|(-fancy) ]] && { ssmode=${arg/-/}; opt[$i]=""; }
[[ $arg =~ (-gmx)|(-vmd)|(-pdb) ]] && { color=${arg/-/}; opt[$i]=""; }
[[ $arg =~ (-p1)|(-p2)|(-p3)|(-p4) ]] && { color=${arg/-/}; opt[$i]=""; }
[[ $arg =~ (-rcsb)|(-taylor) ]] && { color=${arg/-/}; opt[$i]=""; }
[[ $arg =~ -t0 ]] && { t0=$val; opt[$i]=""; opt[$j]=""; }
[[ $arg =~ -dt ]] && { dt=$val; opt[$i]=""; opt[$j]=""; }
[[ $arg =~ -tu ]] && { tu=$val; opt[$i]=""; opt[$j]=""; }
[[ $arg =~ : ]] && {
opt[$i]="";
arg=${arg//:/ }; arg=($arg); n=${#arg[@]}
[[ $n -ge 1 ]] && { minRes=${arg[0]}; ystart=$minRes; }
[[ $n -ge 2 ]] && { maxRes=${arg[1]}; }
[[ $n -ge 3 ]] && { ystart=${arg[2]}; }
}
done
file=${opt[@]}
awk -v file=$file -v ssmode=$ssmode -v color=$color \
-v minRes=$minRes -v maxRes=$maxRes -v ystart=$ystart \
-v x0=$t0 -v dx=$dt -v tu=$tu '
BEGIN {
name["H"] = "α-Helix" ; vss["H"] = 9;
name["G"] = "3_10-Helix" ; vss["G"] = 8;
name["I"] = "π-Helix" ; vss["I"] = 7;
name["P"] = "PPII-Helix" ; vss["P"] = 6;
name["E"] = "β-Sheet" ; vss["E"] = 5;
name["B"] = "β-Bridge" ; vss["B"] = 4;
name["T"] = "Turn" ; vss["T"] = 3;
name["S"] = "Bend" ; vss["S"] = 2;
name["~"] = "Coil" ; vss["~"] = 1;
name["="] = "Chain_Separator"; vss["="] = 0;
c["H","gmx"]="#0000FF"; c["H","vmd"]="#E182E1"; c["H","pdb"]="#E53535";
c["G","gmx"]="#808080"; c["G","vmd"]="#FFA0FF"; c["G","pdb"]="#EC6262";
c["I","gmx"]="#800080"; c["I","vmd"]="#E11414"; c["I","pdb"]="#F28E8E";
c["P","gmx"]="#008080"; c["P","vmd"]="#F28E8E"; c["P","pdb"]="#FFA0FF";
c["E","gmx"]="#FF0000"; c["E","vmd"]="#FFFF64"; c["E","pdb"]="#FFF000";
c["B","gmx"]="#000000"; c["B","vmd"]="#B4B400"; c["B","pdb"]="#D4A800";
c["T","gmx"]="#FFFF00"; c["T","vmd"]="#469696"; c["T","pdb"]="#00B266";
c["S","gmx"]="#008000"; c["S","vmd"]="#00CC00"; c["S","pdb"]="#00CC00";
c["~","gmx"]="#BBBBBB"; c["~","vmd"]="#000000"; c["~","pdb"]="#000000";
c["=","gmx"]="#E6E6E6"; c["=","vmd"]="#FFFFFF"; c["=","pdb"]="#FFFFFF";
# p1: 10.1371/journal.pone.0178333 p2: 10.1371/journal.pcbi.1007487
c["H","p1"]="#00FF00"; c["H","p2"]="#0171B6"; c["H","p3"]="#FFFF00";
c["G","p1"]="#2E8B57"; c["G","p2"]="#D16000"; c["G","p3"]="#FE7D6D";
c["I","p1"]="#008000"; c["I","p2"]="#C12323"; c["I","p3"]="#C12323";
c["P","p1"]="#00CC00"; c["P","p2"]="#FCAEE5"; c["P","p3"]="#FCAEE5";
c["E","p1"]="#0000FF"; c["E","p2"]="#019E73"; c["E","p3"]="#000080";
c["B","p1"]="#3399FF"; c["B","p2"]="#CA9261"; c["B","p3"]="#00FFFF";
c["T","p1"]="#FF8C00"; c["T","p2"]="#008000"; c["T","p3"]="#006400";
c["S","p1"]="#FF0000"; c["S","p2"]="#BFBFBF"; c["S","p3"]="#FF0000";
c["~","p1"]="#000000"; c["~","p2"]="#000000"; c["~","p3"]="#BFBFBF";
c["=","p1"]="#FFFFFF"; c["=","p2"]="#FFFFFF"; c["=","p3"]="#FFFFFF";
# taylor: 10.1186/s12859-020-3526-6
c["H","p4"]="#C78CB5"; c["H","rcsb"]="#EA357F"; c["H","taylor"]="#65FF00";
c["G","p4"]="#465C9F"; c["G","rcsb"]="#91207C"; c["G","taylor"]="#C9FF01";
c["I","p4"]="#DF3431"; c["I","rcsb"]="#57137B"; c["I","taylor"]="#03C9FC";
c["P","p4"]="#FE7D6D"; c["P","rcsb"]="#9F2EF5"; c["P","taylor"]="#FD3300";
c["E","p4"]="#F3EF41"; c["E","rcsb"]="#F7C945"; c["E","taylor"]="#0001FB";
c["B","p4"]="#C1BD38"; c["B","rcsb"]="#6582F7"; c["B","taylor"]="#6201FC";
c["T","p4"]="#2A87A0"; c["T","rcsb"]="#4FAF6D"; c["T","taylor"]="#FF57D8";
c["S","p4"]="#A5A7F4"; c["S","rcsb"]="#83D5C9"; c["S","taylor"]="#FF6500";
c["~","p4"]="#000000"; c["~","rcsb"]="#E93464"; c["~","taylor"]="#000000";
c["=","p4"]="#FFFFFF"; c["=","rcsb"]="#FFFFFF"; c["=","taylor"]="#FFFFFF";
isXPM=match(file, /\.xpm$/)
xyz=0; if(ssmode=="xyz") xyz=1;
fx=.5; if(ssmode=="box") fx=1;
nx=0; ny=0; ix=1; dy=1
fileName=file; sub(/\.[^\.]+$/, "", fileName)
}
isXPM && /x-label:/ { sub(/.*\(/,""); sub(/).*/,""); tu=$0; next }
isXPM && ix && /x-axis/ { ix=0; x0=$3; dx=$4-x0; next }
isXPM && NF==1 { gsub(/[",\n\r]/, ""); zv[ny++]=$0; next } #"
!isXPM && NF>0 { zv[nx++]=$0 }
END { Pi=4*atan2(1,1)
if(isXPM) nx=length(zv[1])
else ny=length(zv[1])
if(ny<maxRes) maxRes=ny
print "# α-Helix 3_{10}-Helix π-Helix PPII-Helix β-Sheet β-Bridge Turn Bend Coil"
n=split("gmx vmd pdb rcsb taylor p1 p2 p3 p4 "color, arr)
for(i=1; i<=n; i++) {
for(v=9; v>=1; v--) {
for(ss in vss) if(vss[ss]==v) printf "c"v"=\""c[ss, arr[i]]"\"; ";
}
print "#"arr[i]
}
if(!xyz) {
fun["H"] = "H"; fun["G"] = "G"; fun["I"] = "I"; fun["P"] = "P";
fun["E"] = "E"; fun["B"] = "B"; fun["T"] = "T"; fun["S"] = "S";
fun["~"] = "C";
for(ss in fun)
printf "%s(n)=sprintf(\"set obj %%d fc rgb \\\"%%s\\\" " \
"fs solid border lw 1;\", n, c%d)\n", fun[ss], vss[ss]
print ""
Nh=10; dt=1./Nh; t=-dt;
for(i=0; i<=Nh; i++) {
t += dt
Hy[i]=Hy[2*Nh-i]=t*dy
Hx[i]=Hx[2*Nh-i]=fx*dx*sin(2*Pi*t)/2.
}
d=0; Nt=10; dt=1./Nt; t=-dt
for(i=0; i<=Nt; i++) {
t += dt;
Ty[i]=Ty[2*Nt-i]=dy*t
Tx[i]=Tx[2*Nt-i]=(t<d || t>1-d) ? 0 : dx*fx*((.5-t)^2/(.5-d)^2-1)/2.
}
Ns=10; dt=1./Ns; t=-dt;
for(i=0; i<=Ns; i++) {
t += dt
Sy[i]=Sy[2*Ns-i]=dy*t
Sx[i]=Sx[2*Ns-i]=dx*fx*(t<0.5 ? t: 1-t)
}
}
Fcount=fileName"~count.gp"
printf "$data <<EOD\n# residue index: %d-%d\n" \
"# Time(%s) %11s%11s%11s%11s%11s%11s%11s%11s%11s%16s\n",
minRes, maxRes, tu,
name["H"], name["G"], name["I"], name["P"],
name["E"], name["B"], name["T"], name["S"],
name["~"], name["="] >Fcount
nobj=0
if(xyz) print "\n$data <<EOD"
for(i=0; i<nx; i++) {
nss["H"] =0; nss["G"] =0; nss["I"] =0; nss["P"] =0; nss["~"] =0
nss["E"] =0; nss["B"] =0; nss["T"] =0; nss["S"] =0; nss["="] =0
x = x0+i*dx
for(j=minRes-1; j<maxRes; j++) {
y = ystart+(j+1-minRes)*dy
if(isXPM) txt=substr(zv[ny-1-j], i+1, 1)
else txt=substr(zv[i], j+1, 1)
nss[txt]++; type[j]=txt
if(xyz) print x, y, vss[txt]
}
printf "%15.6f%11d%11d%11d%11d%11d%11d%11d%11d%11d%11d\n", x,
nss["H"], nss["G"], nss["I"], nss["P"],
nss["E"], nss["B"], nss["T"], nss["S"],
nss["~"], nss["="] >Fcount
if(!xyz) {
for(j=minRes-1; j<maxRes; j++) {
y = ystart+(j+1-minRes)*dy
for(jj=j+1; jj<maxRes && type[jj]==type[j]; jj++) type[jj]=""
if(type[j]) print obj(type[j], x, y, ystart+(jj-minRes)*dy, dx*fx, dy)
}
}
}
print "EOD" \
"\n\nt= \"α-Helix 3_{10}-Helix π-Helix PPII-Helix β-Sheet β-Bridge Turn Bend Coil \"" >Fcount
n=split("gmx vmd pdb rcsb taylor p1 p2 p3 p4 "color, arr)
for(i=1; i<=n; i++) {
printf "c= \"">fileName"~count.gp"
for(v=9; v>=1; v--) {
for(ss in vss) if(vss[ss]==v) printf c[ss, arr[i]]" " >Fcount
}
print "\" #"arr[i] >Fcount
}
print "\nset term pngcairo enhanced truecolor font \"HelveticaNeueLT Pro 85 Hv,85\" \\" \
"\n\tfontscale 1 linewidth 20 pointscale 5 size 6000,4000" \
"\nset tics out nomirror;" \
"\nset key out reverse Left spacing 2 samplen 1/2" \
"\n\nf=100./"ny \
"\nset xl\"Time("tu")\"; set yl\"res%\"" \
"\nset xr [0:"(x)"]; set yr [0:100]" \
"\n\nset output \"ss~count.png\"" \
"\nplot $data u 1:(100) w filledcur y=0 fc rgb word(c, 1) t word(t, 1), \\" \
"\nfor[i=2:9] $data u 1:(100-sum[k=2:i]column(k)*f) w filledcur y=0 fc rgb word(c, i) t word(t, i)" \
"\n\nset output \"ss~count-sm.png\"" \
"\nplot $data u 1:(100) sm bezier w filledcur y=0 fc rgb word(c, 1) t word(t, 1), \\" \
"\nfor[i=2:9] $data u 1:(100-sum[k=2:i]column(k)*f) sm bezier w filledcur y=0 fc rgb word(c, i) t word(t, i)" \
"\n\nset output \"ss~count-hist.png\"" \
"\nset style data histogram" \
"\nset style histogram rowstacked" \
"\nset style fill solid" \
"\nplot for [i=10:2:-1] $data u (column(i)*f) lw 0 lc rgb word(c, i-1) t word(t, i-1)" >Fcount
if(!xyz) print "\n$data <<EOD\n0 0 0\n0 0 0\n0 0 0\n0 0 0"
print "EOD\n"
print "\nset pal defined( \\"
print "\t0.5 c1, 1.5 c1, 1.5 c2, 2.5 c2, 2.5 c3, 3.5 c3, \\"
print "\t3.5 c4, 4.5 c4, 4.5 c5, 5.5 c5, 5.5 c6, 6.5 c6, \\"
print "\t6.5 c7, 7.5 c7, 7.5 c8, 8.5 c8, 8.5 c9, 9.5 c9 )"
print "set cbtics ( \\"
print "\t\"C Coil \" 1, \\"
print "\t\"S Bend \" 2, \\"
print "\t\"T Turn \" 3, \\"
print "\t\"B β-Bridge \" 4, \\"
print "\t\"E β-Sheet \" 5, \\"
print "\t\"P PPII-Helix \" 6, \\"
print "\t\"I π-Helix \" 7, \\"
print "\t\"G 3_{10}-Helix\" 8, \\"
print "\t\"H α-Helix \" 9 )"
print "set cbr [.5:9.5]\n"
print "set output \"ss.png\""
print "set term pngcairo enhanced truecolor font \"HelveticaNeueLT Pro 85 Hv,85\" \\"
print "\tfontscale 1 linewidth 20 pointscale 5 size 6000,4000"
print "set tics out nomirror;"
print "set key out reverse Left spacing 2 samplen 1/2"
print "set xl\"Time("tu")\"; set yl\"#res\";"
print "plot ["x0-dx/2":"x0+(nx-1)*dx+dx/2"] " \
"["ystart":"ystart+(maxRes-minRes)*dy"] $data u 1:2:3 w imag notit"
}
function obj(type, x, y1, y2, dx, dy, i,y, x1, x2) {
if(ssmode=="box") {
nobj++
x1 = x-dx/2; y1 -= dy/2
x2 = x+dx/2; y2 += dy/2
return "set obj "nobj" poly from " \
x1","y1" to "x1","y2" to " \
x2","y2" to "x2","y1" to "x1","y1"; eval "fun[type]"("nobj")"
}
if(type=="H" || type=="G" || type=="I" || type=="P") {
str=""
fdir=1; if(type=="P") fdir=-1
for(y=y1; y<=y2; y+=dy) {
nobj++
str=str"set obj "nobj" poly from "x+fdir*Hx[0]","y+Hy[0]-dy/2
for(i=1; i<=2*Nh; i++) str=str" to "x+fdir*Hx[i]","y+Hy[i]-dy/2
str=str"; eval "fun[type]"("nobj")\n"
}
return str
}
if(type=="S") {
str=""
for(y=y1; y<=y2; y+=dy) {
nobj++
str=str"set obj "nobj" poly from "x+Sx[0]","y+Sy[0]-dy/2
for(i=1; i<=2*Ns; i++) str=str" to "x+Sx[i]","y+Sy[i]-dy/2
str=str"; eval "fun[type]"("nobj")\n"
}
return str
}
if(type=="T") {
nobj++
y1 -= dy/2; y2 += dy/2
str="set obj "nobj" poly from "x+Tx[0]","y1+(y2-y1)*Ty[0]
for(i=1; i<=2*Nt; i++) str=str" to "x+Tx[i]","y1+(y2-y1)*Ty[i]
return str"; eval "fun[type]"("nobj")"
}
if(type=="B") {
nobj++
return "set obj "nobj" poly from " \
x-dx/2","y1-dy/2" to "x","y2+dy/2" to " \
x+dx/2","y1-dy/2" to "x-dx/2","y1-dy/2"; eval "fun[type]"("nobj")"
}
if(type=="E") {
nobj++
return "set obj "nobj" poly from " \
x-dx/4","y1-dy/2" to "x-dx/4","y2 " to " \
x-dx/2","y2 " to "x ","y2+dy/2 " to " \
x+dx/2","y2 " to "x+dx/4","y2 " to " \
x+dx/4","y1-dy/2" to "x-dx/4","y1-dy/2 "; eval "fun[type]"("nobj")"
}
if(type=="~") {
nobj++
return "set obj "nobj" poly from " \
x","y1-dy/2" to "x","y2+dy/2" to "x","y1-dy/2 "; eval "fun[type]"("nobj")"
}
}
' $file > ${file%.*}.gp