[bug 2686]
[bioperl-live.git] / Bio / AnnotationI.pm
blob1e436fb7d72ffbe027d51c43b1c0bd950535b862
1 # $Id$
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
14 =head1 NAME
16 Bio::AnnotationI - Annotation interface
18 =head1 SYNOPSIS
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();
34 =head1 DESCRIPTION
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
48 hash_tree
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)
61 (4) else
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
68 level of this tag
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.
74 =head1 FEEDBACK
76 =head2 Mailing Lists
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.
83 bioperl-l@bioperl.org
85 =head2 Reporting Bugs
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
89 web:
91 http://bugzilla.open-bio.org/
93 =head1 AUTHOR - Ewan Birney
95 Email birney@ebi.ac.uk
97 =head1 APPENDIX
99 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
101 =cut
104 # Let the code begin...
107 package Bio::AnnotationI;
108 use strict;
110 # Object preamble - inherits from Bio::Root::Root
114 use base qw(Bio::Root::RootI);
117 =head2 as_text
119 Title : as_text
120 Usage :
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.
124 Example :
125 Returns : a string
126 Args : none
129 =cut
131 sub as_text{
132 shift->throw_not_implemented();
135 =head2 display_text
137 Title : display_text
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
149 stored.
150 Example :
151 Returns : a string
152 Args : [optional] callback
154 =cut
156 sub display_text {
157 shift->throw_not_implemented();
160 =head2 hash_tree
162 Title : hash_tree
163 Usage :
164 Function: should return an anonymous hash with "XML-like" formatting
165 Example :
166 Returns : a hash reference
167 Args : none
170 =cut
172 sub hash_tree{
173 shift->throw_not_implemented();
176 =head2 tagname
178 Title : tagname
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
187 stored already.
189 Example :
190 Returns : value of tagname (a scalar)
191 Args : new value (a scalar, optional)
194 =cut
196 sub tagname{
197 shift->throw_not_implemented();