| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Bio::DB::GFF::Adaptor::berkeleydb::iterator - iterator for Bio::DB::GFF::Adaptor::berkeleydb | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | For internal use only | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | This is an internal module that is used by the Bio::DB::GFF in-memory | ||
| 12 | adaptor to return an iterator across a sequence feature query. The | ||
| 13 | object has a single method, next_feature(), that returns the next | ||
| 14 | feature from the query. The method next_seq() is an alias for | ||
| 15 | next_feature(). | ||
| 16 | |||
| 17 | =head1 BUGS | ||
| 18 | |||
| 19 | None known yet. | ||
| 20 | |||
| 21 | =head1 SEE ALSO | ||
| 22 | |||
| 23 | L<Bio::DB::GFF>, | ||
| 24 | |||
| 25 | =head1 AUTHOR | ||
| 26 | |||
| 27 | Lincoln Stein E<lt>lstein@cshl.orgE<gt>. | ||
| 28 | |||
| 29 | Copyright (c) 2001 Cold Spring Harbor Laboratory. | ||
| 30 | |||
| 31 | This library is free software; you can redistribute it and/or modify | ||
| 32 | it under the same terms as Perl itself. | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | package Bio::DB::GFF::Adaptor::berkeleydb::iterator; | ||
| 37 | $Bio::DB::GFF::Adaptor::berkeleydb::iterator::VERSION = '1.7.4'; | ||
| 38 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 0 | ▶ | use DB_File qw(R_FIRST R_NEXT); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 40 | |||
| 41 | # this module needs to be cleaned up and documented | ||
| 42 | use Bio::Root::Version; | ||
| 43 | *next_seq = \&next_feature; | ||
| 44 | |||
| 45 | sub new { | ||
| 46 | my $class = shift; | ||
| 47 | my ($data,$callback,$tmpfile) = @_; | ||
| 48 | return bless {data => $data, | ||
| 49 | callback => $callback, | ||
| 50 | tmpfile => $tmpfile, | ||
| 51 | cache => []},$class; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub next_feature { | ||
| 55 | my $self = shift; | ||
| 56 | return shift @{$self->{cache}} if @{$self->{cache}}; | ||
| 57 | |||
| 58 | my $data = $self->{data} or return; | ||
| 59 | my $callback = $self->{callback}; | ||
| 60 | |||
| 61 | my $features; | ||
| 62 | my $db = tied(%$data); | ||
| 63 | my ($key,$value); | ||
| 64 | |||
| 65 | for (my $status = $db->seq($key,$value,$self->{iter}++ ? R_NEXT : R_FIRST); | ||
| 66 | $status == 0; | ||
| 67 | $status = $db->seq($key,$value,R_NEXT)) { | ||
| 68 | my @feature = split ($;,$value); | ||
| 69 | $features = $callback->(@feature); | ||
| 70 | last if $features; | ||
| 71 | } | ||
| 72 | |||
| 73 | unless ($features) { | ||
| 74 | $features = $callback->(); | ||
| 75 | undef $self->{data}; | ||
| 76 | undef $self->{cache}; | ||
| 77 | unlink $self->{tmpfile}; | ||
| 78 | } | ||
| 79 | |||
| 80 | $self->{cache} = $features or return; | ||
| 81 | shift @{$self->{cache}}; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||