| 1 |
=head1 LICENSE |
| 2 |
|
| 3 |
Copyright [2015-2024] EMBL-European Bioinformatics Institute |
| 4 |
|
| 5 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
you may not use this file except in compliance with the License. |
| 7 |
You may obtain a copy of the License at |
| 8 |
|
| 9 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
Unless required by applicable law or agreed to in writing, software |
| 12 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
See the License for the specific language governing permissions and |
| 15 |
limitations under the License. |
| 16 |
|
| 17 |
=cut |
| 18 |
|
| 19 |
package Bio::DB::HTS::VCF::Iterator; |
| 20 |
|
| 21 |
use Bio::DB::HTS; #load the XS |
| 22 |
$Bio::DB::HTS::VCF::Iterator::VERSION = '3.02'; |
| 23 |
|
| 24 |
use strict; |
| 25 |
use warnings; |
| 26 |
use Scalar::Util qw/reftype/; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my $class = shift; |
| 30 |
my (%args) = @_; |
| 31 |
my $iter = $args{iter}; |
| 32 |
my $htsfile = $args{file}; # an open htsFile pointer |
| 33 |
my $header = $args{header}; |
| 34 |
my $index = $args{index}; # either tabix (VCF) or hts index (BCF), depending on the file type |
| 35 |
|
| 36 |
my $self = bless { |
| 37 |
_iter => $iter, |
| 38 |
_htsfile => $htsfile, |
| 39 |
_header => $header, |
| 40 |
_index => $index, |
| 41 |
}, ref $class || $class; |
| 42 |
|
| 43 |
return $self; |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
sub next { |
| 48 |
my $self = shift; |
| 49 |
|
| 50 |
# sometimes *_query doesn't return an iterator, just NULL |
| 51 |
# so we have to allow a null iterator |
| 52 |
return unless defined $self->{_iter} and defined $self->{_header}; |
| 53 |
|
| 54 |
return iter_next($self->{_iter}, $self->{_htsfile}, $self->{_header}, $self->{_index}); |
| 55 |
} |
| 56 |
|
| 57 |
sub close { |
| 58 |
my $self = shift; |
| 59 |
|
| 60 |
return unless defined $self->{_iter}; |
| 61 |
|
| 62 |
iter_free($self->{_iter}); |
| 63 |
delete $self->{_iter}; # delete once you've removed it. Prevents bad re-issuing of code |
| 64 |
} |
| 65 |
|
| 66 |
sub DESTROY { |
| 67 |
my $self = shift; |
| 68 |
return if reftype($self) ne 'HASH'; |
| 69 |
$self->close(); |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
1; |
| 74 |
|
| 75 |
__END__ |
| 76 |
|
| 77 |
=head1 NAME |
| 78 |
|
| 79 |
Bio::DB::HTS::VCF::Iterator - XS module wrapping around a hts_itr_t |
| 80 |
|
| 81 |
=head1 SYNOPSIS |
| 82 |
|
| 83 |
=head1 DESCRIPTION |
| 84 |
|
| 85 |
=head2 Methods |
| 86 |
|
| 87 |
=over 12 |
| 88 |
|
| 89 |
=item C<next> |
| 90 |
|
| 91 |
Returns a string with the line from the iterator |
| 92 |
|
| 93 |
=back |
| 94 |
|
| 95 |
=head1 AUTHOR |
| 96 |
|
| 97 |
Alessandro Vullo E<lt>[email protected]<gt> |
| 98 |
|
| 99 |
=cut |