Bio/Tools/pICalculator.pm

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