151
150
@keys = $self->get_all_annotation_keys() unless @keys;
152
151
foreach my $key (@keys) {
153
if(exists($self->{'_annotation'}->{$key})) {
156
$_->tagname($key) if ! $_->tagname(); $_;
157
} @{$self->{'_annotation'}->{$key}});
152
if(exists($self->{'_annotation'}->{$key})) {
155
$_->tagname($key) if ! $_->tagname(); $_;
156
} @{$self->{'_annotation'}->{$key}});
163
=head2 get_nested_Annotations
165
Title : get_nested_Annotations
166
Usage : my @annotations = $collection->get_nested_Annotations(
169
Function: Retrieves all the Bio::AnnotationI objects for one or more
170
specific key(s). If -recursive is set to true, traverses the nested
171
annotation collections recursively and returns all annotations
174
If no key is given, returns all annotation objects.
176
The returned objects will have their tagname() attribute set to
177
the key under which they were attached, unless the tagname was
180
Returns : list of Bio::AnnotationI - empty if no objects stored for a key
181
Args : -keys => arrayref of keys to search for (optional)
182
-recursive => boolean, whether or not to recursively traverse the
183
nested annotations and return annotations with matching keys.
187
sub get_nested_Annotations {
188
my ($self, @args) = @_;
189
my ($keys, $recursive) = $self->_rearrange([qw(KEYS RECURSIVE)], @args);
193
# if not recursive behave exactly like get_Annotations()
195
my @keys = $keys? @$keys : $self->get_all_annotation_keys();
196
foreach my $key (@keys) {
197
if(exists($self->{'_annotation'}->{$key})) {
200
$_->tagname($key) if ! $_->tagname(); $_;
201
} @{$self->{'_annotation'}->{$key}});
205
# if recursive search for keys recursively
207
my @allkeys = $self->get_all_annotation_keys();
208
foreach my $key (@allkeys) {
210
foreach my $searchkey (@$keys) {
211
if ($key eq $searchkey) { $keymatch = 1;}
214
if(exists($self->{'_annotation'}->{$key})) {
217
$_->tagname($key) if ! $_->tagname(); $_;
218
} @{$self->{'_annotation'}->{$key}});
222
my @annotations = @{$self->{'_annotation'}->{$key}};
223
foreach (@annotations) {
224
if ($_->isa("Bio::AnnotationCollectionI")) {
226
$_->get_nested_Annotations('-keys' => $keys, '-recursive' => 1)
163
236
=head2 get_all_Annotations
165
238
Title : get_all_Annotations
260
334
if( !$object->isa("Bio::AnnotationI") ) {
261
$self->throw("object must be AnnotationI compliant, otherwise we wont add it!");
335
$self->throw("object must be AnnotationI compliant, otherwise we won't add it!");
264
338
# ok, now we are ready! If we don't have an archetype, set it
276
350
# this means isa stuff is executed correctly
278
352
if( !$self->_typemap()->is_valid($key,$object) ) {
279
$self->throw("Object $object was not valid with key $key. If you were adding new keys in, perhaps you want to make use of the archetype method to allow registration to a more basic type");
353
$self->throw("Object $object was not valid with key $key. ".
354
"If you were adding new keys in, perhaps you want to make use\n".
355
"of the archetype method to allow registration to a more basic type");
282
358
$self->_typemap->_add_type_map($key,$archetype);
469
Usage : my $str = $ann->display_text();
470
Function: returns a string. Unlike as_text(), this method returns a string
471
formatted as would be expected for te specific implementation.
473
One can pass a callback as an argument which allows custom text
474
generation; the callback is passed the current instance and any text
478
Args : [optional] callback
483
# this just calls the default display_text output for
485
my $DEFAULT_CB = sub {
488
foreach my $ann ($obj->get_Annotations()) {
489
$txt .= $ann->display_text()."\n";
495
my ($self, $cb) = @_;
497
$self->throw("") if ref $cb ne 'CODE';
392
505
Title : hash_tree