~ubuntu-branches/ubuntu/karmic/bioperl/karmic

« back to all changes in this revision

Viewing changes to Bio/Annotation/OntologyTerm.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# $Id: OntologyTerm.pm,v 1.8 2003/10/13 20:02:43 lapp Exp $
 
2
#
 
3
# BioPerl module for Bio::Annotation::OntologyTerm
 
4
#
 
5
# Cared for by Hilmar Lapp <hlapp at gmx.net>
 
6
#
 
7
# Copyright Hilmar Lapp
 
8
#
 
9
# You may distribute this module under the same terms as perl itself
 
10
 
 
11
 
12
# (c) Hilmar Lapp, hlapp at gmx.net, 2002.
 
13
# (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
 
14
#
 
15
# You may distribute this module under the same terms as perl itself.
 
16
# Refer to the Perl Artistic License (see the license accompanying this
 
17
# software package, or see http://www.perl.com/language/misc/Artistic.html)
 
18
# for the terms under which you may use, modify, and redistribute this module.
 
19
 
20
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 
21
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 
22
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
23
#
 
24
 
 
25
# POD documentation - main docs before the code
 
26
 
 
27
=head1 NAME
 
28
 
 
29
Bio::Annotation::OntologyTerm - An ontology term adapted to AnnotationI
 
30
 
 
31
=head1 SYNOPSIS
 
32
 
 
33
   use Bio::Annotation::OntologyTerm;
 
34
   use Bio::Annotation::Collection;
 
35
   use Bio::Ontology::Term;
 
36
 
 
37
   my $coll = new Bio::Annotation::Collection;
 
38
 
 
39
   # this also implements a tag/value pair, where tag _and_ value are treated
 
40
   # as ontology terms
 
41
   my $annterm = new Bio::Annotation::OntologyTerm(-label => 'ABC1',
 
42
                                                   -tagname => 'Gene Name');
 
43
   # ontology terms can be added directly - they implicitly have a tag
 
44
   $coll->add_Annotation($annterm);
 
45
 
 
46
   # implementation is by composition - you can get/set the term object
 
47
   # e.g.
 
48
   my $term = $annterm->term(); # term is-a Bio::Ontology::TermI
 
49
   print "ontology term ",$term->name()," (ID ",$term->identifier(),
 
50
         "), ontology ",$term->ontology()->name(),"\n";
 
51
   $term = Bio::Ontology::Term->new(-name => 'ABC2', -ontology => 'Gene Name');
 
52
   $annterm->term($term);
 
53
 
 
54
=head1 DESCRIPTION
 
55
 
 
56
Ontology term annotation object 
 
57
 
 
58
=head1 FEEDBACK
 
59
 
 
60
=head2 Mailing Lists
 
61
 
 
62
User feedback is an integral part of the evolution of this and other
 
63
Bioperl modules. Send your comments and suggestions preferably to one
 
64
of the Bioperl mailing lists. Your participation is much appreciated.
 
65
 
 
66
  bioperl-l@bioperl.org              - General discussion
 
67
  http://bio.perl.org/MailList.html  - About the mailing lists
 
68
 
 
69
=head2 Reporting Bugs
 
70
 
 
71
Report bugs to the Bioperl bug tracking system to help us keep track
 
72
the bugs and their resolution.  Bug reports can be submitted via email
 
73
or the web:
 
74
 
 
75
  bioperl-bugs@bioperl.org
 
76
  http://bugzilla.bioperl.org/
 
77
 
 
78
=head1 AUTHOR - Hilmar Lapp
 
79
 
 
80
Email bioperl-l@bio.perl.org
 
81
Email hlapp at gmx.net
 
82
 
 
83
 
 
84
=head1 APPENDIX
 
85
 
 
86
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
 
87
 
 
88
=cut
 
89
 
 
90
 
 
91
# Let the code begin...
 
92
 
 
93
 
 
94
package Bio::Annotation::OntologyTerm;
 
95
use vars qw(@ISA);
 
96
use strict;
 
97
 
 
98
# Object preamble - inherits from Bio::Root::Root
 
99
 
 
100
use Bio::AnnotationI;
 
101
use Bio::Ontology::TermI;
 
102
use Bio::Ontology::Term;
 
103
use Bio::Root::Root;
 
104
 
 
105
@ISA = qw(Bio::Root::Root Bio::AnnotationI Bio::Ontology::TermI);
 
106
 
 
107
=head2 new
 
108
 
 
109
 Title   : new
 
110
 Usage   : my $sv = new Bio::Annotation::OntologyTerm;
 
111
 Function: Instantiate a new OntologyTerm object
 
112
 Returns : Bio::Annotation::OntologyTerm object
 
113
 Args    : -term => $term to initialize the term data field [optional]
 
114
           Most named arguments that Bio::Ontology::Term accepts will work
 
115
           here too. -label is a synonym for -name, -tagname is a synonym for
 
116
           -ontology.
 
117
 
 
118
=cut
 
119
 
 
120
sub new{
 
121
    my ($class,@args) = @_;
 
122
    
 
123
    my $self = $class->SUPER::new(@args);
 
124
    
 
125
    my ($term,$name,$label,$identifier,$definition,$ont,$tag) =
 
126
        $self->_rearrange([qw(TERM
 
127
                          NAME
 
128
                          LABEL
 
129
                          IDENTIFIER
 
130
                          DEFINITION
 
131
                          ONTOLOGY
 
132
                          TAGNAME)],
 
133
                      @args);
 
134
    if($term) {
 
135
        $self->term($term);
 
136
    } else {
 
137
        $self->name($name || $label) if $name || $label;
 
138
        $self->identifier($identifier) if $identifier;
 
139
        $self->definition($definition) if $definition;
 
140
    }
 
141
    $self->ontology($ont || $tag) if $ont || $tag;
 
142
    
 
143
    return $self;
 
144
}
 
145
 
 
146
 
 
147
=head1 AnnotationI implementing functions
 
148
 
 
149
=cut
 
150
 
 
151
=head2 as_text
 
152
 
 
153
 Title   : as_text
 
154
 Usage   : my $text = $obj->as_text
 
155
 Function: return the string "Name: $v" where $v is the name of the term
 
156
 Returns : string
 
157
 Args    : none
 
158
 
 
159
 
 
160
=cut
 
161
 
 
162
sub as_text{
 
163
   my ($self) = @_;
 
164
 
 
165
   return $self->tagname()."|".$self->name()."|".$self->identifier();
 
166
}
 
167
 
 
168
=head2 hash_tree
 
169
 
 
170
 Title   : hash_tree
 
171
 Usage   : my $hashtree = $value->hash_tree
 
172
 Function: For supporting the AnnotationI interface just returns the value
 
173
           as a hashref with the key 'value' pointing to the value
 
174
 Returns : hashrf
 
175
 Args    : none
 
176
 
 
177
 
 
178
=cut
 
179
 
 
180
sub hash_tree{
 
181
   my ($self) = @_;
 
182
   
 
183
   my $h = {};
 
184
   $h->{'name'} = $self->name();
 
185
   $h->{'identifier'} = $self->identifier();
 
186
   $h->{'definition'} = $self->definition();
 
187
   $h->{'synonyms'} = [$self->get_synonyms()];
 
188
}
 
189
 
 
190
 
 
191
=head2 tagname
 
192
 
 
193
 Title   : tagname
 
194
 Usage   : $obj->tagname($newval)
 
195
 Function: Get/set the tagname for this annotation value.
 
196
 
 
197
           Setting this is optional. If set, it obviates the need to provide
 
198
           a tag to AnnotationCollection when adding this object.
 
199
 
 
200
           This is aliased to ontology() here.
 
201
 Example : 
 
202
 Returns : value of tagname (a scalar)
 
203
 Args    : new value (a scalar, optional)
 
204
 
 
205
 
 
206
=cut
 
207
 
 
208
sub tagname{
 
209
    my $self = shift;
 
210
 
 
211
    return $self->ontology(@_) if @_;
 
212
    # if in get mode we need to get the name from the ontology
 
213
    my $ont = $self->ontology();
 
214
    return ref($ont) ? $ont->name() : $ont;
 
215
}
 
216
 
 
217
=head1 Methods for Bio::Ontology::TermI compliance
 
218
 
 
219
=cut
 
220
 
 
221
=head2 term
 
222
 
 
223
 Title   : term
 
224
 Usage   : $obj->term($newval)
 
225
 Function: Get/set the Bio::Ontology::TermI implementing object.
 
226
 
 
227
           We implement TermI by composition, and this method sets/gets the
 
228
           object we delegate to.
 
229
 Example : 
 
230
 Returns : value of term (a Bio::Ontology::TermI compliant object)
 
231
 Args    : new value (a Bio::Ontology::TermI compliant object, optional)
 
232
 
 
233
 
 
234
=cut
 
235
 
 
236
sub term{
 
237
    my ($self,$value) = @_;
 
238
    if( defined $value) {
 
239
        $self->{'term'} = $value;
 
240
    }
 
241
    if(! exists($self->{'term'})) {
 
242
        $self->{'term'} = Bio::Ontology::Term->new();
 
243
    }
 
244
    return $self->{'term'};
 
245
}
 
246
 
 
247
=head2 identifier
 
248
 
 
249
 Title   : identifier
 
250
 Usage   : $term->identifier( "0003947" );
 
251
           or
 
252
           print $term->identifier();
 
253
 Function: Set/get for the identifier of this Term.
 
254
 Returns : The identifier [scalar].
 
255
 Args    : The identifier [scalar] (optional).
 
256
 
 
257
=cut
 
258
 
 
259
sub identifier {
 
260
    return shift->term()->identifier(@_);
 
261
} # identifier
 
262
 
 
263
=head2 name
 
264
 
 
265
 Title   : name
 
266
 Usage   : $term->name( "N-acetylgalactosaminyltransferase" );
 
267
           or
 
268
           print $term->name();
 
269
 Function: Set/get for the name of this Term.
 
270
 Returns : The name [scalar].
 
271
 Args    : The name [scalar] (optional).
 
272
 
 
273
=cut
 
274
 
 
275
sub name {
 
276
    return shift->term()->name(@_);
 
277
} # name
 
278
 
 
279
 
 
280
=head2 definition
 
281
 
 
282
 Title   : definition
 
283
 Usage   : $term->definition( "Catalysis of ..." );
 
284
           or
 
285
           print $term->definition();
 
286
 Function: Set/get for the definition of this Term.
 
287
 Returns : The definition [scalar].
 
288
 Args    : The definition [scalar] (optional).
 
289
 
 
290
=cut
 
291
 
 
292
sub definition {
 
293
    return shift->term()->definition(@_);
 
294
} # definition
 
295
 
 
296
=head2 ontology
 
297
 
 
298
 Title   : ontology
 
299
 Usage   : $term->ontology( $top );
 
300
           or 
 
301
           $top = $term->ontology();
 
302
 Function: Set/get for a relationship between this Term and
 
303
           another Term (e.g. the top level of the ontology).
 
304
 Returns : The ontology of this Term [TermI].
 
305
 Args    : The ontology of this Term [TermI or scalar -- which
 
306
           becomes the name of the catagory term] (optional).
 
307
 
 
308
=cut
 
309
 
 
310
sub ontology {
 
311
    return shift->term()->ontology(@_);
 
312
}
 
313
 
 
314
=head2 is_obsolete
 
315
 
 
316
 Title   : is_obsolete
 
317
 Usage   : $term->is_obsolete( 1 );
 
318
           or
 
319
           if ( $term->is_obsolete() )
 
320
 Function: Set/get for the obsoleteness of this Term.
 
321
 Returns : the obsoleteness [0 or 1].
 
322
 Args    : the obsoleteness [0 or 1] (optional).
 
323
 
 
324
=cut
 
325
 
 
326
sub is_obsolete {
 
327
    return shift->term()->is_obsolete(@_);
 
328
} # is_obsolete
 
329
 
 
330
=head2 comment
 
331
 
 
332
 Title   : comment
 
333
 Usage   : $term->comment( "Consider the term ..." );
 
334
           or 
 
335
           print $term->comment();
 
336
 Function: Set/get for an arbitrary comment about this Term.
 
337
 Returns : A comment.
 
338
 Args    : A comment (optional).
 
339
 
 
340
=cut
 
341
 
 
342
sub comment {
 
343
    return shift->term()->comment(@_);
 
344
} # comment
 
345
 
 
346
=head2 get_synonyms
 
347
 
 
348
 Title   : get_synonyms()
 
349
 Usage   : @aliases = $term->get_synonyms();                 
 
350
 Function: Returns a list of aliases of this Term.
 
351
 Returns : A list of aliases [array of [scalar]].
 
352
 Args    :
 
353
 
 
354
=cut
 
355
 
 
356
sub get_synonyms {
 
357
    return shift->term()->get_synonyms(@_);
 
358
} # get_synonyms
 
359
 
 
360
=head2 add_synonym
 
361
 
 
362
 Title   : add_synonym
 
363
 Usage   : $term->add_synonym( @asynonyms );
 
364
           or
 
365
           $term->add_synonym( $synonym );                  
 
366
 Function: Pushes one or more synonyms into the list of synonyms.
 
367
 Returns : 
 
368
 Args    : One synonym [scalar] or a list of synonyms [array of [scalar]].
 
369
 
 
370
=cut
 
371
 
 
372
sub add_synonym {
 
373
    return shift->term()->add_synonym(@_);
 
374
} # add_synonym
 
375
 
 
376
 
 
377
=head2 remove_synonyms
 
378
 
 
379
 Title   : remove_synonyms()
 
380
 Usage   : $term->remove_synonyms();
 
381
 Function: Deletes (and returns) the synonyms of this Term.
 
382
 Returns : A list of synonyms [array of [scalar]].
 
383
 Args    :
 
384
 
 
385
=cut
 
386
 
 
387
sub remove_synonyms {
 
388
    return shift->term()->remove_synonyms(@_);
 
389
} # remove_synonyms
 
390
 
 
391
=head2 get_dblinks
 
392
 
 
393
 Title   : get_dblinks()
 
394
 Usage   : @ds = $term->get_dblinks();
 
395
 Function: Returns a list of each dblinks of this GO term.
 
396
 Returns : A list of dblinks [array of [scalars]].
 
397
 Args    :
 
398
 
 
399
=cut
 
400
 
 
401
sub get_dblinks {
 
402
    return shift->term->get_dblinks(@_);
 
403
} # get_dblinks
 
404
 
 
405
 
 
406
=head2 add_dblink
 
407
 
 
408
 Title   : add_dblink
 
409
 Usage   : $term->add_dblink( @dbls );
 
410
           or
 
411
           $term->add_dblink( $dbl );                  
 
412
 Function: Pushes one or more dblinks
 
413
           into the list of dblinks.
 
414
 Returns : 
 
415
 Args    : One  dblink [scalar] or a list of
 
416
            dblinks [array of [scalars]].
 
417
 
 
418
=cut
 
419
 
 
420
sub add_dblink {
 
421
    return shift->term->add_dblink(@_);
 
422
} # add_dblink
 
423
 
 
424
 
 
425
=head2 remove_dblinks
 
426
 
 
427
 Title   : remove_dblinks()
 
428
 Usage   : $term->remove_dblinks();
 
429
 Function: Deletes (and returns) the definition references of this GO term.
 
430
 Returns : A list of definition references [array of [scalars]].
 
431
 Args    :
 
432
 
 
433
=cut
 
434
 
 
435
sub remove_dblinks {
 
436
    return shift->term->remove_dblinks(@_);
 
437
} # remove_dblinks
 
438
 
 
439
=head2 get_secondary_ids
 
440
 
 
441
 Title   : get_secondary_ids
 
442
 Usage   : @ids = $term->get_secondary_ids();
 
443
 Function: Returns a list of secondary identifiers of this Term.
 
444
 
 
445
           Secondary identifiers mostly originate from merging terms,
 
446
           or possibly also from splitting terms.
 
447
 
 
448
 Returns : A list of secondary identifiers [array of [scalar]]
 
449
 Args    :
 
450
 
 
451
=cut
 
452
 
 
453
sub get_secondary_ids {
 
454
    return shift->term->get_secondary_ids(@_);
 
455
} # get_secondary_ids
 
456
 
 
457
 
 
458
=head2 add_secondary_id
 
459
 
 
460
 Title   : add_secondary_id
 
461
 Usage   : $term->add_secondary_id( @ids );
 
462
           or
 
463
           $term->add_secondary_id( $id );                  
 
464
 Function: Adds one or more secondary identifiers to this term.
 
465
 Returns : 
 
466
 Args    : One or more secondary identifiers [scalars]
 
467
 
 
468
=cut
 
469
 
 
470
sub add_secondary_id {
 
471
    return shift->term->add_secondary_id(@_);
 
472
} # add_secondary_id
 
473
 
 
474
 
 
475
=head2 remove_secondary_ids
 
476
 
 
477
 Title   : remove_secondary_ids
 
478
 Usage   : $term->remove_secondary_ids();
 
479
 Function: Deletes (and returns) the secondary identifiers of this Term.
 
480
 Returns : The previous list of secondary identifiers [array of [scalars]]
 
481
 Args    :
 
482
 
 
483
=cut
 
484
 
 
485
sub remove_secondary_ids {
 
486
    return shift->term->remove_secondary_ids(@_);
 
487
} # remove_secondary_ids
 
488
 
 
489
 
 
490
1;