maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / lib / Bio / Ontology / InterProTerm.pm
blob69ef5de3024ac259396a2828443119a3784be55a
2 # BioPerl module for Bio::Ontology::InterProTerm
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Peter Dimitrov <dimitrov@gnf.org>
8 # Copyright Peter Dimitrov
9 # (c) Peter Dimitrov, dimitrov@gnf.org, 2002.
10 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
12 # You may distribute this module under the same terms as perl itself.
13 # Refer to the Perl Artistic License (see the license accompanying this
14 # software package, or see http://www.perl.com/language/misc/Artistic.html)
15 # for the terms under which you may use, modify, and redistribute this module.
17 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 # POD documentation - main docs before the code
23 =head1 NAME
25 Bio::Ontology::InterProTerm - Implementation of InterProI term interface
27 =head1 SYNOPSIS
29 my $term = Bio::Ontology::InterProTerm->new(
30 -interpro_id => "IPR000001",
31 -name => "Kringle",
32 -definition => "Kringles are autonomous structural domains ...",
33 -ontology => "Domain"
35 print $term->interpro_id(), "\n";
36 print $term->name(), "\n";
37 print $term->definition(), "\n";
38 print $term->is_obsolete(), "\n";
39 print $term->ontology->name(), "\n";
41 =head1 DESCRIPTION
43 This is a simple extension of L<Bio::Ontology::Term> for InterPro terms.
45 =head1 FEEDBACK
47 =head2 Mailing Lists
49 User feedback is an integral part of the evolution of this and other
50 Bioperl modules. Send your comments and suggestions preferably to
51 the Bioperl mailing list. Your participation is much appreciated.
53 bioperl-l@bioperl.org - General discussion
54 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
56 =head2 Support
58 Please direct usage questions or support issues to the mailing list:
60 I<bioperl-l@bioperl.org>
62 rather than to the module maintainer directly. Many experienced and
63 reponsive experts will be able look at the problem and quickly
64 address it. Please include a thorough description of the problem
65 with code and data examples if at all possible.
67 =head2 Reporting Bugs
69 Report bugs to the Bioperl bug tracking system to help us keep track
70 of the bugs and their resolution. Bug reports can be submitted via
71 the web:
73 https://github.com/bioperl/bioperl-live/issues
75 =head1 AUTHOR - Peter Dimitrov
77 Email dimitrov@gnf.org
79 =head1 APPENDIX
81 The rest of the documentation details each of the object methods.
82 Internal methods are usually preceded with a _
84 =cut
87 # Let the code begin...
90 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 # Defined in parent class
265 #sub get_references{
266 # my $self = shift;
268 # return @{$self->{"_references"}} if exists($self->{"_references"});
269 # return ();
272 =head2 add_reference
274 Title : add_reference
275 Usage :
276 Function: Add one or more references to this InterPro term.
277 Example :
278 Returns :
279 Args : One or more L<Bio::Annotation::Reference> objects.
282 =cut
284 # Defined in parent class
286 #sub add_reference{
287 # my $self = shift;
289 # $self->{"_references"} = [] unless exists($self->{"_references"});
290 # push(@{$self->{"_references"}}, @_);
293 =head2 remove_references
295 Title : remove_references
296 Usage :
297 Function: Remove all references for this InterPro term.
298 Example :
299 Returns : The list of previous references as an array of
300 L<Bio::Annotation::Reference> objects.
301 Args :
304 =cut
306 # Defined in parent class
307 #sub remove_references{
308 # my $self = shift;
310 # my @arr = $self->get_references();
311 # $self->{"_references"} = [];
312 # return @arr;
315 =head2 get_members
317 Title : get_members
318 Usage : @arr = get_members()
319 Function: Get the list of member(s) for this object.
320 Example :
321 Returns : An array of Bio::Annotation::DBLink objects
322 Args :
325 =cut
327 sub get_members{
328 my $self = shift;
329 return $self->get_dbxrefs('member_list');
332 =head2 add_member
334 Title : add_member
335 Usage :
336 Function: Add one or more member(s) to this object.
337 Example :
338 Returns :
339 Args : One or more Bio::Annotation::DBLink objects.
342 =cut
344 sub add_member{
345 my $self = shift;
346 $self->add_dbxref(-dbxrefs => \@_, -context => 'member_list');
349 =head2 remove_members
351 Title : remove_members
352 Usage :
353 Function: Remove all members for this class.
354 Example :
355 Returns : The list of previous members as an array of
356 Bio::Annotation::DBLink objects.
357 Args :
360 =cut
362 sub remove_members{
363 my $self = shift;
364 return $self->remove_dbxrefs('member_list');
367 =head2 get_examples
369 Title : get_examples
370 Usage : @arr = get_examples()
371 Function: Get the list of example(s) for this object.
373 This is an element of the InterPro xml schema.
375 Example :
376 Returns : An array of Bio::Annotation::DBLink objects
377 Args :
380 =cut
382 sub get_examples{
383 my $self = shift;
384 return $self->get_dbxrefs('example_list');
387 =head2 add_example
389 Title : add_example
390 Usage :
391 Function: Add one or more example(s) to this object.
393 This is an element of the InterPro xml schema.
395 Example :
396 Returns :
397 Args : One or more Bio::Annotation::DBLink objects.
400 =cut
402 sub add_example{
403 my $self = shift;
404 return $self->add_dbxref(-dbxrefs => \@_, -context => 'example_list');
407 =head2 remove_examples
409 Title : remove_examples
410 Usage :
411 Function: Remove all examples for this class.
413 This is an element of the InterPro xml schema.
415 Example :
416 Returns : The list of previous examples as an array of
417 Bio::Annotation::DBLink objects.
418 Args :
421 =cut
423 sub remove_examples{
424 my $self = shift;
425 return $self->remove_dbxrefs('example_list');
428 =head2 get_external_documents
430 Title : get_external_documents
431 Usage : @arr = get_external_documents()
432 Function: Get the list of external_document(s) for this object.
434 This is an element of the InterPro xml schema.
436 Example :
437 Returns : An array of Bio::Annotation::DBLink objects
438 Args :
441 =cut
443 sub get_external_documents{
444 my $self = shift;
445 return $self->get_dbxrefs('external_doc_list');
448 =head2 add_external_document
450 Title : add_external_document
451 Usage :
452 Function: Add one or more external_document(s) to this object.
454 This is an element of the InterPro xml schema.
456 Example :
457 Returns :
458 Args : One or more Bio::Annotation::DBLink objects.
461 =cut
463 sub add_external_document{
464 my $self = shift;
465 return $self->add_dbxref(-dbxrefs => \@_, -context => 'external_doc_list');
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;
486 return $self->remove_dbxrefs('external_doc_list');
489 =head2 class_list
491 Title : class_list
492 Usage : $obj->class_list($newval)
493 Function: Set/get for class list element of the InterPro xml schema
494 Example :
495 Returns : reference to an array of Bio::Annotation::DBLink objects
496 Args : reference to an array of Bio::Annotation::DBLink objects
498 =cut
500 # this is inconsistent with the above, but we work around it and hope nothing
501 # breaks
503 sub class_list{
504 my ($self, $value) = @_;
505 if( defined $value && ref $value eq 'ARRAY') {
506 if (!@$value) {
507 # passing an empty array ref is essentially same as remove_dbxrefs,
508 # so do that
509 $self->remove_dbxrefs('class_list');
510 } else {
511 $self->add_dbxref(-dbxrefs => $value, -context => 'class_list');
514 return [$self->get_dbxrefs('class_list')];
517 =head2 to_string
519 Title : to_string()
520 Usage : print $term->to_string();
521 Function: to_string method for InterPro terms.
522 Returns : A string representation of this InterPro term.
523 Args :
525 =cut
527 sub to_string {
528 my ($self) = @_;
529 my $s = "";
531 $s .= "-- InterPro id:\n";
532 $s .= $self->interpro_id() . "\n";
533 if ( defined $self->name ) {
534 $s .= "-- Name:\n";
535 $s .= $self->name() . "\n";
536 $s .= "-- Definition:\n";
537 $s .= ( $self->definition() || '' ) . "\n";
538 $s .= "-- Category:\n";
539 if ( defined( $self->ontology() ) ) {
540 $s .= $self->ontology()->name() . "\n";
542 else {
543 $s .= "\n";
545 $s .= "-- Version:\n";
546 $s .= ( $self->version() || '' ) . "\n";
547 $s .= "-- Is obsolete:\n";
548 $s .= $self->is_obsolete() . "\n";
549 $s .= "-- Comment:\n";
550 $s .= ( $self->comment() || '' ) . "\n";
551 if ( defined $self->get_references ) {
552 $s .= "-- References:\n";
553 foreach my $ref ( $self->get_references ) {
554 $s .=
555 $ref->authors . "\n"
556 . $ref->title . "\n"
557 . $ref->location . "\n\n";
559 $s .= "\n";
561 if ( defined $self->get_members ) {
562 $s .= "-- Member List:\n";
563 foreach my $ref ( $self->get_members ) {
564 $s .= $ref->database . "\t" . $ref->primary_id . "\n";
566 $s .= "\n";
568 if ( defined $self->get_external_documents ) {
569 $s .= "-- External Document List:\n";
570 foreach my $ref ( $self->get_external_documents ) {
571 $s .= $ref->database . "\t" . $ref->primary_id . "\n";
573 $s .= "\n";
575 if ( defined $self->get_examples ) {
576 $s .= "-- Examples:\n";
577 foreach my $ref ( $self->get_examples ) {
578 $s .= join( "\t",
579 map { $ref->$_ || '' } qw(database primary_id comment) )
580 . "\n";
582 $s .= "\n";
584 if ( defined $self->class_list ) {
585 $s .= "-- Class List:\n";
586 foreach my $ref ( @{ $self->class_list } ) {
587 $s .= $ref->primary_id . "\n";
589 $s .= "\n";
591 if ( $self->get_secondary_ids ) {
592 $s .= "-- Secondary IDs:\n";
593 foreach my $ref ( $self->get_secondary_ids() ) {
594 # TODO: getting undef here in some cases, needs to be checked
595 next unless defined ($ref);
596 $s .= $ref . "\n";
598 $s .= "\n";
601 else {
602 $s .= "InterPro term not fully instantiated\n";
604 return $s;
607 =head1 Deprecated methods
609 These are here for backwards compatibility.
611 =cut
613 =head2 secondary_ids
615 Title : secondary_ids
616 Usage : $obj->secondary_ids($newval)
617 Function: This is deprecated. Use get_secondary_ids() or
618 add_secondary_id() instead.
619 Example :
620 Returns : reference to an array of strings
621 Args : reference to an array of strings
624 =cut
626 sub secondary_ids{
627 my $self = shift;
628 my @ids;
630 $self->warn("secondary_ids is deprecated. Use ".
631 "get_secondary_ids/add_secondary_id instead.");
633 # set mode?
634 if(@_) {
635 my $sids = shift;
636 if($sids) {
637 $self->add_secondary_id(@$sids);
638 @ids = @$sids;
639 } else {
640 # we interpret setting to undef as removing the array
641 $self->remove_secondary_ids();
643 } else {
644 # no; get mode
645 @ids = $self->get_secondary_ids();
647 return \@ids;