3 # BioPerl module for Bio::Tools::ECnumber
5 # Cared for by Christian M. Zmasek <czmasek@gnf.org> or <cmzmasek@yahoo.com>
7 # (c) Christian M. Zmasek, czmasek@gnf.org, 2002.
8 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
10 # You may distribute this module under the same terms as perl itself.
11 # Refer to the Perl Artistic License (see the license accompanying this
12 # software package, or see http://www.perl.com/language/misc/Artistic.html)
13 # for the terms under which you may use, modify, and redistribute this module.
15 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
16 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 # POD documentation - main docs before the code
25 Bio::Tools::ECnumber - representation of EC numbers (Enzyme Classification)
29 use Bio::Tools::ECnumber;
31 # Creation of ECnumber objects
32 my $EC1 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.1" );
33 my $EC2 = Bio::Tools::ECnumber->new( -ec_string => "EC 1.1.1.1" );
34 my $EC3 = Bio::Tools::ECnumber->new();
37 my $EC4 = $EC1->copy();
39 # Modification/canonicalization of ECnumber objects
40 print $EC3->EC_string( "1.01.01.001" ); # Prints "1.1.1.1".
43 print $EC3->EC_string();
45 print $EC3->to_string();
48 # -- Against ECnumber object:
49 if ( $EC3->is_equal( $EC2 ) ) { # Prints "equal".
52 # -- Against string representation of EC number:
53 if ( ! $EC3->is_equal( "1.1.1.-" ) ) { # Prints "not equal".
58 my $EC5 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.-" );
59 # -- Against ECnumber object.
60 if ( $EC1->is_member( $EC5 ) ) { # Prints "member".
63 # -- Against string representation of EC number.
64 if ( ! $EC1->is_member( "4.3.1.-" ) ) { # Prints "not member".
70 L<Bio::Tools::ECnumber> is a representation of EC numbers,
71 the numerical heirarchy for Enzyme Classification.
73 See L<http://www.chem.qmul.ac.uk/iubmb/enzyme/> for more details.
79 User feedback is an integral part of the evolution of this and other
80 Bioperl modules. Send your comments and suggestions preferably to one
81 of the Bioperl mailing lists. Your participation is much appreciated.
83 bioperl-l@bioperl.org - General discussion
84 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
88 Report bugs to the Bioperl bug tracking system to help us keep track
89 the bugs and their resolution. Bug reports can be submitted via the
92 http://bugzilla.open-bio.org/
98 Email: czmasek@gnf.org or cmzmasek@yahoo.com
100 WWW: http://www.genetics.wustl.edu/eddy/people/zmasek/
104 Genomics Institute of the Novartis Research Foundation
105 10675 John Jay Hopkins Drive
110 The rest of the documentation details each of the object
111 methods. Internal methods are usually preceded with a _
116 # Let the code begin...
118 package Bio
::Tools
::ECnumber
;
121 use constant DEFAULT
=> "-";
122 use constant TRUE
=> 1;
123 use constant FALSE
=> 0;
125 use base
qw(Bio::Root::Root);
130 Usage : $EC1 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.1" );
132 $EC2 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.2",
133 -comment => "Is EC 4.3.2.2" );
135 $EC3 = Bio::Tools::ECnumber->new(); # EC3 is now "-.-.-.-"
136 Function: Creates a new ECnumber object.
137 Parses a EC number from "x.x.x.x", "EC x.x.x.x",
138 "ECx.x.x.x", or "EC:x.x.x.x";
139 x being either a positive integer or a "-".
140 Returns : A new ECnumber object.
141 Args : A string representing a EC number, e.g. "4.3.2.1"
142 or "EC 4.3.2.1" or "1.-.-.-".
147 my( $class, @args ) = @_;
149 my $self = $class->SUPER::new
( @args );
151 my ( $EC_string, $comment )
152 = $self->_rearrange( [ qw( EC_STRING COMMENT ) ], @args );
156 $EC_string && $self->EC_string( $EC_string );
157 $comment && $self->comment( $comment );
168 Usage : $EC1->init(); # EC1 is now "-.-.-.-"
169 Function: Initializes this ECnumber to default values.
178 $self->enzyme_class( DEFAULT
);
179 $self->sub_class( DEFAULT
);
180 $self->sub_sub_class( DEFAULT
);
181 $self->serial_number( DEFAULT
);
182 $self->comment( "" );
191 Usage : $EC2 = $EC1->copy();
192 Function: Creates a new ECnumber object which is an exact copy
194 Returns : A copy of this ECnumber.
202 my $new_ec = $self->new();
203 $new_ec->enzyme_class( $self->enzyme_class() );
204 $new_ec->sub_class( $self->sub_class() );
205 $new_ec->sub_sub_class( $self->sub_sub_class() );
206 $new_ec->serial_number( $self->serial_number() );
207 $new_ec->comment( $self->comment() );
217 Usage : $EC3->EC_string( "1.1.1.-" );
219 print $EC3->EC_string();
220 Function: Set/get for string representations of EC numbers.
221 Parses a EC number from "x.x.x.x", "EC x.x.x.x",
222 "ECx.x.x.x", or "EC:x.x.x.x";
223 x being either a positive integer or a "-".
224 Returns : A string representations of a EC number.
225 Args : A string representations of a EC number.
230 my ( $self, $value ) = @_;
232 if ( defined $value) {
233 $value =~ s/\s+//g; # Removes white space.
234 $value =~ s/^EC//i; # Removes "EC".
235 $value =~ s/^://; # Removes ":".
237 if ( $value =~ /^([\d-]*)\.([\d-]*)\.([\d-]*)\.([\d-]*)$/ ) {
238 $self->enzyme_class( $1 );
239 $self->sub_class( $2 );
240 $self->sub_sub_class( $3 );
241 $self->serial_number( $4 );
244 $self->throw( "Illegal format error [$value]" );
248 return $self->to_string();
257 Usage : print $EC3->to_string();
258 Function: To string method for EC numbers
259 (equals the "get" functionality of "EC_string").
260 Returns : A string representations of a EC number.
268 my $s = $self->enzyme_class() . ".";
269 $s .= $self->sub_class() . ".";
270 $s .= $self->sub_sub_class() . ".";
271 $s .= $self->serial_number();
281 Usage : if ( $EC3->is_equal( $EC2 ) )
283 if ( $EC3->is_equal( "1.1.1.-" ) )
284 Function: Checks whether this ECnumber is equal to the argument
285 EC number (please note: "1.1.1.1" != "1.1.1.-").
286 Returns : True (1) or false (0).
287 Args : A ECnumber object or a string representation of a EC number.
292 my ( $self, $value ) = @_;
294 if ( $self->_is_not_reference( $value ) ) {
295 $value = $self->new( -ec_string
=> $value );
298 $self->_is_ECnumber_object( $value );
301 unless ( $self->enzyme_class() eq $value->enzyme_class() ) {
304 unless ( $self->sub_class() eq $value->sub_class() ) {
307 unless ( $self->sub_sub_class() eq $value->sub_sub_class() ) {
310 unless ( $self->serial_number() eq $value->serial_number() ) {
322 Usage : if ( $EC1->is_member( $EC5 ) )
324 if ( $EC1->is_member( "4.3.-.-" ) )
325 Function: Checks whether this ECnumber is a member of the (incomplete)
326 argument EC number (e.g. "1.1.1.1" is a member of "1.1.1.-"
327 but not of "1.1.1.2").
328 Returns : True (1) or false (0).
329 Args : A ECnumber object or a string representation of a EC number.
334 my ( $self, $value ) = @_;
336 if ( $self->_is_not_reference( $value ) ) {
337 $value = $self->new( -ec_string
=> $value );
340 $self->_is_ECnumber_object( $value );
342 $self->_check_for_illegal_defaults();
343 $value->_check_for_illegal_defaults();
345 unless ( $value->enzyme_class() eq DEFAULT
346 || $self->enzyme_class() eq $value->enzyme_class() ) {
349 unless ( $value->sub_class() eq DEFAULT
350 || $self->sub_class() eq $value->sub_class() ) {
353 unless ( $value->sub_sub_class() eq DEFAULT
354 || $self->sub_sub_class() eq $value->sub_sub_class() ) {
357 unless ( $value->serial_number() eq DEFAULT
358 || $self->serial_number() eq $value->serial_number() ) {
370 Usage : $EC1->enzyme_class( 1 );
372 print $EC1->enzyme_class();
373 Function: Set/get for the enzyme class number of ECnumbers.
374 Returns : The enzyme class number of this ECnumber.
375 Args : A positive integer or "-".
380 my ( $self, $value ) = @_;
382 if ( defined $value) {
383 $self->{ "_enzyme_class" } = $self->_check_number( $value );
386 return $self->{ "_enzyme_class" };
395 Usage : $EC1->sub_class( 4 );
397 print $EC1->sub_class();
398 Function: Set/get for the enzyme sub class number of ECnumbers.
399 Returns : The enzyme sub class number of this ECnumber.
400 Args : A positive integer or "-".
405 my ( $self, $value ) = @_;
407 if ( defined $value) {
408 $self->{ "_sub_class" } = $self->_check_number( $value );
411 return $self->{ "_sub_class" };
419 Title : sub_sub_class
420 Usage : $EC1->sub_sub_class( 12 );
422 print $EC1->sub_sub_class();
423 Function: Set/get for the enzyme sub sub class number of ECnumbers.
424 Returns : The enzyme sub sub class number of this ECnumber.
425 Args : A positive integer or "-".
430 my ( $self, $value ) = @_;
432 if ( defined $value) {
433 $self->{ "_sub_sub_class" } = $self->_check_number( $value );
436 return $self->{ "_sub_sub_class" };
444 Title : serial_number
445 Usage : $EC1->serial_number( 482 );
447 print $EC1->serial_number();
448 Function: Set/get for the serial number of ECnumbers.
449 Returns : The serial number of this ECnumber.
450 Args : A positive integer or "-".
455 my ( $self, $value ) = @_;
457 if ( defined $value) {
458 $self->{ "_serial_number" } = $self->_check_number( $value );
461 return $self->{ "_serial_number" };
470 Usage : $EC1->comment( "deprecated" );
472 print $EC1->comment();
473 Function: Set/get for a arbitrary comment.
474 Returns : A comment [scalar].
475 Args : A comment [scalar].
480 my ( $self, $value ) = @_;
482 if ( defined $value) {
483 $self->{ "_comment" } = $value;
486 return $self->{ "_comment" };
492 # Title : _check_number
493 # Function: Checks and standardizes the individual numbers of a EC number
494 # (removes leading zeros, removes white spaces).
495 # Returns : A standardized number.
496 # Args : A string representing a number in a EC number.
498 my ( $self, $value ) = @_;
500 my $original_value = $value;
501 $value =~ s/\s+//g; # Removes white space.
502 if ( $value eq "" ) {
505 $value =~ s/^0+//; # Removes leading zeros.
506 if ( $value eq "" ) { # If it was "0" (or "00"), it would be "" now.
509 elsif ( $value ne DEFAULT
510 && $value =~ /\D/ ) {
511 $self->throw( "Illegal format error [$original_value]" );
519 # Title : _check_for_illegal_defaults()
520 # Function: Checks for situations like "1.-.1.1", which
521 # are illegal in membership tests.
524 sub _check_for_illegal_defaults
{
527 if ( ( $self->sub_sub_class() eq DEFAULT
528 && $self->serial_number() ne DEFAULT
) ||
529 ( $self->sub_class() eq DEFAULT
530 && $self->sub_sub_class() ne DEFAULT
) ||
531 ( $self->enzyme_class() eq DEFAULT
532 && $self->sub_class() ne DEFAULT
) ) {
533 $self->throw( "Illegal format error for comparison ["
534 . $self->to_string() . "]" );
537 } # _check_for_illegal_defaults
541 # Title : _is_not_reference
542 # Function: Checks whether the argument is not a reference.
543 # Returns : True or false.
545 sub _is_not_reference
{
546 my ( $self, $value ) = @_;
548 return ( ! ref( $value ) );
550 } # _is_not_reference
554 # Title : _is_ECnumber_object
555 # Function: Checks whether the arument is a ECnumber.
557 # Args : A reference.
558 sub _is_ECnumber_object
{
559 my ( $self, $value ) = @_;
561 unless( $value->isa( "Bio::Tools::ECnumber" ) ) {
562 $self->throw( "Found [". ref( $value )
563 ."] where [Bio::Tools::ECnumber] expected" );
566 } # _is_ECnumber_object