-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathConSurf_Grades_Parser.pm
267 lines (235 loc) · 8.04 KB
/
ConSurf_Grades_Parser.pm
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
#!/usr/bin/perl -w
##############################################################################
# ConSurf_Parser.pm
#
# This module is used for simple parsing the ConSurf grades file
# After parsing a pdb file via read(filename) function, several items can
# be retrieved via get("item name")
#
# Available item names:
# "HEADER.classification" - as in pdb specification
# "HEADER.depDate" - as in pdb specification
# "HEADER.idCode" - as in pdb specification
# "SEQRESx.raw" - amino acid list of chain x in aa one letter format
# "chains" - array of chains
#
# Note:
# The read() function does not clear previous data. It is best to
# create a new pdbParser for each file parsed.
#
# Changelog:
# 2007-Nov-10, Ofir Goldenberg - Created
##############################################################################
package ConSurf_Parser;
use strict;
# global vars
my %aa;
my %modified_residues;
my $nucleic_acid_flag = "!";
##############################################################################
# new()
# initialize object and amino acid hash conversion table
##############################################################################
sub new {
my ($class_name) = @_;
my ($self) = {};
bless ($self, $class_name);
$self->{'_created'} = 1;
# the conversion table
# !!! keys in lower case !!!
$aa{"ala"} = "A"; # Alanine
$aa{"arg"} = "R"; # Arginine
$aa{"asn"} = "N"; # Asparagine
$aa{"asp"} = "D"; # Aspartic acid
$aa{"cys"} = "C"; # Cysteine
$aa{"gln"} = "Q"; # Glutamine
$aa{"glu"} = "E"; # Glutamic acid
$aa{"gly"} = "G"; # Glycine
$aa{"his"} = "H"; # Histidine
$aa{"ile"} = "I"; # Isoleucine
$aa{"leu"} = "L"; # Leucine
$aa{"lys"} = "K"; # Lysine
$aa{"met"} = "M"; # Methionine
$aa{"phe"} = "F"; # Phenylalanine
$aa{"pro"} = "P"; # Proline
$aa{"ser"} = "S"; # Serine
$aa{"thr"} = "T"; # Threonine
$aa{"trp"} = "W"; # Tryptophan
$aa{"tyr"} = "Y"; # Tyrosine
$aa{"val"} = "V"; # Valine
# known items in SEQRES that will cause the file to be skipped
$aa{"a"} = $nucleic_acid_flag;
$aa{"t"} = $nucleic_acid_flag;
$aa{"c"} = $nucleic_acid_flag;
$aa{"g"} = $nucleic_acid_flag;
$aa{"u"} = $nucleic_acid_flag; # old style rna
$aa{"da"} = $nucleic_acid_flag;
$aa{"dt"} = $nucleic_acid_flag;
$aa{"dc"} = $nucleic_acid_flag;
$aa{"dg"} = $nucleic_acid_flag;
$aa{"du"} = $nucleic_acid_flag;
$aa{"di"} = $nucleic_acid_flag;
$aa{"5cm"} = $nucleic_acid_flag;
$modified_residues{"mse"} = "met";
$modified_residues{"asn"} = "asn";
$modified_residues{"mly"} = "lys";
$modified_residues{"hyp"} = "pro";
$modified_residues{"ser"} = "ser";
$modified_residues{"thr"} = "thr";
$modified_residues{"cme"} = "cys";
$modified_residues{"cgu"} = "glu";
$modified_residues{"sep"} = "ser";
$modified_residues{"kcx"} = "lys";
$modified_residues{"mle"} = "leu";
$modified_residues{"tpo"} = "thr";
$modified_residues{"cso"} = "cys";
$modified_residues{"ptr"} = "tyr";
$modified_residues{"dle"} = "leu";
$modified_residues{"llp"} = "lys";
$modified_residues{"dva"} = "val";
$modified_residues{"tys"} = "tyr";
$modified_residues{"aib"} = "ala";
$modified_residues{"ocs"} = "cys";
$modified_residues{"nle"} = "leu";
$modified_residues{"mva"} = "val";
return $self;
}
##############################################################################
# read(filename)
# Reads file and extracts needed data
#
# Params:
# filename - path to plain text pdb file (unzipped)
##############################################################################
sub read {
my ($self, $file) = @_;
my $line;
my $result = "1";
my $last_record_found = "";
my @chains = ();
# open file
open (PDBFILE, $file) or return 0;
# save filename we just read
$self->{'_filename'} = $file;
while ($line = <PDBFILE>)
{
chomp $line;
# HEADER record
if ($line =~ /^HEADER.*/)
{
# save data
$self->{"HEADER.classification"} = substr($line,10,40);
$self->{"HEADER.depDate"} = substr($line,50,8);
$self->{"HEADER.idCode"} = substr($line,62,4);
}
# SEQRES record
elsif ($line =~ /^SEQRES.*/)
{
# get chain id and prev data
my $chainID = substr($line,11,1);
my $seq = $self->{"SEQRES$chainID.raw"};
my $modified_residue_counter = $self->{"MODIFIED_COUNT$chainID.raw"};
my $modified_residue_list = $self->{"MODIFIED_LIST$chainID.raw"};
# skip to next line if this is a nucleic acid chain
if (defined($seq) and substr($seq,0,1) eq $nucleic_acid_flag)
{
next;
}
# check if this chain was already processed
my $chainfound = 0;
foreach my $id (@chains)
{
if ($id eq $chainID) {$chainfound = 1;}
}
if (!$chainfound)
{
push(@chains,$chainID);
$modified_residue_counter = 0;
}
# convert to one letter format
foreach my $aminoName (split(" ",substr($line,19,51)))
{
# try to convert using regular amino acid hash
my $shortName = $aa{lc($aminoName)};
# check if residue is identified
if (!defined($shortName))
{
# count this modified residue
$modified_residue_counter++;
# try to check for known modifed residues
my $std_residue_name = $modified_residues{lc($aminoName)};
# check if residue is identified
if (!defined($std_residue_name))
{
# set residue name to X
$shortName = "X";
# add message to front of modified residue list
my $modified_changed_to_X_msg = "Modified residue(s) in this chain were converted to the one letter representation 'X'\n";
if (!defined($modified_residue_list))
{
$modified_residue_list = $modified_changed_to_X_msg;
}
elsif ($modified_residue_list !~ /Modified residue/)
{
$modified_residue_list = $modified_changed_to_X_msg.$modified_residue_list;
}
}
else
{
$shortName = $aa{$std_residue_name};
my $modified_residue_name = uc($aminoName);
# add to modified residue list
if (!defined($modified_residue_list))
{
$modified_residue_list = $modified_residue_name."->".uc($std_residue_name)."\n";
}
elsif ($modified_residue_list !~ /$modified_residue_name/)
{
$modified_residue_list .= $modified_residue_name."->".uc($std_residue_name)."\n";
}
}
}
# check if we found nucleic acid
elsif ($shortName eq $nucleic_acid_flag)
{
$seq = $nucleic_acid_flag."101 this chain contains nucleic acid";
last;
}
# add one letter code to sequence
$seq .= $shortName;
}
# save data
$self->{"SEQRES$chainID.raw"} = $seq;
$self->{"MODIFIED_COUNT$chainID.raw"} = $modified_residue_counter;
$self->{"MODIFIED_LIST$chainID.raw"} = $modified_residue_list;
# we are at the last section of intrest
$last_record_found = "SEQRES";
}
# exit if last record was read (we passed the last section of intrest)
if (length($last_record_found)>0 and $last_record_found ne substr($line,0,length($last_record_found)))
{
last;
}
}
# save chain list
$self->{"chains"} = [@chains];
# finish up
close PDBFILE;
return $result;
}
# just return the $nucleic_acid_flag
sub nucleic_acid_flag
{
return $nucleic_acid_flag;
}
# just return the $nucleic_acid_flag
sub skip_file_code
{
return $nucleic_acid_flag;
}
# get a parsed value
sub get {
my ($self, $key) = @_;
return $self->{$key};
}
1;