3 # BioPerl module for Bio::Annotation::SimpleValue
5 # Cared for by bioperl <bioperl-l@bioperl.org>
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Annotation::SimpleValue - A simple scalar
19 use Bio::Annotation::SimpleValue;
20 use Bio::Annotation::Collection;
22 my $col = Bio::Annotation::Collection->new();
23 my $sv = Bio::Annotation::SimpleValue->new(-value => 'someval');
24 $col->add_Annotation('tagname', $sv);
28 Scalar value annotation object
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to one
36 of the Bioperl mailing lists. Your participation is much appreciated.
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
43 Report bugs to the Bioperl bug tracking system to help us keep track
44 the bugs and their resolution. Bug reports can be submitted via
47 http://bugzilla.open-bio.org/
49 =head1 AUTHOR - Ewan Birney
51 Email birney@ebi.ac.uk
55 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
60 # Let the code begin...
63 package Bio
::Annotation
::SimpleValue
;
66 # Object preamble - inherits from Bio::Root::Root
68 #use Bio::Ontology::TermI;
70 use base
qw(Bio::Root::Root Bio::AnnotationI);
75 Usage : my $sv = Bio::Annotation::SimpleValue->new();
76 Function: Instantiate a new SimpleValue object
77 Returns : Bio::Annotation::SimpleValue object
78 Args : -value => $value to initialize the object data field [optional]
79 -tagname => $tag to initialize the tagname [optional]
80 -tag_term => ontology term representation of the tag [optional]
85 my ($class,@args) = @_;
87 my $self = $class->SUPER::new
(@args);
89 my ($value,$tag,$term) =
90 $self->_rearrange([qw(VALUE TAGNAME TAG_TERM)], @args);
93 defined $term && $self->tag_term($term);
94 defined $value && $self->value($value);
95 defined $tag && $self->tagname($tag);
101 =head1 AnnotationI implementing functions
108 Usage : my $text = $obj->as_text
109 Function: return the string "Value: $v" where $v is the value
119 return "Value: ".$self->value;
125 Usage : my $str = $ann->display_text();
126 Function: returns a string. Unlike as_text(), this method returns a string
127 formatted as would be expected for te specific implementation.
129 One can pass a callback as an argument which allows custom text
130 generation; the callback is passed the current instance and any text
134 Args : [optional] callback
139 my $DEFAULT_CB = sub { $_[0]->value};
142 my ($self, $cb) = @_;
144 $self->throw("") if ref $cb ne 'CODE';
153 Usage : my $hashtree = $value->hash_tree
154 Function: For supporting the AnnotationI interface just returns the value
155 as a hashref with the key 'value' pointing to the value
166 $h->{'value'} = $self->value;
173 Usage : $obj->tagname($newval)
174 Function: Get/set the tagname for this annotation value.
176 Setting this is optional. If set, it obviates the need to
177 provide a tag to AnnotationCollection when adding this
181 Returns : value of tagname (a scalar)
182 Args : new value (a scalar, optional)
190 # check for presence of an ontology term
191 if($self->{'_tag_term'}) {
192 # keep a copy in case the term is removed later
193 $self->{'tagname'} = $_[0] if @_;
194 # delegate to the ontology term object
195 return $self->tag_term->name(@_);
197 return $self->{'tagname'} = shift if @_;
198 return $self->{'tagname'};
202 =head1 Specific accessors for SimpleValue
209 Usage : $obj->value($newval)
210 Function: Get/Set the value for simplevalue
211 Returns : value of value
212 Args : newvalue (optional)
218 my ($self,$value) = @_;
220 if( defined $value) {
221 $self->{'value'} = $value;
223 return $self->{'value'};
229 Usage : $obj->tag_term($newval)
230 Function: Get/set the L<Bio::Ontology::TermI> object representing
233 This is so you can specifically relate the tag of this
234 annotation to an entry in an ontology. You may want to do
235 this to associate an identifier with the tag, or a
236 particular category, such that you can better match the tag
237 against a controlled vocabulary.
239 This accessor will return undef if it has never been set
240 before in order to allow this annotation to stay
241 light-weight if an ontology term representation of the tag
242 is not needed. Once it is set to a valid value, tagname()
243 will actually delegate to the name() of this term.
246 Returns : a L<Bio::Ontology::TermI> compliant object, or undef
247 Args : on set, new value (a L<Bio::Ontology::TermI> compliant
248 object or undef, optional)
256 return $self->{'_tag_term'} = shift if @_;
257 return $self->{'_tag_term'};