2 # BioPerl module for Bio::Annotation::SimpleValue
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by bioperl <bioperl-l@bioperl.org>
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::Annotation::SimpleValue - A simple scalar
20 use Bio::Annotation::SimpleValue;
21 use Bio::Annotation::Collection;
23 my $col = Bio::Annotation::Collection->new();
24 my $sv = Bio::Annotation::SimpleValue->new(-value => 'someval');
25 $col->add_Annotation('tagname', $sv);
29 Scalar value annotation object
35 User feedback is an integral part of the evolution of this and other
36 Bioperl modules. Send your comments and suggestions preferably to one
37 of the Bioperl mailing lists. Your participation is much appreciated.
39 bioperl-l@bioperl.org - General discussion
40 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
44 Please direct usage questions or support issues to the mailing list:
46 I<bioperl-l@bioperl.org>
48 rather than to the module maintainer directly. Many experienced and
49 reponsive experts will be able look at the problem and quickly
50 address it. Please include a thorough description of the problem
51 with code and data examples if at all possible.
55 Report bugs to the Bioperl bug tracking system to help us keep track
56 the bugs and their resolution. Bug reports can be submitted via
59 https://github.com/bioperl/bioperl-live/issues
61 =head1 AUTHOR - Ewan Birney
63 Email birney@ebi.ac.uk
67 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
72 # Let the code begin...
75 package Bio
::Annotation
::SimpleValue
;
79 # Object preamble - inherits from Bio::Root::Root
81 #use Bio::Ontology::TermI;
83 use base
qw(Bio::Root::Root Bio::AnnotationI);
88 Usage : my $sv = Bio::Annotation::SimpleValue->new();
89 Function: Instantiate a new SimpleValue object
90 Returns : Bio::Annotation::SimpleValue object
91 Args : -value => $value to initialize the object data field [optional]
92 -tagname => $tag to initialize the tagname [optional]
93 -tag_term => ontology term representation of the tag [optional]
98 my ($class,@args) = @_;
100 my $self = $class->SUPER::new
(@args);
102 my ($value,$tag,$term) =
103 $self->_rearrange([qw(VALUE TAGNAME TAG_TERM)], @args);
106 defined $term && $self->tag_term($term);
107 defined $value && $self->value($value);
108 defined $tag && $self->tagname($tag);
114 =head1 AnnotationI implementing functions
121 Usage : my $text = $obj->as_text
122 Function: return the string "Value: $v" where $v is the value
132 return "Value: ".$self->value;
138 Usage : my $str = $ann->display_text();
139 Function: returns a string. Unlike as_text(), this method returns a string
140 formatted as would be expected for te specific implementation.
142 One can pass a callback as an argument which allows custom text
143 generation; the callback is passed the current instance and any text
147 Args : [optional] callback
152 my $DEFAULT_CB = sub { $_[0]->value};
155 my ($self, $cb) = @_;
157 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
166 Usage : my $hashtree = $value->hash_tree
167 Function: For supporting the AnnotationI interface just returns the value
168 as a hashref with the key 'value' pointing to the value
179 $h->{'value'} = $self->value;
186 Usage : $obj->tagname($newval)
187 Function: Get/set the tagname for this annotation value.
189 Setting this is optional. If set, it obviates the need to
190 provide a tag to AnnotationCollection when adding this
194 Returns : value of tagname (a scalar)
195 Args : new value (a scalar, optional)
203 # check for presence of an ontology term
204 if($self->{'_tag_term'}) {
205 # keep a copy in case the term is removed later
206 $self->{'tagname'} = $_[0] if @_;
207 # delegate to the ontology term object
208 return $self->tag_term->name(@_);
210 return $self->{'tagname'} = shift if @_;
211 return $self->{'tagname'};
215 =head1 Specific accessors for SimpleValue
222 Usage : $obj->value($newval)
223 Function: Get/Set the value for simplevalue
224 Returns : value of value
225 Args : newvalue (optional)
231 my ($self,$value) = @_;
233 if( defined $value) {
234 $self->{'value'} = $value;
236 return $self->{'value'};
242 Usage : $obj->tag_term($newval)
243 Function: Get/set the L<Bio::Ontology::TermI> object representing
246 This is so you can specifically relate the tag of this
247 annotation to an entry in an ontology. You may want to do
248 this to associate an identifier with the tag, or a
249 particular category, such that you can better match the tag
250 against a controlled vocabulary.
252 This accessor will return undef if it has never been set
253 before in order to allow this annotation to stay
254 light-weight if an ontology term representation of the tag
255 is not needed. Once it is set to a valid value, tagname()
256 will actually delegate to the name() of this term.
259 Returns : a L<Bio::Ontology::TermI> compliant object, or undef
260 Args : on set, new value (a L<Bio::Ontology::TermI> compliant
261 object or undef, optional)
269 return $self->{'_tag_term'} = shift if @_;
270 return $self->{'_tag_term'};