tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / Bio / Ontology / InterProTerm.pm
blobf72c733ad625575f0c8f4b22526763429e5293d5
1 # $Id$
3 # BioPerl module for Bio::Ontology::InterProTerm
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Peter Dimitrov <dimitrov@gnf.org>
9 # Copyright Peter Dimitrov
10 # (c) Peter Dimitrov, dimitrov@gnf.org, 2002.
11 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
13 # You may distribute this module under the same terms as perl itself.
14 # Refer to the Perl Artistic License (see the license accompanying this
15 # software package, or see http://www.perl.com/language/misc/Artistic.html)
16 # for the terms under which you may use, modify, and redistribute this module.
18 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
19 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 # POD documentation - main docs before the code
24 =head1 NAME
26 Bio::Ontology::InterProTerm - Implementation of InterProI term interface
28 =head1 SYNOPSIS
30 my $term = Bio::Ontology::InterProTerm->new(
31 -interpro_id => "IPR000001",
32 -name => "Kringle",
33 -definition => "Kringles are autonomous structural domains ...",
34 -ontology => "Domain"
36 print $term->interpro_id(), "\n";
37 print $term->name(), "\n";
38 print $term->definition(), "\n";
39 print $term->is_obsolete(), "\n";
40 print $term->ontology->name(), "\n";
42 =head1 DESCRIPTION
44 This is a simple extension of L<Bio::Ontology::Term> for InterPro terms.
46 =head1 FEEDBACK
48 =head2 Mailing Lists
50 User feedback is an integral part of the evolution of this and other
51 Bioperl modules. Send your comments and suggestions preferably to
52 the Bioperl mailing list. Your participation is much appreciated.
54 bioperl-l@bioperl.org - General discussion
55 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
57 =head2 Support
59 Please direct usage questions or support issues to the mailing list:
61 I<bioperl-l@bioperl.org>
63 rather than to the module maintainer directly. Many experienced and
64 reponsive experts will be able look at the problem and quickly
65 address it. Please include a thorough description of the problem
66 with code and data examples if at all possible.
68 =head2 Reporting Bugs
70 Report bugs to the Bioperl bug tracking system to help us keep track
71 of the bugs and their resolution. Bug reports can be submitted via
72 the web:
74 http://bugzilla.open-bio.org/
76 =head1 AUTHOR - Peter Dimitrov
78 Email dimitrov@gnf.org
80 =head1 APPENDIX
82 The rest of the documentation details each of the object methods.
83 Internal methods are usually preceded with a _
85 =cut
88 # Let the code begin...
91 package Bio::Ontology::InterProTerm;
92 use strict;
94 use Bio::Annotation::Reference;
96 use constant INTERPRO_ID_DEFAULT => "IPR000000";
98 use base qw(Bio::Ontology::Term);
100 =head2 new
102 Title : new
103 Usage : $term = Bio::Ontology::InterProTerm->new( -interpro_id => "IPR000002",
104 -name => "Cdc20/Fizzy",
105 -definition => "The Cdc20/Fizzy region is almost always ...",
106 -ontology => "Domain"
109 Function: Creates a new Bio::Ontology::InterProTerm.
110 Example :
111 Returns : A new Bio::Ontology::InterProTerm object.
112 Args :
113 -interpro_id => the InterPro ID of the term. Has the form IPRdddddd, where dddddd is a zero-padded six digit number
114 -name => the name of this InterPro term [scalar]
115 -definition => the definition/abstract of this InterPro term [scalar]
116 -ontology => ontology of InterPro terms [Bio::Ontology::OntologyI]
117 -comment => a comment [scalar]
119 =cut
121 sub new{
122 my ($class, @args) = @_;
123 my $self = $class->SUPER::new(@args);
125 my ( $interpro_id,
126 $short_name)
127 = $self->_rearrange( [qw( INTERPRO_ID
128 SHORT_NAME
130 ], @args );
132 $interpro_id && $self->interpro_id( $interpro_id );
133 $short_name && $self->short_name( $short_name );
135 return $self;
138 =head2 init
140 Title : init
141 Usage : $term->init();
142 Function: Initializes this InterProTerm to all "" and empty lists.
143 Example :
144 Returns :
145 Args :
148 =cut
150 sub init{
151 my $self = shift;
153 # first call the inherited version to properly chain up the hierarchy
154 $self->SUPER::init(@_);
156 # then only initialize what we implement ourselves here
157 $self->interpro_id( INTERPRO_ID_DEFAULT );
158 $self->short_name("");
162 =head2 _check_interpro_id
164 Title : _check_interpro_id
165 Usage :
166 Function: Performs simple check in order to validate that its argument has the form IPRdddddd, where dddddd is a zero-padded six digit number.
167 Example :
168 Returns : Returns its argument if valid, otherwise throws exception.
169 Args : String
172 =cut
174 sub _check_interpro_id{
175 my ($self, $value) = @_;
177 $self->throw( "InterPro ID ".$value." is incorrect\n" )
178 unless ( $value =~ /^IPR\d{6}$/ ||
179 $value eq INTERPRO_ID_DEFAULT );
181 return $value;
184 =head2 interpro_id
186 Title : interpro_id
187 Usage : $obj->interpro_id($newval)
188 Function: Set/get for the interpro_id of this InterProTerm
189 Example :
190 Returns : value of interpro_id (a scalar)
191 Args : new value (a scalar, optional)
194 =cut
196 sub interpro_id{
197 my ($self, $value) = @_;
199 if( defined $value) {
200 $value = $self->_check_interpro_id($value);
201 return $self->identifier($value);
204 return $self->identifier();
207 =head2 short_name
209 Title : short_name
210 Usage : $obj->short_name($newval)
211 Function: Set/get for the short name of this InterProTerm.
212 Example :
213 Returns : value of short_name (a scalar)
214 Args : new value (a scalar, optional)
217 =cut
219 sub short_name{
220 my ($self, $value) = @_;
222 if( defined $value) {
223 $self->{'short_name'} = $value ? $value : undef;
226 return $self->{'short_name'};
229 =head2 protein_count
231 Title : protein_count
232 Usage : $obj->protein_count($newval)
233 Function: Set/get for the protein count of this InterProTerm.
234 Example :
235 Returns : value of protein_count (a scalar)
236 Args : new value (a scalar, optional)
239 =cut
241 sub protein_count{
242 my ($self,$value) = @_;
244 if( defined $value) {
245 $self->{'protein_count'} = $value ? $value : undef;
248 return $self->{'protein_count'};
251 =head2 get_references
253 Title : get_references
254 Usage :
255 Function: Get the references for this InterPro term.
256 Example :
257 Returns : An array of L<Bio::Annotation::Reference> objects
258 Args :
261 =cut
263 sub get_references{
264 my $self = shift;
266 return @{$self->{"_references"}} if exists($self->{"_references"});
267 return ();
270 =head2 add_reference
272 Title : add_reference
273 Usage :
274 Function: Add one or more references to this InterPro term.
275 Example :
276 Returns :
277 Args : One or more L<Bio::Annotation::Reference> objects.
280 =cut
282 sub add_reference{
283 my $self = shift;
285 $self->{"_references"} = [] unless exists($self->{"_references"});
286 push(@{$self->{"_references"}}, @_);
289 =head2 remove_references
291 Title : remove_references
292 Usage :
293 Function: Remove all references for this InterPro term.
294 Example :
295 Returns : The list of previous references as an array of
296 L<Bio::Annotation::Reference> objects.
297 Args :
300 =cut
302 sub remove_references{
303 my $self = shift;
305 my @arr = $self->get_references();
306 $self->{"_references"} = [];
307 return @arr;
310 =head2 get_members
312 Title : get_members
313 Usage : @arr = get_members()
314 Function: Get the list of member(s) for this object.
315 Example :
316 Returns : An array of Bio::Annotation::DBLink objects
317 Args :
320 =cut
322 sub get_members{
323 my $self = shift;
325 return @{$self->{'_members'}} if exists($self->{'_members'});
326 return ();
329 =head2 add_member
331 Title : add_member
332 Usage :
333 Function: Add one or more member(s) to this object.
334 Example :
335 Returns :
336 Args : One or more Bio::Annotation::DBLink objects.
339 =cut
341 sub add_member{
342 my $self = shift;
344 $self->{'_members'} = [] unless exists($self->{'_members'});
345 push(@{$self->{'_members'}}, @_);
348 =head2 remove_members
350 Title : remove_members
351 Usage :
352 Function: Remove all members for this class.
353 Example :
354 Returns : The list of previous members as an array of
355 Bio::Annotation::DBLink objects.
356 Args :
359 =cut
361 sub remove_members{
362 my $self = shift;
364 my @arr = $self->get_members();
365 $self->{'_members'} = [];
366 return @arr;
369 =head2 get_examples
371 Title : get_examples
372 Usage : @arr = get_examples()
373 Function: Get the list of example(s) for this object.
375 This is an element of the InterPro xml schema.
377 Example :
378 Returns : An array of Bio::Annotation::DBLink objects
379 Args :
382 =cut
384 sub get_examples{
385 my $self = shift;
387 return @{$self->{'_examples'}} if exists($self->{'_examples'});
388 return ();
391 =head2 add_example
393 Title : add_example
394 Usage :
395 Function: Add one or more example(s) to this object.
397 This is an element of the InterPro xml schema.
399 Example :
400 Returns :
401 Args : One or more Bio::Annotation::DBLink objects.
404 =cut
406 sub add_example{
407 my $self = shift;
409 $self->{'_examples'} = [] unless exists($self->{'_examples'});
410 push(@{$self->{'_examples'}}, @_);
413 =head2 remove_examples
415 Title : remove_examples
416 Usage :
417 Function: Remove all examples for this class.
419 This is an element of the InterPro xml schema.
421 Example :
422 Returns : The list of previous examples as an array of
423 Bio::Annotation::DBLink objects.
424 Args :
427 =cut
429 sub remove_examples{
430 my $self = shift;
432 my @arr = $self->get_examples();
433 $self->{'_examples'} = [];
434 return @arr;
437 =head2 get_external_documents
439 Title : get_external_documents
440 Usage : @arr = get_external_documents()
441 Function: Get the list of external_document(s) for this object.
443 This is an element of the InterPro xml schema.
445 Example :
446 Returns : An array of Bio::Annotation::DBLink objects
447 Args :
450 =cut
452 sub get_external_documents{
453 my $self = shift;
455 return @{$self->{'_external_documents'}} if exists($self->{'_external_documents'});
456 return ();
459 =head2 add_external_document
461 Title : add_external_document
462 Usage :
463 Function: Add one or more external_document(s) to this object.
465 This is an element of the InterPro xml schema.
467 Example :
468 Returns :
469 Args : One or more Bio::Annotation::DBLink objects.
472 =cut
474 sub add_external_document{
475 my $self = shift;
477 $self->{'_external_documents'} = [] unless exists($self->{'_external_documents'});
478 push(@{$self->{'_external_documents'}}, @_);
481 =head2 remove_external_documents
483 Title : remove_external_documents
484 Usage :
485 Function: Remove all external_documents for this class.
487 This is an element of the InterPro xml schema.
489 Example :
490 Returns : The list of previous external_documents as an array of
491 Bio::Annotation::DBLink objects.
492 Args :
495 =cut
497 sub remove_external_documents{
498 my $self = shift;
500 my @arr = $self->get_external_documents();
501 $self->{'_external_documents'} = [];
502 return @arr;
505 =head2 class_list
507 Title : class_list
508 Usage : $obj->class_list($newval)
509 Function: Set/get for class list element of the InterPro xml schema
510 Example :
511 Returns : reference to an array of Bio::Annotation::DBLink objects
512 Args : reference to an array of Bio::Annotation::DBLink objects
515 =cut
517 sub class_list{
518 my ($self, $value) = @_;
520 if( defined $value) {
521 $self->{'class_list'} = $value;
524 return $self->{'class_list'};
527 =head2 to_string
529 Title : to_string()
530 Usage : print $term->to_string();
531 Function: to_string method for InterPro terms.
532 Returns : A string representation of this InterPro term.
533 Args :
535 =cut
537 sub to_string {
538 my($self) = @_;
539 my $s = "";
541 $s .= "-- InterPro id:\n";
542 $s .= $self->interpro_id()."\n";
543 if (defined $self->name) {
544 $s .= "-- Name:\n";
545 $s .= $self->name()."\n";
546 $s .= "-- Definition:\n";
547 $s .= $self->definition()."\n";
548 $s .= "-- Category:\n";
549 if ( defined( $self->ontology() ) ) {
550 $s .= $self->ontology()->name()."\n";
551 } else {
552 $s .= "\n";
554 $s .= "-- Version:\n";
555 $s .= $self->version()."\n";
556 $s .= "-- Is obsolete:\n";
557 $s .= $self->is_obsolete()."\n";
558 $s .= "-- Comment:\n";
559 $s .= $self->comment()."\n";
560 if (defined $self->get_references) {
561 $s .= "-- References:\n";
562 foreach my $ref ( $self->get_references ) {
563 $s .= $ref->authors."\n".$ref->title."\n".$ref->location."\n\n";
565 $s .= "\n";
567 if (defined $self->get_members) {
568 $s .= "-- Member List:\n";
569 foreach my $ref ( $self->get_members ) {
570 $s .= $ref->database."\t".$ref->primary_id."\n";
572 $s .= "\n";
574 if (defined $self->get_external_documents) {
575 $s .= "-- External Document List:\n";
576 foreach my $ref ( $self->get_external_documents ) {
577 $s .= $ref->database."\t".$ref->primary_id."\n";
579 $s .= "\n";
581 if (defined $self->get_examples) {
582 $s .= "-- Examples:\n";
583 foreach my $ref ( $self->get_examples ) {
584 $s .= $ref->database."\t".$ref->primary_id."\t".$ref->comment."\n";
586 $s .= "\n";
588 if (defined $self->class_list) {
589 $s .= "-- Class List:\n";
590 foreach my $ref ( @{$self->class_list} ) {
591 $s .= $ref->primary_id."\n";
593 $s .= "\n";
595 if ($self->get_secondary_ids) {
596 $s .= "-- Secondary IDs:\n";
597 foreach my $ref ( $self->get_secondary_ids() ) {
598 $s .= $ref."\n";
600 $s .= "\n";
603 else {
604 $s .= "InterPro term not fully instantiated\n";
606 return $s;
609 =head1 Deprecated methods
611 These are here for backwards compatibility.
613 =cut
615 =head2 secondary_ids
617 Title : secondary_ids
618 Usage : $obj->secondary_ids($newval)
619 Function: This is deprecated. Use get_secondary_ids() or
620 add_secondary_id() instead.
621 Example :
622 Returns : reference to an array of strings
623 Args : reference to an array of strings
626 =cut
628 sub secondary_ids{
629 my $self = shift;
630 my @ids;
632 $self->warn("secondary_ids is deprecated. Use ".
633 "get_secondary_ids/add_secondary_id instead.");
635 # set mode?
636 if(@_) {
637 my $sids = shift;
638 if($sids) {
639 $self->add_secondary_id(@$sids);
640 @ids = @$sids;
641 } else {
642 # we interpret setting to undef as removing the array
643 $self->remove_secondary_ids();
645 } else {
646 # no; get mode
647 @ids = $self->get_secondary_ids();
649 return \@ids;