| Filename | /Users/ap13/perl5/lib/perl5/Bio/AnnotationI.pm |
| Statements | Executed 5 statements in 142µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 13µs | 26µs | Bio::AnnotationI::BEGIN@116 |
| 1 | 1 | 1 | 9µs | 77µs | Bio::AnnotationI::BEGIN@120 |
| 0 | 0 | 0 | 0s | 0s | Bio::AnnotationI::as_text |
| 0 | 0 | 0 | 0s | 0s | Bio::AnnotationI::display_text |
| 0 | 0 | 0 | 0s | 0s | Bio::AnnotationI::hash_tree |
| 0 | 0 | 0 | 0s | 0s | Bio::AnnotationI::tagname |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # | ||||
| 2 | # BioPerl module for Bio::AnnotationI | ||||
| 3 | # | ||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||
| 5 | # | ||||
| 6 | # Cared for by Ewan Birney <birney@ebi.ac.uk> | ||||
| 7 | # | ||||
| 8 | # Copyright Ewan Birney | ||||
| 9 | # | ||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||
| 11 | |||||
| 12 | # POD documentation - main docs before the code | ||||
| 13 | |||||
| 14 | =head1 NAME | ||||
| 15 | |||||
| 16 | Bio::AnnotationI - Annotation interface | ||||
| 17 | |||||
| 18 | =head1 SYNOPSIS | ||||
| 19 | |||||
| 20 | # generally you get AnnotationI's from AnnotationCollectionI's | ||||
| 21 | |||||
| 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(); | ||||
| 30 | } | ||||
| 31 | } | ||||
| 32 | |||||
| 33 | =head1 DESCRIPTION | ||||
| 34 | |||||
| 35 | Interface all annotations must support. There are two things that each | ||||
| 36 | annotation has to support. | ||||
| 37 | |||||
| 38 | $annotation->as_text() | ||||
| 39 | |||||
| 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. | ||||
| 44 | |||||
| 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: | ||||
| 48 | |||||
| 49 | $hash = $annotation->hash_tree(); | ||||
| 50 | |||||
| 51 | The formatting is as follows. | ||||
| 52 | |||||
| 53 | (1) For each key in the hash, if the value is a reference'd array - | ||||
| 54 | |||||
| 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) | ||||
| 59 | (4) else | ||||
| 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 | ||||
| 62 | |||||
| 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 | ||||
| 65 | level of this tag | ||||
| 66 | |||||
| 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. | ||||
| 70 | |||||
| 71 | =head1 FEEDBACK | ||||
| 72 | |||||
| 73 | =head2 Mailing Lists | ||||
| 74 | |||||
| 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. | ||||
| 79 | |||||
| 80 | bioperl-l@bioperl.org | ||||
| 81 | |||||
| 82 | =head2 Support | ||||
| 83 | |||||
| 84 | Please direct usage questions or support issues to the mailing list: | ||||
| 85 | |||||
| 86 | I<bioperl-l@bioperl.org> | ||||
| 87 | |||||
| 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. | ||||
| 92 | |||||
| 93 | =head2 Reporting Bugs | ||||
| 94 | |||||
| 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 | ||||
| 97 | web: | ||||
| 98 | |||||
| 99 | https://github.com/bioperl/bioperl-live/issues | ||||
| 100 | |||||
| 101 | =head1 AUTHOR - Ewan Birney | ||||
| 102 | |||||
| 103 | Email birney@ebi.ac.uk | ||||
| 104 | |||||
| 105 | =head1 APPENDIX | ||||
| 106 | |||||
| 107 | The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ | ||||
| 108 | |||||
| 109 | =cut | ||||
| 110 | |||||
| 111 | #' | ||||
| 112 | # Let the code begin... | ||||
| 113 | |||||
| 114 | |||||
| 115 | package Bio::AnnotationI; | ||||
| 116 | 2 | 27µs | 2 | 39µs | # spent 26µs (13+13) within Bio::AnnotationI::BEGIN@116 which was called:
# once (13µs+13µs) by base::import at line 116 # spent 26µs making 1 call to Bio::AnnotationI::BEGIN@116
# spent 13µs making 1 call to strict::import |
| 117 | |||||
| 118 | # Object preamble - inherits from Bio::Root::Root | ||||
| 119 | |||||
| 120 | 2 | 113µs | 2 | 77µs | # spent 77µs (9+67) within Bio::AnnotationI::BEGIN@120 which was called:
# once (9µs+67µs) by base::import at line 120 # spent 77µs making 1 call to Bio::AnnotationI::BEGIN@120
# spent 68µs making 1 call to base::import, recursion: max depth 1, sum of overlapping time 68µs |
| 121 | |||||
| 122 | =head2 as_text | ||||
| 123 | |||||
| 124 | Title : as_text | ||||
| 125 | Usage : | ||||
| 126 | Function: single text string, without newlines representing the | ||||
| 127 | annotation, mainly for human readability. It is not aimed | ||||
| 128 | at being able to store/represent the annotation. | ||||
| 129 | Example : | ||||
| 130 | Returns : a string | ||||
| 131 | Args : none | ||||
| 132 | |||||
| 133 | |||||
| 134 | =cut | ||||
| 135 | |||||
| 136 | sub as_text{ | ||||
| 137 | shift->throw_not_implemented(); | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | =head2 display_text | ||||
| 141 | |||||
| 142 | Title : display_text | ||||
| 143 | Usage : my $str = $ann->display_text(); | ||||
| 144 | Function: returns a string. Unlike as_text(), this method returns a string | ||||
| 145 | formatted as would be expected for the specific implementation. | ||||
| 146 | |||||
| 147 | Implementations should allow passing a callback as an argument which | ||||
| 148 | allows custom text generation; the callback will be passed the | ||||
| 149 | current implementation. | ||||
| 150 | |||||
| 151 | Note that this is meant to be used as a simple representation | ||||
| 152 | of the annotation data but probably shouldn't be used in cases | ||||
| 153 | where more complex comparisons are needed or where data is | ||||
| 154 | stored. | ||||
| 155 | Example : | ||||
| 156 | Returns : a string | ||||
| 157 | Args : [optional] callback | ||||
| 158 | |||||
| 159 | =cut | ||||
| 160 | |||||
| 161 | sub display_text { | ||||
| 162 | shift->throw_not_implemented(); | ||||
| 163 | } | ||||
| 164 | |||||
| 165 | =head2 hash_tree | ||||
| 166 | |||||
| 167 | Title : hash_tree | ||||
| 168 | Usage : | ||||
| 169 | Function: should return an anonymous hash with "XML-like" formatting | ||||
| 170 | Example : | ||||
| 171 | Returns : a hash reference | ||||
| 172 | Args : none | ||||
| 173 | |||||
| 174 | =cut | ||||
| 175 | |||||
| 176 | sub hash_tree{ | ||||
| 177 | shift->throw_not_implemented(); | ||||
| 178 | } | ||||
| 179 | |||||
| 180 | =head2 tagname | ||||
| 181 | |||||
| 182 | Title : tagname | ||||
| 183 | Usage : $obj->tagname($newval) | ||||
| 184 | Function: Get/set the tagname for this annotation value. | ||||
| 185 | |||||
| 186 | Setting this is optional. If set, it obviates the need to | ||||
| 187 | provide a tag to Bio::AnnotationCollectionI when adding | ||||
| 188 | this object. When obtaining an AnnotationI object from the | ||||
| 189 | collection, the collection will set the value to the tag | ||||
| 190 | under which it was stored unless the object has a tag | ||||
| 191 | stored already. | ||||
| 192 | |||||
| 193 | Example : | ||||
| 194 | Returns : value of tagname (a scalar) | ||||
| 195 | Args : new value (a scalar, optional) | ||||
| 196 | |||||
| 197 | |||||
| 198 | =cut | ||||
| 199 | |||||
| 200 | sub tagname{ | ||||
| 201 | shift->throw_not_implemented(); | ||||
| 202 | } | ||||
| 203 | |||||
| 204 | 1 | 2µs | 1; |