bug 2549; fixed small bug in Bio::Taxon which doesn't catch -common_name
[bioperl-live.git] / Bio / Ontology / InterProTerm.pm
blob7fab239e2356265b6e63a5f3b3db75dff82972ac
1 # $Id$
3 # BioPerl module for Bio::Ontology::InterProTerm
5 # Cared for by Peter Dimitrov <dimitrov@gnf.org>
7 # Copyright Peter Dimitrov
8 # (c) Peter Dimitrov, dimitrov@gnf.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
11 # You may distribute this module under the same terms as perl itself.
12 # Refer to the Perl Artistic License (see the license accompanying this
13 # software package, or see http://www.perl.com/language/misc/Artistic.html)
14 # for the terms under which you may use, modify, and redistribute this module.
16 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 # POD documentation - main docs before the code
22 =head1 NAME
24 Bio::Ontology::InterProTerm - Implementation of InterProI term interface
26 =head1 SYNOPSIS
28 my $term = Bio::Ontology::InterProTerm->new(
29 -interpro_id => "IPR000001",
30 -name => "Kringle",
31 -definition => "Kringles are autonomous structural domains ...",
32 -ontology => "Domain"
34 print $term->interpro_id(), "\n";
35 print $term->name(), "\n";
36 print $term->definition(), "\n";
37 print $term->is_obsolete(), "\n";
38 print $term->ontology->name(), "\n";
40 =head1 DESCRIPTION
42 This is a simple extension of L<Bio::Ontology::Term> for InterPro terms.
44 =head1 FEEDBACK
46 =head2 Mailing Lists
48 User feedback is an integral part of the evolution of this and other
49 Bioperl modules. Send your comments and suggestions preferably to
50 the Bioperl mailing list. Your participation is much appreciated.
52 bioperl-l@bioperl.org - General discussion
53 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 =head2 Reporting Bugs
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via
59 the web:
61 http://bugzilla.open-bio.org/
63 =head1 AUTHOR - Peter Dimitrov
65 Email dimitrov@gnf.org
67 =head1 APPENDIX
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
72 =cut
75 # Let the code begin...
78 package Bio::Ontology::InterProTerm;
79 use strict;
81 use Bio::Annotation::Reference;
83 use constant INTERPRO_ID_DEFAULT => "IPR000000";
85 use base qw(Bio::Ontology::Term);
87 =head2 new
89 Title : new
90 Usage : $term = Bio::Ontology::InterProTerm->new( -interpro_id => "IPR000002",
91 -name => "Cdc20/Fizzy",
92 -definition => "The Cdc20/Fizzy region is almost always ...",
93 -ontology => "Domain"
96 Function: Creates a new Bio::Ontology::InterProTerm.
97 Example :
98 Returns : A new Bio::Ontology::InterProTerm object.
99 Args :
100 -interpro_id => the InterPro ID of the term. Has the form IPRdddddd, where dddddd is a zero-padded six digit number
101 -name => the name of this InterPro term [scalar]
102 -definition => the definition/abstract of this InterPro term [scalar]
103 -ontology => ontology of InterPro terms [Bio::Ontology::OntologyI]
104 -comment => a comment [scalar]
106 =cut
108 sub new{
109 my ($class, @args) = @_;
110 my $self = $class->SUPER::new(@args);
112 my ( $interpro_id,
113 $short_name)
114 = $self->_rearrange( [qw( INTERPRO_ID
115 SHORT_NAME
117 ], @args );
119 $interpro_id && $self->interpro_id( $interpro_id );
120 $short_name && $self->short_name( $short_name );
122 return $self;
125 =head2 init
127 Title : init
128 Usage : $term->init();
129 Function: Initializes this InterProTerm to all "" and empty lists.
130 Example :
131 Returns :
132 Args :
135 =cut
137 sub init{
138 my $self = shift;
140 # first call the inherited version to properly chain up the hierarchy
141 $self->SUPER::init(@_);
143 # then only initialize what we implement ourselves here
144 $self->interpro_id( INTERPRO_ID_DEFAULT );
145 $self->short_name("");
149 =head2 _check_interpro_id
151 Title : _check_interpro_id
152 Usage :
153 Function: Performs simple check in order to validate that its argument has the form IPRdddddd, where dddddd is a zero-padded six digit number.
154 Example :
155 Returns : Returns its argument if valid, otherwise throws exception.
156 Args : String
159 =cut
161 sub _check_interpro_id{
162 my ($self, $value) = @_;
164 $self->throw( "InterPro ID ".$value." is incorrect\n" )
165 unless ( $value =~ /^IPR\d{6}$/ ||
166 $value eq INTERPRO_ID_DEFAULT );
168 return $value;
171 =head2 interpro_id
173 Title : interpro_id
174 Usage : $obj->interpro_id($newval)
175 Function: Set/get for the interpro_id of this InterProTerm
176 Example :
177 Returns : value of interpro_id (a scalar)
178 Args : new value (a scalar, optional)
181 =cut
183 sub interpro_id{
184 my ($self, $value) = @_;
186 if( defined $value) {
187 $value = $self->_check_interpro_id($value);
188 return $self->identifier($value);
191 return $self->identifier();
194 =head2 short_name
196 Title : short_name
197 Usage : $obj->short_name($newval)
198 Function: Set/get for the short name of this InterProTerm.
199 Example :
200 Returns : value of short_name (a scalar)
201 Args : new value (a scalar, optional)
204 =cut
206 sub short_name{
207 my ($self, $value) = @_;
209 if( defined $value) {
210 $self->{'short_name'} = $value ? $value : undef;
213 return $self->{'short_name'};
216 =head2 protein_count
218 Title : protein_count
219 Usage : $obj->protein_count($newval)
220 Function: Set/get for the protein count of this InterProTerm.
221 Example :
222 Returns : value of protein_count (a scalar)
223 Args : new value (a scalar, optional)
226 =cut
228 sub protein_count{
229 my ($self,$value) = @_;
231 if( defined $value) {
232 $self->{'protein_count'} = $value ? $value : undef;
235 return $self->{'protein_count'};
238 =head2 get_references
240 Title : get_references
241 Usage :
242 Function: Get the references for this InterPro term.
243 Example :
244 Returns : An array of L<Bio::Annotation::Reference> objects
245 Args :
248 =cut
250 sub get_references{
251 my $self = shift;
253 return @{$self->{"_references"}} if exists($self->{"_references"});
254 return ();
257 =head2 add_reference
259 Title : add_reference
260 Usage :
261 Function: Add one or more references to this InterPro term.
262 Example :
263 Returns :
264 Args : One or more L<Bio::Annotation::Reference> objects.
267 =cut
269 sub add_reference{
270 my $self = shift;
272 $self->{"_references"} = [] unless exists($self->{"_references"});
273 push(@{$self->{"_references"}}, @_);
276 =head2 remove_references
278 Title : remove_references
279 Usage :
280 Function: Remove all references for this InterPro term.
281 Example :
282 Returns : The list of previous references as an array of
283 L<Bio::Annotation::Reference> objects.
284 Args :
287 =cut
289 sub remove_references{
290 my $self = shift;
292 my @arr = $self->get_references();
293 $self->{"_references"} = [];
294 return @arr;
297 =head2 get_members
299 Title : get_members
300 Usage : @arr = get_members()
301 Function: Get the list of member(s) for this object.
302 Example :
303 Returns : An array of Bio::Annotation::DBLink objects
304 Args :
307 =cut
309 sub get_members{
310 my $self = shift;
312 return @{$self->{'_members'}} if exists($self->{'_members'});
313 return ();
316 =head2 add_member
318 Title : add_member
319 Usage :
320 Function: Add one or more member(s) to this object.
321 Example :
322 Returns :
323 Args : One or more Bio::Annotation::DBLink objects.
326 =cut
328 sub add_member{
329 my $self = shift;
331 $self->{'_members'} = [] unless exists($self->{'_members'});
332 push(@{$self->{'_members'}}, @_);
335 =head2 remove_members
337 Title : remove_members
338 Usage :
339 Function: Remove all members for this class.
340 Example :
341 Returns : The list of previous members as an array of
342 Bio::Annotation::DBLink objects.
343 Args :
346 =cut
348 sub remove_members{
349 my $self = shift;
351 my @arr = $self->get_members();
352 $self->{'_members'} = [];
353 return @arr;
356 =head2 get_examples
358 Title : get_examples
359 Usage : @arr = get_examples()
360 Function: Get the list of example(s) for this object.
362 This is an element of the InterPro xml schema.
364 Example :
365 Returns : An array of Bio::Annotation::DBLink objects
366 Args :
369 =cut
371 sub get_examples{
372 my $self = shift;
374 return @{$self->{'_examples'}} if exists($self->{'_examples'});
375 return ();
378 =head2 add_example
380 Title : add_example
381 Usage :
382 Function: Add one or more example(s) to this object.
384 This is an element of the InterPro xml schema.
386 Example :
387 Returns :
388 Args : One or more Bio::Annotation::DBLink objects.
391 =cut
393 sub add_example{
394 my $self = shift;
396 $self->{'_examples'} = [] unless exists($self->{'_examples'});
397 push(@{$self->{'_examples'}}, @_);
400 =head2 remove_examples
402 Title : remove_examples
403 Usage :
404 Function: Remove all examples for this class.
406 This is an element of the InterPro xml schema.
408 Example :
409 Returns : The list of previous examples as an array of
410 Bio::Annotation::DBLink objects.
411 Args :
414 =cut
416 sub remove_examples{
417 my $self = shift;
419 my @arr = $self->get_examples();
420 $self->{'_examples'} = [];
421 return @arr;
424 =head2 get_external_documents
426 Title : get_external_documents
427 Usage : @arr = get_external_documents()
428 Function: Get the list of external_document(s) for this object.
430 This is an element of the InterPro xml schema.
432 Example :
433 Returns : An array of Bio::Annotation::DBLink objects
434 Args :
437 =cut
439 sub get_external_documents{
440 my $self = shift;
442 return @{$self->{'_external_documents'}} if exists($self->{'_external_documents'});
443 return ();
446 =head2 add_external_document
448 Title : add_external_document
449 Usage :
450 Function: Add one or more external_document(s) to this object.
452 This is an element of the InterPro xml schema.
454 Example :
455 Returns :
456 Args : One or more Bio::Annotation::DBLink objects.
459 =cut
461 sub add_external_document{
462 my $self = shift;
464 $self->{'_external_documents'} = [] unless exists($self->{'_external_documents'});
465 push(@{$self->{'_external_documents'}}, @_);
468 =head2 remove_external_documents
470 Title : remove_external_documents
471 Usage :
472 Function: Remove all external_documents for this class.
474 This is an element of the InterPro xml schema.
476 Example :
477 Returns : The list of previous external_documents as an array of
478 Bio::Annotation::DBLink objects.
479 Args :
482 =cut
484 sub remove_external_documents{
485 my $self = shift;
487 my @arr = $self->get_external_documents();
488 $self->{'_external_documents'} = [];
489 return @arr;
492 =head2 class_list
494 Title : class_list
495 Usage : $obj->class_list($newval)
496 Function: Set/get for class list element of the InterPro xml schema
497 Example :
498 Returns : reference to an array of Bio::Annotation::DBLink objects
499 Args : reference to an array of Bio::Annotation::DBLink objects
502 =cut
504 sub class_list{
505 my ($self, $value) = @_;
507 if( defined $value) {
508 $self->{'class_list'} = $value;
511 return $self->{'class_list'};
514 =head2 to_string
516 Title : to_string()
517 Usage : print $term->to_string();
518 Function: to_string method for InterPro terms.
519 Returns : A string representation of this InterPro term.
520 Args :
522 =cut
524 sub to_string {
525 my($self) = @_;
526 my $s = "";
528 $s .= "-- InterPro id:\n";
529 $s .= $self->interpro_id()."\n";
530 if (defined $self->name) {
531 $s .= "-- Name:\n";
532 $s .= $self->name()."\n";
533 $s .= "-- Definition:\n";
534 $s .= $self->definition()."\n";
535 $s .= "-- Category:\n";
536 if ( defined( $self->ontology() ) ) {
537 $s .= $self->ontology()->name()."\n";
538 } else {
539 $s .= "\n";
541 $s .= "-- Version:\n";
542 $s .= $self->version()."\n";
543 $s .= "-- Is obsolete:\n";
544 $s .= $self->is_obsolete()."\n";
545 $s .= "-- Comment:\n";
546 $s .= $self->comment()."\n";
547 if (defined $self->get_references) {
548 $s .= "-- References:\n";
549 foreach my $ref ( $self->get_references ) {
550 $s .= $ref->authors."\n".$ref->title."\n".$ref->location."\n\n";
552 $s .= "\n";
554 if (defined $self->get_members) {
555 $s .= "-- Member List:\n";
556 foreach my $ref ( $self->get_members ) {
557 $s .= $ref->database."\t".$ref->primary_id."\n";
559 $s .= "\n";
561 if (defined $self->get_external_documents) {
562 $s .= "-- External Document List:\n";
563 foreach my $ref ( $self->get_external_documents ) {
564 $s .= $ref->database."\t".$ref->primary_id."\n";
566 $s .= "\n";
568 if (defined $self->get_examples) {
569 $s .= "-- Examples:\n";
570 foreach my $ref ( $self->get_examples ) {
571 $s .= $ref->database."\t".$ref->primary_id."\t".$ref->comment."\n";
573 $s .= "\n";
575 if (defined $self->class_list) {
576 $s .= "-- Class List:\n";
577 foreach my $ref ( @{$self->class_list} ) {
578 $s .= $ref->primary_id."\n";
580 $s .= "\n";
582 if ($self->get_secondary_ids) {
583 $s .= "-- Secondary IDs:\n";
584 foreach my $ref ( $self->get_secondary_ids() ) {
585 $s .= $ref."\n";
587 $s .= "\n";
590 else {
591 $s .= "InterPro term not fully instantiated\n";
593 return $s;
596 =head1 Deprecated methods
598 These are here for backwards compatibility.
600 =cut
602 =head2 secondary_ids
604 Title : secondary_ids
605 Usage : $obj->secondary_ids($newval)
606 Function: This is deprecated. Use get_secondary_ids() or
607 add_secondary_id() instead.
608 Example :
609 Returns : reference to an array of strings
610 Args : reference to an array of strings
613 =cut
615 sub secondary_ids{
616 my $self = shift;
617 my @ids;
619 $self->warn("secondary_ids is deprecated. Use ".
620 "get_secondary_ids/add_secondary_id instead.");
622 # set mode?
623 if(@_) {
624 my $sids = shift;
625 if($sids) {
626 $self->add_secondary_id(@$sids);
627 @ids = @$sids;
628 } else {
629 # we interpret setting to undef as removing the array
630 $self->remove_secondary_ids();
632 } else {
633 # no; get mode
634 @ids = $self->get_secondary_ids();
636 return \@ids;