-
Notifications
You must be signed in to change notification settings - Fork 0
/
dssp2pdb.pl
executable file
·246 lines (223 loc) · 6.66 KB
/
dssp2pdb.pl
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
#! /usr/bin/perl -w
$dssp2pdb_version = "0.03" ;
# dssp2pdb
# converts dssp type output to HELIX/SHEET lines for PDB files
# distributed under gnu public license
# copyright James Stroud 2002
#https://github.com/ivanamihalek/perlscr/blob/master/translation/dssp2pdb.pl
#version history
#0.01
# original version
#0.02
# added "-3" for 3(10) helices
# added "-5" for pi helices
# allowed for modified amino acids ("X" in dssp output)
# fixed bug that choked on blank chain label in dssp output
#0.03
# dispenses helix/sheet lines of original pdb
$true = 1 ;
$false = 0 ;
$helix = "HELIX" ;
$sheet = "SHEET" ;
use Getopt::Std ;
$opt_3 = $false ;
$opt_5 = $false ;
getopts ('35') ;
$helices_310 = $opt_3 ; # flag for 3(10) helices
$helices_pi = $opt_5 ; # flag for pi helices
sub printhelp() {
print STDERR <<EOF ;
************************************************************************
** dssp2pdb version $dssp2pdb_version (c) James Stroud, 2002
** provided under the gnu public license
** james.stroud\@colorado.edu
************************************************************************
** Converts dssp file to HELIX/SHEET type lines for PDB files
** dssp2pdb will insert HELIX/SHEET lines above ATOM lines if
** "pdbfile.pdb "is provided
** When the "-3" flag is set, 3(10) helices will result in HELIX lines
** When the "-5" flag is set, pi helices will result in HELIX lines
************************************************************************
** Usage: dssp2pdb [-35] dsspfile.dssp [pdbfile.pdb] > new_pdbfile.pdb
************************************************************************
EOF
}
if (! $ARGV[0]) {
printhelp() ;
exit ;
}
%iupac = ( A => ALA,
C => CYS,
D => ASP,
E => GLU,
F => PHE,
G => GLY,
H => HIS,
I => ILE,
K => LYS,
L => LEU,
M => MET,
N => ASN,
P => PRO,
Q => GLN,
R => ARG,
S => SER,
T => THR,
V => VAL,
W => TRP,
Y => TYR,
X => UNK, ) ; # UNK courtesy of Dirk Kostrewa
sub printss() {
print @comments ;
$number = 0 ;
$helixcount = 0 ;
$sheetcount = 0 ;
while ($number < $elements) {
if ($eletype[$number] eq $helix) {
$helixcount++ ;
$length = $resnum2[$number] - $resnum1[$number] + 1 ;
( defined $restype1[$number]) || ( $restype1[$number] = "UNK");
( defined $restype2[$number]) || ( $restype2[$number] = "UNK");
printf "HELIX %4d %3d $restype1[$number] $reschain1[$number]%5d ".
"$restype2[$number] $reschain2[$number]%5d%3d".
" %3d\n",
($helixcount, $helixcount, $resnum1[$number], $resnum2[$number], 1, $length) ;
}
if ($eletype[$number] eq $sheet) {
$sheetcount++ ;
( defined $restype1[$number]) || ( $restype1[$number] = "UNK");
( defined $restype2[$number]) || ( $restype2[$number] = "UNK");
printf "SHEET %4d %3d 1 $restype1[$number] $reschain1[$number]%4d ".
"$restype2[$number] $reschain2[$number]%4d 0\n",
($sheetcount, $sheetcount, $resnum1[$number], $resnum2[$number]) ;
}
$number++ ;
}
}
$dsspfile = $ARGV[0] ;
$comments[0] = "REMARK 1 secondary structure assigned by dssp\n" ;
$comments[1] = "REMARK 2 dssp output converted by dssp2pdb version $dssp2pdb_version\n" ;
open (DSSP, $dsspfile) or die "Could not open file \"$dsspfile\"\n" ;
$helixcount = 0 ;
$sheetcount = 0 ;
#
# loop to find start of ss info
#
while () {
$line = <DSSP> ;
if (! $line) {
printhelp() ;
print STDERR "\n\"$dsspfile\" does not seem to be dssp output\n\n" ;
exit ;
}
if ($line =~ /RESIDUE AA STRUCTURE/) { # ready to cull ss info
last ;
}
}
#
# loop to cull ss info from dssp file
#
$residues = 0 ; # will eventually become number of residues in file
while () {
$line = <DSSP> ;
if (! $line) {
last ;
}
$resid[$residues] = substr ($line, 5, 5) ;
$chain[$residues] = substr ($line, 11, 1) ;
$aa[$residues] = $iupac{substr ($line, 13, 1)} ;
$ss[$residues] = substr ($line, 16, 1) ;
$residues++ ;
}
close (DSSP) ;
#
# loop to parse ss info from data structures
#
$elements = 0 ; # index to keep track of ss elements we are on
$helixcount = 0 ; # number of helices
$sheetcount = 0 ; # number of sheets
$number = 0 ; # residue number, index of this loop
$last_type = "" ;
while($number < $residues) {
$current_type = "" ; # type of ss elements, will have value only if HELIX or SHEET
if ($ss[$number] eq "H") {
$current_type = $helix ;
}
if ($ss[$number] eq "E") {
$current_type = $sheet ;
}
if ($ss[$number] eq "G" && $helices_310) {
$current_type = $helix ;
}
if ($ss[$number] eq "I" && $helices_pi) {
$current_type = $helix ;
}
if ($current_type eq $helix) {
if ($current_type eq $last_type) {
# extension of helix
$restype2[$elements-1] = $aa[$number] ;
$resnum2[$elements-1] = $resid[$number] ;
$reschain2[$elements-1] = $chain[$number] ;
} else {
# new helix
$helixcount++ ;
$eletype[$elements] = $helix ;
$restype1[$elements] = $aa[$number] ;
$resnum1[$elements] = $resid[$number] ;
$reschain1[$elements] = $chain[$number] ;
$restype2[$elements] = $aa[$number] ;
$resnum2[$elements] = $resid[$number] ;
$reschain2[$elements] = $chain[$number] ;
$elements++ ;
}
}
if ($current_type eq $sheet) {
if ($current_type eq $last_type) {
# extension of strand
$restype2[$elements-1] = $aa[$number] ;
$resnum2[$elements-1] = $resid[$number] ;
$reschain2[$elements-1] = $chain[$number] ;
} else {
# new strand
$sheetcount++ ;
$eletype[$elements] = $sheet ;
$restype1[$elements] = $aa[$number] ;
$resnum1[$elements] = $resid[$number] ;
$reschain1[$elements] = $chain[$number] ;
$restype2[$elements] = $aa[$number] ;
$resnum2[$elements] = $resid[$number] ;
$reschain2[$elements] = $chain[$number] ;
$elements++ ;
}
}
$last_type = $current_type ;
$number++ ;
}
$first_atom = $true ;
if ($ARGV[1]) {
$pdbfile = $ARGV[1] ;
open (PDB, $pdbfile) or die "Could not open file \"$pdbfile\"\n" ;
#
# loop to print pdb file lines before ATOM lines
#
while () {
$line = <PDB> ;
if (! $line) {
if ($first_atom) {
printhelp() ;
print STDERR "\n\"$pdbfile\" does not seem like a pdb file\n\n" ;
exit ;
} else { exit }
}
if ($line =~ /^ATOM/ and $first_atom) { # print out ss info
printss() ;
$first_atom = $false ;
}
if ($line !~ /^HELIX/ and $line !~/^SHEET/) {
print $line ;
}
}
} else {
printss() ;
}
exit ;