forked from alexrd/SynthPDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorpdb.pl
executable file
·319 lines (261 loc) · 7.18 KB
/
colorpdb.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
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
#!/usr/bin/env perl
use strict;
use lib "/Users/alexrd/perl";
use mj qw ( %names %symb );
my $pdbfile = shift(@ARGV);
my $contactfile = shift(@ARGV);
my $seqfile = shift(@ARGV);
if (!defined $contactfile) {
$contactfile = "contact_freq.dat";
}
if (!defined $seqfile) {
$seqfile = "clustal_frag_align.dat";
}
sub help {
print("
colorpdb.pl
Usage: ./colorpdb.pl pdb_file contact_table (default: contact_freq.dat) sequence_align_file (default: clustal_frag_align.dat)
Alex Dickson
University of Michigan
This script uses a specified pdb as a template, and creates a set of pdbs with
contact frequency information in the beta factor column. Given NAME.pdb, it will output:
NAME_prot.pdb
NAME_phob.pdb
NAME_phil.pdb
NAME_water.pdb
which show the frequency of contacts with all protein amino acids, hydrophobic amino
acids, hydrophilic amino acids, and water, respectively.
This also prints out pdbs that are colored by sequence conservation:
NAME_cons_exact.pdb -- printing the frequency of exact matches
NAME_cons_type.pdb -- printing the frequency of matches by type (hydrophobic, aromatic, +ve, -ve, etc.)
It uses the both the NAME.pdb file in the current directory, as well as the aligned pdb
file in the seqalign/ directory to get the amino acid numbering after alignment.
");
exit(0);
}
my $flag = shift(@ARGV);
if ($flag eq "-h" || $flag eq "-help") {
&help;
}
if (!-f $pdbfile) {
print("Error: pdbfile does not exist!\n");
&help;
}
(my $pdb) = ($pdbfile =~ m/([0-9A-Za-z]+)\.pdb/);
my $tmp = `ls seqalign/${pdb}*`;
my @alignfiles = split(/\n/,$tmp);
if (scalar @alignfiles == 0) {
print("Error: no aligned files in the seqalign/ directory!\n");
&help;
}
my %alignseq;
# read alignfile
if (!-f $seqfile) {
print("Error! seqfile $seqfile is not defined!\n");
&help;
}
open(MYIN,$seqfile);
while (my $line = <MYIN>) {
chomp($line);
my @arr = split(/\s+/,$line);
if (defined $arr[0] && $arr[0] ne "CLUSTAL") {
$alignseq{$arr[0]} .= "$arr[1]";
}
}
close(MYIN);
(my $exactref, my $typeref) = &getcons(\%alignseq);
my @match_exact = @{$exactref};
my @match_type = @{$typeref};
my @labels;
my %resinfo;
my $firstres = undef;
# read in the table
open(MYIN,"$contactfile");
my $line = <MYIN>;
chomp($line);
my @labels = split(/ /,$line);
while ($line = <MYIN>) {
chomp($line);
my @arr = split(/ /,$line);
if (!defined $firstres) {
$firstres = $arr[0];
}
for my $i (1..@arr-1) {
$resinfo{$arr[0]}{$labels[$i]} = $arr[$i];
}
}
my @tk = keys %alignseq;
my $l = length($alignseq{$tk[0]});
my $lastres = $firstres + $l - 1;
# get avg properties: prot, phob, phil, water
my @phob = qw (val leu ile phe met);
my @phil = qw (asp asn glu gln ser lys arg his thr);
my @others = qw (gly ala cys tyr trp pro);
for my $res (keys %resinfo) {
$resinfo{$res}{"phob"} = 0;
$resinfo{$res}{"prot"} = 0;
$resinfo{$res}{"phil"} = 0;
$resinfo{$res}{"water"} = 0;
for my $lab (keys %{$resinfo{$res}}) {
for (@phob) {
if ($lab eq $_) {
$resinfo{$res}{"phob"} += $resinfo{$res}{$_};
$resinfo{$res}{"prot"} += $resinfo{$res}{$_};
}
}
for (@phil) {
if ($lab eq $_) {
$resinfo{$res}{"phil"} += $resinfo{$res}{$_};
$resinfo{$res}{"prot"} += $resinfo{$res}{$_};
}
}
for (@others) {
if ($lab eq $_) {
$resinfo{$res}{"prot"} += $resinfo{$res}{$_};
}
}
if ($lab eq "hoh") {
$resinfo{$res}{"water"} += $resinfo{$res}{$_};
}
}
}
# read through pdb, printing out new ones as you go
if (!-d "color") {
mkdir("color");
}
for my $i (0..@alignfiles-1) {
(my $alignchain) = ($alignfiles[$i] =~ m/([A-Z])\.pdb/);
open(MYIN,"$alignfiles[$i]");
my $out = $alignfiles[$i];
$out =~ s/seqalign/color/;
my $phobout = $out;
$phobout =~ s/align/phob/;
my $philout = $out;
$philout =~ s/align/phil/;
my $protout = $out;
$protout =~ s/align/prot/;
my $waterout = $out;
$waterout =~ s/align/water/;
my $exactout = $out;
$exactout =~ s/align/match_exact/;
my $typeout = $out;
$typeout =~ s/align/match_type/;
open(PHOBOUT,">$phobout");
open(PHILOUT,">$philout");
open(PROTOUT,">$protout");
open(WATEROUT,">$waterout");
open(EXACTOUT,">$exactout");
open(TYPEOUT,">$typeout");
while (my $line = <MYIN>) {
if (substr($line,0,4) eq "ATOM" || substr($line,0,6) eq "HETATM") {
my $chain = substr($line,21,1);
my $resnum = substr($line,22,4);
$resnum =~ s/\s+//;
if ($chain eq "$alignchain" && exists $resinfo{$resnum}) {
my $tline = $line;
substr($tline,55,5,sprintf("%5.2f",$resinfo{$resnum}{"phob"}));
print(PHOBOUT "$tline");
$tline = $line;
substr($tline,55,5,sprintf("%5.2f",$resinfo{$resnum}{"phil"}));
print(PHILOUT "$tline");
$tline = $line;
substr($tline,55,5,sprintf("%5.2f",$resinfo{$resnum}{"prot"}));
print(PROTOUT "$tline");
$tline = $line;
substr($tline,55,5,sprintf("%5.2f",$resinfo{$resnum}{"water"}));
print(WATEROUT "$tline");
$tline = $line;
substr($tline,55,5,sprintf("%5.2f",$match_exact[$resnum-$firstres]));
print(EXACTOUT "$tline");
$tline = $line;
substr($tline,55,5,sprintf("%5.2f",$match_type[$resnum-$firstres]));
print(TYPEOUT "$tline");
} else {
substr($line,55,5,sprintf("%5.2f",0));
print(PHOBOUT "$line");
print(PHILOUT "$line");
print(PROTOUT "$line");
print(WATEROUT "$line");
print(EXACTOUT "$line");
print(TYPEOUT "$line");
}
}
}
close(MYIN);
close(PHOBOUT);
close(PHILOUT);
close(PROTOUT);
close(WATEROUT);
close(EXACTOUT);
close(TYPEOUT);
# visualize first file
my $vmd = "/Developer/Applications/VMD\\ 1.9.1.app/Contents/MacOS/startup.command";
system("$vmd -e viscolors.tcl -args $phobout $philout $protout $waterout $exactout $typeout $firstres $lastres $alignchain");
}
sub getcons {
my %seq = %{@_[0]};
my @keys = keys %seq;
my $n = length($seq{$keys[0]});
my @exact;
my @type;
for my $i (0..$n-1) {
my %aas;
my %aas_type;
my $nused = 0;
for my $key (@keys) {
my $aa = substr($seq{$key},$i,1);
if ($aa ne "-") {
my $type = &gettype($aa);
if (!exists $aas{$aa}) {
$aas{$aa} = 0;
}
$aas{$aa}++;
if (!exists $aas_type{$type}) {
$aas_type{$type} = 0;
}
$aas_type{$type}++;
$nused++;
}
}
my $norm = $nused*($nused-1);
if ($norm > 0) {
my $sum = 0;
for (keys %aas) {
$sum += ($aas{$_}-1)*$aas{$_};
}
$exact[$i] = $sum/$norm;
$sum = 0;
for (keys %aas_type) {
$sum += ($aas_type{$_}-1)*$aas_type{$_};
}
$type[$i] = $sum/$norm;
} else {
$exact[$i] = 1;
$type[$i] = 1;
}
}
return(\@exact,\@type);
}
sub gettype {
# uses optimal amino acid grouping predicted by maximum variance (see Table I of Wrabl and Grishin, Proteins, (61) 523-534, 2005)
my $aa = lc(shift);
if ("wfy" =~ m/$aa/) {
return 0;
} elsif ("mliv" =~ m/$aa/) {
return 1;
} elsif ("c" =~ m/$aa/) {
return 2;
} elsif ("g" =~ m/$aa/) {
return 3;
} elsif ("p" =~ m/$aa/) {
return 4;
} elsif ("ats" =~ m/$aa/) {
return 5;
} elsif ("nde" =~ m/$aa/) {
return 6;
} elsif ("hqrk" =~ m/$aa/) {
return 7;
} else {
die("Error! amino acid $aa has no type");
}
}