comparison variant_effect_predictor/Bio/Tools/ECnumber.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1f6dce3d34e0
1 # $Id: ECnumber.pm,v 1.7 2002/12/12 18:27:02 czmasek Exp $
2 #
3 # BioPerl module for Bio::Tools::ECnumber
4 #
5 # Cared for by Christian M. Zmasek <czmasek@gnf.org> or <cmzmasek@yahoo.com>
6 #
7 # (c) Christian M. Zmasek, czmasek@gnf.org, 2002.
8 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
9 #
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.
14 #
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.
18 #
19
20 # POD documentation - main docs before the code
21
22
23 =head1 NAME
24
25 ECnumber - representation of EC numbers
26
27 =head1 SYNOPSIS
28
29 use Bio::Tools::ECnumber;
30
31
32 # Creation of ECnumber objects
33 # ----------------------------
34
35 my $EC1 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.1" );
36 my $EC2 = Bio::Tools::ECnumber->new( -ec_string => "EC 1.1.1.1" );
37 my $EC3 = Bio::Tools::ECnumber->new();
38
39
40 # Copying
41 # -------
42
43 my $EC4 = $EC1->copy();
44
45
46 # Modification of ECnumber objects
47 # --------------------------------
48
49 print $EC3->EC_string( "1.01.01.001" ); # Prints "1.1.1.1".
50
51
52 # To string
53 # ---------
54
55 print $EC3->EC_string();
56
57 # or:
58
59 print $EC3->to_string();
60
61
62
63 # Test for equality
64 # -----------------
65
66 # Against ECnumber object:
67 if ( $EC3->is_equal( $EC2 ) ) { # Prints "equal".
68 print "equal";
69 }
70
71 # Against string representation of EC number:
72 if ( ! $EC3->is_equal( "1.1.1.-" ) ) { # Prints "not equal".
73 print "not equal";
74 }
75
76
77 # Test for membership
78 # -------------------
79
80 my $EC5 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.-" );
81
82 # Against ECnumber object.
83 if ( $EC1->is_member( $EC5 ) ) { # Prints "member".
84 print "member";
85 }
86
87
88 # Against string representation of EC number.
89 if ( ! $EC1->is_member( "4.3.1.-" ) ) { # Prints "not member".
90 print "not member";
91 }
92
93
94
95 =head1 DESCRIPTION
96
97 ECnumber is a representation of EC numbers [http://www.chem.qmul.ac.uk/iubmb/enzyme/].
98
99 =head1 FEEDBACK
100
101 =head2 Mailing Lists
102
103 User feedback is an integral part of the evolution of this and other
104 Bioperl modules. Send your comments and suggestions preferably to one
105 of the Bioperl mailing lists. Your participation is much appreciated.
106
107 bioperl-l@bioperl.org - General discussion
108 http://bio.perl.org/MailList.html - About the mailing lists
109
110 =head2 Reporting Bugs
111
112 Report bugs to the Bioperl bug tracking system to help us keep track
113 the bugs and their resolution. Bug reports can be submitted via email
114 or the web:
115
116 bioperl-bugs@bio.perl.org
117 http://bugzilla.bioperl.org/
118
119 =head1 AUTHOR
120
121 Christian M. Zmasek
122
123 Email: czmasek@gnf.org or cmzmasek@yahoo.com
124
125 WWW: http://www.genetics.wustl.edu/eddy/people/zmasek/
126
127 Address:
128
129 Genomics Institute of the Novartis Research Foundation
130 10675 John Jay Hopkins Drive
131 San Diego, CA 92121
132
133 =head1 APPENDIX
134
135 The rest of the documentation details each of the object
136 methods. Internal methods are usually preceded with a _
137
138 =cut
139
140
141 # Let the code begin...
142
143 package Bio::Tools::ECnumber;
144 use vars qw( @ISA );
145 use strict;
146 use Bio::Root::Object;
147
148 use constant DEFAULT => "-";
149 use constant TRUE => 1;
150 use constant FALSE => 0;
151
152 @ISA = qw( Bio::Root::Root );
153
154
155
156
157
158 =head2 new
159
160 Title : new
161 Usage : $EC1 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.1" );
162 or
163 $EC2 = Bio::Tools::ECnumber->new( -ec_string => "4.3.2.2",
164 -comment => "Is EC 4.3.2.2" );
165 or
166 $EC3 = Bio::Tools::ECnumber->new(); # EC3 is now "-.-.-.-"
167 Function: Creates a new ECnumber object.
168 Parses a EC number from "x.x.x.x", "EC x.x.x.x",
169 "ECx.x.x.x", or "EC:x.x.x.x";
170 x being either a positive integer or a "-".
171 Returns : A new Ecnumber object.
172 Args : A string representing a EC number, e.g. "4.3.2.1"
173 or "EC 4.3.2.1" or "1.-.-.-".
174
175 =cut
176
177 sub new {
178 my( $class, @args ) = @_;
179
180 my $self = $class->SUPER::new( @args );
181
182 my ( $EC_string, $comment )
183 = $self->_rearrange( [ qw( EC_STRING COMMENT ) ], @args );
184
185 $self->init();
186
187 $EC_string && $self->EC_string( $EC_string );
188 $comment && $self->comment( $comment );
189
190 return $self;
191
192 } # new
193
194
195
196 =head2 init
197
198 Title : init()
199 Usage : $EC1->init(); # EC1 is now "-.-.-.-"
200 Function: Initializes this ECnumber to default values.
201 Returns :
202 Args :
203
204 =cut
205
206 sub init {
207 my( $self ) = @_;
208
209 $self->enzyme_class( DEFAULT );
210 $self->sub_class( DEFAULT );
211 $self->sub_sub_class( DEFAULT );
212 $self->serial_number( DEFAULT );
213 $self->comment( "" );
214
215 } # init
216
217
218
219 =head2 copy
220
221 Title : copy()
222 Usage : $EC2 = $EC1->copy();
223 Function: Creates a new ECnumber object which is an exact copy
224 of this ECnumber.
225 Returns : A copy of this ECnumber.
226 Args :
227
228 =cut
229
230 sub copy {
231 my( $self ) = @_;
232
233 my $new_ec = $self->new();
234 $new_ec->enzyme_class( $self->enzyme_class() );
235 $new_ec->sub_class( $self->sub_class() );
236 $new_ec->sub_sub_class( $self->sub_sub_class() );
237 $new_ec->serial_number( $self->serial_number() );
238 $new_ec->comment( $self->comment() );
239 return $new_ec;
240
241 } # copy
242
243
244
245 =head2 EC_string
246
247 Title : EC_string
248 Usage : $EC3->EC_string( "1.1.1.-" );
249 or
250 print $EC3->EC_string();
251 Function: Set/get for string representations of EC numbers.
252 Parses a EC number from "x.x.x.x", "EC x.x.x.x",
253 "ECx.x.x.x", or "EC:x.x.x.x";
254 x being either a positive integer or a "-".
255 Returns : A string representations of a EC number.
256 Args : A string representations of a EC number.
257
258 =cut
259
260 sub EC_string {
261 my ( $self, $value ) = @_;
262
263 if ( defined $value) {
264 $value =~ s/\s+//g; # Removes white space.
265 $value =~ s/^EC//i; # Removes "EC".
266 $value =~ s/^://; # Removes ":".
267
268 if ( $value =~ /^([\d-]*)\.([\d-]*)\.([\d-]*)\.([\d-]*)$/ ) {
269 $self->enzyme_class( $1 );
270 $self->sub_class( $2 );
271 $self->sub_sub_class( $3 );
272 $self->serial_number( $4 );
273 }
274 else {
275 $self->throw( "Illegal format error [$value]" );
276 }
277 }
278
279 return $self->to_string();
280
281 } # EC_string
282
283
284
285 =head2 to_string
286
287 Title : to_string()
288 Usage : print $EC3->to_string();
289 Function: To string method for EC numbers
290 (equals the "get" functionality of "EC_string").
291 Returns : A string representations of a EC number.
292 Args :
293
294 =cut
295
296 sub to_string {
297 my ( $self ) = @_;
298
299 my $s = $self->enzyme_class() . ".";
300 $s .= $self->sub_class() . ".";
301 $s .= $self->sub_sub_class() . ".";
302 $s .= $self->serial_number();
303 return $s;
304
305 } # to_string
306
307
308
309 =head2 is_equal
310
311 Title : is_equal
312 Usage : if ( $EC3->is_equal( $EC2 ) )
313 or
314 if ( $EC3->is_equal( "1.1.1.-" ) )
315 Function: Checks whether this ECnumber is equal to the argument
316 EC number (please note: "1.1.1.1" != "1.1.1.-").
317 Returns : True (1) or false (0).
318 Args : A ECnumber object or a string representation of a EC number.
319
320 =cut
321
322 sub is_equal {
323 my ( $self, $value ) = @_;
324
325 if ( $self->_is_not_reference( $value ) ) {
326 $value = $self->new( -ec_string => $value );
327 }
328 else {
329 $self->_is_ECnumber_object( $value );
330 }
331
332 unless ( $self->enzyme_class() eq $value->enzyme_class() ) {
333 return FALSE;
334 }
335 unless ( $self->sub_class() eq $value->sub_class() ) {
336 return FALSE;
337 }
338 unless ( $self->sub_sub_class() eq $value->sub_sub_class() ) {
339 return FALSE;
340 }
341 unless ( $self->serial_number() eq $value->serial_number() ) {
342 return FALSE;
343 }
344 return TRUE;
345
346 } # is_equal
347
348
349
350 =head2 is_member
351
352 Title : is_member
353 Usage : if ( $EC1->is_member( $EC5 ) )
354 or
355 if ( $EC1->is_member( "4.3.-.-" ) )
356 Function: Checks whether this ECnumber is a member of the (incomplete)
357 argument EC number (e.g. "1.1.1.1" is a member of "1.1.1.-"
358 but not of "1.1.1.2").
359 Returns : True (1) or false (0).
360 Args : A ECnumber object or a string representation of a EC number.
361
362 =cut
363
364 sub is_member {
365 my ( $self, $value ) = @_;
366
367 if ( $self->_is_not_reference( $value ) ) {
368 $value = $self->new( -ec_string => $value );
369 }
370 else {
371 $self->_is_ECnumber_object( $value );
372 }
373 $self->_check_for_illegal_defaults();
374 $value->_check_for_illegal_defaults();
375
376 unless ( $value->enzyme_class() eq DEFAULT
377 || $self->enzyme_class() eq $value->enzyme_class() ) {
378 return FALSE;
379 }
380 unless ( $value->sub_class() eq DEFAULT
381 || $self->sub_class() eq $value->sub_class() ) {
382 return FALSE;
383 }
384 unless ( $value->sub_sub_class() eq DEFAULT
385 || $self->sub_sub_class() eq $value->sub_sub_class() ) {
386 return FALSE;
387 }
388 unless ( $value->serial_number() eq DEFAULT
389 || $self->serial_number() eq $value->serial_number() ) {
390 return FALSE;
391 }
392 return TRUE;
393
394 } # is_member
395
396
397
398 =head2 enzyme_class
399
400 Title : enzyme_class
401 Usage : $EC1->enzyme_class( 1 );
402 or
403 print $EC1->enzyme_class();
404 Function: Set/get for the enzyme class number of ECnumbers.
405 Returns : The enzyme class number of this ECnumber.
406 Args : A positive integer or "-".
407
408 =cut
409
410 sub enzyme_class {
411 my ( $self, $value ) = @_;
412
413 if ( defined $value) {
414 $self->{ "_enzyme_class" } = $self->_check_number( $value );
415 }
416
417 return $self->{ "_enzyme_class" };
418
419 } # enzyme_class
420
421
422
423 =head2 sub_class
424
425 Title : sub_class
426 Usage : $EC1->sub_class( 4 );
427 or
428 print $EC1->sub_class();
429 Function: Set/get for the enzyme sub class number of ECnumbers.
430 Returns : The enzyme sub class number of this ECnumber.
431 Args : A positive integer or "-".
432
433 =cut
434
435 sub sub_class {
436 my ( $self, $value ) = @_;
437
438 if ( defined $value) {
439 $self->{ "_sub_class" } = $self->_check_number( $value );
440 }
441
442 return $self->{ "_sub_class" };
443
444 } # sub_class
445
446
447
448 =head2 sub_sub_class
449
450 Title : sub_sub_class
451 Usage : $EC1->sub_sub_class( 12 );
452 or
453 print $EC1->sub_sub_class();
454 Function: Set/get for the enzyme sub sub class number of ECnumbers.
455 Returns : The enzyme sub sub class number of this ECnumber.
456 Args : A positive integer or "-".
457
458 =cut
459
460 sub sub_sub_class {
461 my ( $self, $value ) = @_;
462
463 if ( defined $value) {
464 $self->{ "_sub_sub_class" } = $self->_check_number( $value );
465 }
466
467 return $self->{ "_sub_sub_class" };
468
469 } # sub_sub_class
470
471
472
473 =head2 serial_number
474
475 Title : serial_number
476 Usage : $EC1->serial_number( 482 );
477 or
478 print $EC1->serial_number();
479 Function: Set/get for the serial number of ECnumbers.
480 Returns : The serial number of this ECnumber.
481 Args : A positive integer or "-".
482
483 =cut
484
485 sub serial_number {
486 my ( $self, $value ) = @_;
487
488 if ( defined $value) {
489 $self->{ "_serial_number" } = $self->_check_number( $value );
490 }
491
492 return $self->{ "_serial_number" };
493
494 } # serial_number
495
496
497
498 =head2 comment
499
500 Title : comment
501 Usage : $EC1->comment( "deprecated" );
502 or
503 print $EC1->comment();
504 Function: Set/get for a arbitrary comment.
505 Returns : A comment [scalar].
506 Args : A comment [scalar].
507
508 =cut
509
510 sub comment {
511 my ( $self, $value ) = @_;
512
513 if ( defined $value) {
514 $self->{ "_comment" } = $value;
515 }
516
517 return $self->{ "_comment" };
518
519 } # comment
520
521
522
523 # Title : _check_number
524 # Function: Checks and standardizes the individual numbers of a EC number
525 # (removes leading zeros, removes white spaces).
526 # Returns : A standardized number.
527 # Args : A string representing a number in a EC number.
528 sub _check_number {
529 my ( $self, $value ) = @_;
530
531 my $original_value = $value;
532 $value =~ s/\s+//g; # Removes white space.
533 if ( $value eq "" ) {
534 $value = DEFAULT;
535 }
536 $value =~ s/^0+//; # Removes leading zeros.
537 if ( $value eq "" ) { # If it was "0" (or "00"), it would be "" now.
538 $value = "0";
539 }
540 elsif ( $value ne DEFAULT
541 && $value =~ /\D/ ) {
542 $self->throw( "Illegal format error [$original_value]" );
543 }
544 return $value;
545
546 } # _check_number
547
548
549
550 # Title : _check_for_illegal_defaults()
551 # Function: Checks for situations like "1.-.1.1", which
552 # are illegal in membership tests.
553 # Returns :
554 # Args :
555 sub _check_for_illegal_defaults {
556 my ( $self ) = @_;
557
558 if ( ( $self->sub_sub_class() eq DEFAULT
559 && $self->serial_number() ne DEFAULT ) ||
560 ( $self->sub_class() eq DEFAULT
561 && $self->sub_sub_class() ne DEFAULT ) ||
562 ( $self->enzyme_class() eq DEFAULT
563 && $self->sub_class() ne DEFAULT ) ) {
564 $self->throw( "Illegal format error for comparison ["
565 . $self->to_string() . "]" );
566 }
567
568 } # _check_for_illegal_defaults
569
570
571
572 # Title : _is_not_reference
573 # Function: Checks whether the argument is not a reference.
574 # Returns : True or false.
575 # Args : A scalar.
576 sub _is_not_reference {
577 my ( $self, $value ) = @_;
578
579 return ( ! ref( $value ) );
580
581 } # _is_not_reference
582
583
584
585 # Title : _is_ECnumber_object
586 # Function: Checks whether the arument is a ECnumber.
587 # Returns :
588 # Args : A reference.
589 sub _is_ECnumber_object {
590 my ( $self, $value ) = @_;
591
592 unless( $value->isa( "Bio::Tools::ECnumber" ) ) {
593 $self->throw( "Found [". ref( $value )
594 ."] where [Bio::Tools::ECnumber] expected" );
595 }
596
597 } # _is_ECnumber_object
598
599
600
601 1;