2 # BioPerl module for Bio::AnnotationI
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
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();
35 Interface all annotations must support. There are two things that each
36 annotation has to support.
38 $annotation->as_text()
40 Annotations have to support an "as_text" method. This should be a
41 single text string, without newlines representing the annotation,
42 mainly for human readability. It is not aimed at being able to
43 store/represent the annotation.
45 The second method allows annotations to at least attempt to represent
46 themselves as pure data for storage/display/whatever. The method
47 hash_tree should return an anonymous hash with "XML-like" formatting:
49 $hash = $annotation->hash_tree();
51 The formatting is as follows.
53 (1) For each key in the hash, if the value is a reference'd array -
55 (2) For each element of the array if the value is a object -
56 Assume the object has the method "hash_tree";
57 (3) else if the value is a reference to a hash
58 Recurse again from point (1)
60 Assume the value is a scalar, and handle it directly as text
61 (5) else (if not an array) apply rules 2,3 and 4 to value
63 The XML path in tags is represented by the keys taken in the
64 hashes. When arrays are encountered they are all present in the path
67 This is a pretty "natural" representation of an object tree in an XML
68 style, without forcing everything to inherit off some super-generic
69 interface for representing things in the hash.
75 User feedback is an integral part of the evolution of this
76 and other Bioperl modules. Send your comments and suggestions preferably
77 to one of the Bioperl mailing lists.
78 Your participation is much appreciated.
84 Please direct usage questions or support issues to the mailing list:
86 I<bioperl-l@bioperl.org>
88 rather than to the module maintainer directly. Many experienced and
89 reponsive experts will be able look at the problem and quickly
90 address it. Please include a thorough description of the problem
91 with code and data examples if at all possible.
95 Report bugs to the Bioperl bug tracking system to help us keep track
96 the bugs and their resolution. Bug reports can be submitted via the
99 https://github.com/bioperl/bioperl-live/issues
101 =head1 AUTHOR - Ewan Birney
103 Email birney@ebi.ac.uk
107 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
112 # Let the code begin...
115 package Bio
::AnnotationI
;
119 # Object preamble - inherits from Bio::Root::Root
121 use base
qw(Bio::Root::RootI);
127 Function: single text string, without newlines representing the
128 annotation, mainly for human readability. It is not aimed
129 at being able to store/represent the annotation.
138 shift->throw_not_implemented();
144 Usage : my $str = $ann->display_text();
145 Function: returns a string. Unlike as_text(), this method returns a string
146 formatted as would be expected for the specific implementation.
148 Implementations should allow passing a callback as an argument which
149 allows custom text generation; the callback will be passed the
150 current implementation.
152 Note that this is meant to be used as a simple representation
153 of the annotation data but probably shouldn't be used in cases
154 where more complex comparisons are needed or where data is
158 Args : [optional] callback
163 shift->throw_not_implemented();
170 Function: should return an anonymous hash with "XML-like" formatting
172 Returns : a hash reference
178 shift->throw_not_implemented();
184 Usage : $obj->tagname($newval)
185 Function: Get/set the tagname for this annotation value.
187 Setting this is optional. If set, it obviates the need to
188 provide a tag to Bio::AnnotationCollectionI when adding
189 this object. When obtaining an AnnotationI object from the
190 collection, the collection will set the value to the tag
191 under which it was stored unless the object has a tag
195 Returns : value of tagname (a scalar)
196 Args : new value (a scalar, optional)
202 shift->throw_not_implemented();