~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

Viewing changes to Bio/Tools/pICalculator.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
 
 
3
=head1 NAME
 
4
 
 
5
pICalculator
 
6
 
 
7
=head1 DESCRIPTION
 
8
 
 
9
Calculates the isoelectric point of a protein, the pH at which there
 
10
is no overall charge on the protein. Calculates the charge on a protein
 
11
at a given pH. Can use built-in sets of pK values or custom pK sets.
 
12
 
 
13
=head1 SYNOPSIS
 
14
 
 
15
  use Bio::Tools::pICalculator;
 
16
  use Bio::SeqIO;
 
17
 
 
18
  my $in = Bio::SeqIO->new( -fh => \*STDIN ,-format => 'Fasta' );
 
19
 
 
20
  my $calc = Bio::Tools::pICalculator->new(-places => 2,
 
21
                                           -pKset => 'EMBOSS');
 
22
 
 
23
  while ( my $seq = $in->next_seq ) {
 
24
     $calc->seq($seq);
 
25
     my $iep = $calc->iep;
 
26
     print sprintf( "%s\t%s\t%.2f\n",
 
27
                    $seq->id,
 
28
                    $iep,
 
29
                    $calc->charge_at_pH($iep) );
 
30
 
 
31
     for( my $i = 0; $i <= 14; $i += 0.5 ){
 
32
        print sprintf( "pH = %.2f\tCharge = %.2f\n",
 
33
                       $i,
 
34
                       $calc->charge_at_pH($i) );
 
35
     }
 
36
  }
 
37
 
 
38
=head1 SEE ALSO
 
39
 
 
40
http://fields.scripps.edu/DTASelect/20010710-pI-Algorithm.pdf
 
41
http://www.hgmp.mrc.ac.uk/Software/EMBOSS/Apps/iep.html
 
42
http://us.expasy.org/tools/pi_tool.html
 
43
 
 
44
=head1 LIMITATIONS
 
45
 
 
46
There are various sources for the pK values of the amino acids. The set of
 
47
pK values chosen will affect the pI reported.
 
48
 
 
49
The charge state of each residue is assumed to be independent of the others.
 
50
Protein modifications (such as a phosphate group) that have a charge are
 
51
ignored.
 
52
 
 
53
=head1 FEEDBACK
 
54
 
 
55
=head2 Mailing Lists
 
56
 
 
57
User feedback is an integral part of the evolution of this
 
58
and other Bioperl modules. Send your comments and suggestions preferably
 
59
to one of the Bioperl mailing lists.
 
60
Your participation is much appreciated.
 
61
 
 
62
  bioperl-l@bioperl.org                 - General discussion
 
63
  http://bio.perl.org/MailList.html     - About the mailing lists
 
64
 
 
65
=head2 Bugs
 
66
 
 
67
Report bugs to the Bioperl bug tracking system to help us keep track
 
68
the bugs and their resolution.
 
69
Bug reports can be submitted via email or the web:
 
70
 
 
71
  bioperl-bugs@bio.perl.org
 
72
  http://bugzilla.bioperl.org/
 
73
 
 
74
=head1 AUTHOR
 
75
 
 
76
Mark Southern (mark_southern@merck.com). From an algorithm by David Tabb found
 
77
at http://fields.scripps.edu/DTASelect/20010710-pI-Algorithm.pdf.
 
78
Modification for Bioperl, additional documentation by Brian Osborne.
 
79
 
 
80
=head1 COPYRIGHT
 
81
 
 
82
Copyright (c) 2002, Merck & Co. Inc. All Rights Reserved. This module is
 
83
free software. It may be used, redistributed and/or modified under the terms
 
84
of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)
 
85
 
 
86
=head1 APPENDIX
 
87
 
 
88
The rest of the documentation details each of the object methods.
 
89
Private methods are usually preceded by a _.
 
90
 
 
91
=cut
 
92
 
 
93
# Let the code begin...
 
94
 
 
95
package Bio::Tools::pICalculator;
 
96
use vars qw(@ISA);
 
97
use strict;
 
98
 
 
99
use Bio::Root::Root;
 
100
 
 
101
@ISA = qw(Bio::Root::Root);
 
102
 
 
103
# pK values from the DTASelect program from Scripps
 
104
# http://fields.scripps.edu/DTASelect
 
105
my $DTASelect_pK = {  N_term   =>  8.0,
 
106
                      K        => 10.0, # Lys
 
107
                      R        => 12.0, # Arg
 
108
                      H        =>  6.5, # His
 
109
                      D        =>  4.4, # Asp
 
110
                      E        =>  4.4, # Glu
 
111
                      C        =>  8.5, # Cys
 
112
                      Y        => 10.0, # Tyr
 
113
                      C_term   =>  3.1
 
114
                    };
 
115
 
 
116
# pK values from the iep program from EMBOSS
 
117
# http://www.hgmp.mrc.ac.uk/Software/EMBOSS/
 
118
my $Emboss_pK  = { N_term   =>  8.6,
 
119
                   K        => 10.8, # Lys
 
120
                   R        => 12.5, # Arg
 
121
                   H        =>  6.5, # His
 
122
                   D        =>  3.9, # Asp
 
123
                   E        =>  4.1, # Glu
 
124
                   C        =>  8.5, # Cys
 
125
                   Y        => 10.1, # Tyr
 
126
                   C_term   =>  3.6
 
127
                 };
 
128
 
 
129
=head2 desc
 
130
 
 
131
 Title   : new
 
132
 Usage   : Bio::Tools::pICalculator->new
 
133
 Function: Instantiates the Bio::Tools::pICalculator object
 
134
 Example : $calc = Bio::Tools::pICalculator->new( -pKset => \%pKvalues,
 
135
                                                  # a Bio::Seq object
 
136
                                                  -seq => $seq,
 
137
                                                  -places => 2 );
 
138
           or:
 
139
 
 
140
           $calc = Bio::Tools::pICalculator->new( -pKset => 'string',
 
141
                                                  # a Bio::Seq object
 
142
                                                  -seq => $seq,
 
143
                                                  -places => 1 );
 
144
 
 
145
           Constructs a new pICalculator. Arguments are a flattened hash.
 
146
           Valid, optional keys are:
 
147
 
 
148
           pKset - A reference to a hash with key value pairs for the 
 
149
                   pK values of the charged amino acids. Required keys
 
150
                   are:
 
151
 
 
152
                   N_term   C_term   K   R   H   D   E   C   Y
 
153
 
 
154
           pKset - A string ( 'DTASelect' or 'EMBOSS' ) that will 
 
155
                   specify an internal set of pK values to be used. The 
 
156
                   default is 'EMBOSS'
 
157
 
 
158
           seq - A Bio::Seq sequence object to analyze
 
159
 
 
160
           places - The number of decimal places to use in the
 
161
                    isoelectric point calculation. The default is 2.
 
162
 
 
163
 Returns : The description
 
164
 Args    : The description or none
 
165
 
 
166
=cut
 
167
 
 
168
sub new {
 
169
   my( $class, %opts ) = @_;
 
170
   my $self = $class->SUPER::new(%opts);
 
171
   $self = bless {}, ref $self || $self;
 
172
   $self->seq( $opts{-seq} ) if exists $opts{-seq};
 
173
   $self->pKset( $opts{-pKset} || 'EMBOSS' );
 
174
   exists $opts{-places} ? $self->places( $opts{-places} ) :
 
175
     $self->places(2);
 
176
   return $self;
 
177
}
 
178
 
 
179
=head2 seq
 
180
 
 
181
 Title   : seq
 
182
 Usage   : $calc->seq($seqobj)
 
183
 Function: Sets or returns the Bio::Seq used in the calculation
 
184
 Example : $seqobj = Bio::Seq->new(-seq=>"gghhhmmm",-id=>"GHM");
 
185
           $calc = Bio::Tools::pICalculator->new;
 
186
           $calc->seq($seqobj);
 
187
 Returns : Bio::Seq object
 
188
 Args    : Bio::Seq object or none
 
189
 
 
190
=cut
 
191
 
 
192
sub seq {
 
193
   my( $this, $seq ) = @_;
 
194
   unless( defined $seq && UNIVERSAL::isa($seq,'Bio::Seq') ){
 
195
      die $seq . " is not a valid Bio::Seq object\n";
 
196
   }
 
197
   $this->{-seq} = $seq;
 
198
   $this->{-count} = count_charged_residues( $seq );
 
199
   return $this->{-seq};
 
200
}
 
201
 
 
202
=head2 pKset
 
203
 
 
204
 Title   : pKset
 
205
 Usage   : $pkSet = $calc->pKSet(\%pKSet)
 
206
 Function: Sets or returns the hash of pK values used in the calculation
 
207
 Example : $calc->pKset('emboss')
 
208
 Returns : reference to pKset hash
 
209
 Args    : The reference to a pKset hash, a string, or none. Examples:
 
210
 
 
211
           pKset - A reference to a hash with key value pairs for the
 
212
                   pK values of the charged amino acids. Required keys
 
213
                   are:
 
214
 
 
215
                   N_term   C_term   K   R   H   D   E   C   Y
 
216
 
 
217
           pKset - A valid string ( 'DTASelect' or 'EMBOSS' ) that will 
 
218
                   specify an internal set of pK values to be used. The 
 
219
                   default is 'EMBOSS'
 
220
 
 
221
=cut
 
222
 
 
223
sub pKset {
 
224
   my ( $this, $pKset ) = @_;
 
225
   if( ref $pKset eq 'HASH' ){         # user defined pK values
 
226
      $this->{-pKset} = $pKset;
 
227
   }elsif( $pKset =~ /^emboss$/i ){    # from EMBOSS's iep program
 
228
      $this->{-pKset} = $Emboss_pK;
 
229
   }elsif( $pKset =~ /^dtaselect$/i ){ # from DTASelect (scripps)
 
230
      $this->{-pKset} = $DTASelect_pK;
 
231
   }else{                              # default to EMBOSS
 
232
      $this->{-pKset} = $Emboss_pK;
 
233
   }
 
234
   return $this->{-pKset};
 
235
}
 
236
 
 
237
sub places {
 
238
   my $this = shift;
 
239
   $this->{-places} = shift if @_;
 
240
   return $this->{-places};
 
241
}
 
242
 
 
243
=head2 iep
 
244
 
 
245
 Title   : iep
 
246
 Usage   : $calc->iep
 
247
 Function: Returns the isoelectric point
 
248
 Example : $calc = Bio::Tools::pICalculator->new(-places => 2);
 
249
           $calc->seq($seqobj);
 
250
           $iep = $calc->iep;
 
251
 Returns : The isoelectric point of the sequence in the Bio::Seq object
 
252
 Args    : None
 
253
 
 
254
=cut
 
255
 
 
256
sub iep {
 
257
   my $this = shift;
 
258
   return _calculate_iep($this->{-pKset},
 
259
                         $this->{-places},
 
260
                         $this->{-seq},
 
261
                         $this->{-count}
 
262
                        );
 
263
}
 
264
 
 
265
=head2 charge_at_pH
 
266
 
 
267
 Title   : charge_at_pH
 
268
 Usage   : $charge = $calc->charge_at_pH($pH)
 
269
 Function: Sets or gets the description of the sequence
 
270
 Example : $calc = Bio::Tools::pICalculator->new(-places => 2);
 
271
           $calc->seq($seqobj);
 
272
           $charge = $calc->charge_at_ph("7");
 
273
 Returns : The predicted charge at the given pH
 
274
 Args    : pH
 
275
 
 
276
=cut
 
277
 
 
278
sub charge_at_pH {
 
279
   my $this = shift;
 
280
   return _calculate_charge_at_pH( shift, $this->{-pKset},
 
281
                                  $this->{-count} );
 
282
}
 
283
 
 
284
sub count_charged_residues {
 
285
   my $seq = shift;
 
286
   my $sequence = $seq->seq;
 
287
   my $count;
 
288
   for ( qw( K R H D E C Y ) ){ # charged AA's
 
289
      $count->{$_}++ while $sequence =~ /$_/ig;
 
290
   }
 
291
   return $count;
 
292
}
 
293
 
 
294
sub _calculate_iep {
 
295
    my( $pK, $places, $seq, $count ) = @_;
 
296
    my $pH = 7.0;
 
297
    my $step = 3.5;
 
298
    my $last_charge = 0.0;
 
299
    my $format = "%.${places}f";
 
300
 
 
301
    unless( defined $count ){
 
302
       $count = count_charged_residues($seq);
 
303
    }
 
304
    while(1){
 
305
       my $charge = _calculate_charge_at_pH( $pH, $pK, $count );
 
306
       last if sprintf($format,$charge) == 
 
307
         sprintf($format,$last_charge);
 
308
       $charge > 0 ? ( $pH += $step ) : ( $pH -= $step );
 
309
       $step /= 2.0;
 
310
       $last_charge = $charge;
 
311
    }
 
312
    return sprintf( $format, $pH );
 
313
}
 
314
 
 
315
# it's the sum of all the partial charges for the
 
316
# termini and all of the charged aa's!
 
317
sub _calculate_charge_at_pH {
 
318
   no warnings; # don't complain if a given key doesn't exist
 
319
   my( $pH, $pK, $count ) = @_;
 
320
   my $charge =    _partial_charge( $pK->{N_term}, $pH )
 
321
   + $count->{K} * _partial_charge( $pK->{K},      $pH )
 
322
   + $count->{R} * _partial_charge( $pK->{R},      $pH )
 
323
   + $count->{H} * _partial_charge( $pK->{H},      $pH )
 
324
   - $count->{D} * _partial_charge( $pH,      $pK->{D} )
 
325
   - $count->{E} * _partial_charge( $pH,      $pK->{E} )
 
326
   - $count->{C} * _partial_charge( $pH,      $pK->{C} )
 
327
   - $count->{Y} * _partial_charge( $pH,      $pK->{Y} )
 
328
   -               _partial_charge( $pH, $pK->{C_term} );
 
329
   return $charge;
 
330
}
 
331
 
 
332
# Concentration Ratio is 10**(pK - pH) for positive groups
 
333
# and 10**(pH - pK) for negative groups
 
334
sub _partial_charge {
 
335
   my $cr = 10 ** ( $_[0] - $_[1] );
 
336
   return $cr / ( $cr + 1 );
 
337
}
 
338
 
 
339
1;
 
340
 
 
341
__END__