4 # BioPerl module for Bio::AnnotationI
6 # Cared for by Ewan Birney <birney@ebi.ac.uk>
8 # Copyright Ewan Birney
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::AnnotationI - Annotation interface
20 # generally you get AnnotationI's from AnnotationCollectionI's
22 foreach $key ( $ac->get_all_annotation_keys() ) {
23 @values = $ac->get_Annotations($key);
24 foreach $value ( @values ) {
25 # value is an Bio::AnnotationI, and defines a "as_text" method
26 print "Annotation ",$key," stringified value ",$value->as_text,"\n";
27 # you can also use a generic hash_tree method for getting
28 # stuff out say into XML format
29 $hash_tree = $value->hash_tree();
36 Interface all annotations must support. There are two things that each
37 annotation has to support.
39 $annotation->as_text()
41 Annotations have to support an "as_text" method. This should be a
42 single text string, without newlines representing the annotation,
43 mainly for human readability. It is not aimed at being able to
44 store/represent the annotation.
46 The second method allows annotations to at least attempt to represent
47 themselves as pure data for storage/display/whatever. The method
50 $hash = $annotation->hash_tree();
52 should return an anonymous hash with "XML-like" formatting. The
53 formatting is as follows.
55 (1) For each key in the hash, if the value is a reference'd array -
57 (2) For each element of the array if the value is a object -
58 Assume the object has the method "hash_tree";
59 (3) else if the value is a referene to a hash
60 Recurse again from point (1)
62 Assumme the value is a scalar, and handle it directly as text
64 (5) else (if not an array) apply rules 2,3 and 4 to value
66 The XML path in tags is represented by the keys taken in the
67 hashes. When arrays are encountered they are all present in the path
70 This is a pretty "natural" representation of an object tree in an XML
71 style, without forcing everything to inheriet off some super-generic
72 interface for representing things in the hash.
78 User feedback is an integral part of the evolution of this
79 and other Bioperl modules. Send your comments and suggestions preferably
80 to one of the Bioperl mailing lists.
81 Your participation is much appreciated.
87 Report bugs to the Bioperl bug tracking system to help us keep track
88 the bugs and their resolution. Bug reports can be submitted via the
91 http://bugzilla.open-bio.org/
93 =head1 AUTHOR - Ewan Birney
95 Email birney@ebi.ac.uk
99 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
104 # Let the code begin...
107 package Bio
::AnnotationI
;
110 # Object preamble - inherits from Bio::Root::Root
114 use base
qw(Bio::Root::RootI);
121 Function: single text string, without newlines representing the
122 annotation, mainly for human readability. It is not aimed
123 at being able to store/represent the annotation.
132 shift->throw_not_implemented();
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 the specific implementation.
142 Implementations should allow passing a callback as an argument which
143 allows custom text generation; the callback will be passed the
144 current implementation.
146 Note that this is meant to be used as a simple representation
147 of the annotation data but probably shouldn't be used in cases
148 where more complex comparisons are needed or where data is
152 Args : [optional] callback
157 shift->throw_not_implemented();
164 Function: should return an anonymous hash with "XML-like" formatting
166 Returns : a hash reference
173 shift->throw_not_implemented();
179 Usage : $obj->tagname($newval)
180 Function: Get/set the tagname for this annotation value.
182 Setting this is optional. If set, it obviates the need to
183 provide a tag to Bio::AnnotationCollectionI when adding
184 this object. When obtaining an AnnotationI object from the
185 collection, the collection will set the value to the tag
186 under which it was stored unless the object has a tag
190 Returns : value of tagname (a scalar)
191 Args : new value (a scalar, optional)
197 shift->throw_not_implemented();