File: Tabix.pm

package info (click to toggle)
tabix 0.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 384 kB
  • ctags: 521
  • sloc: ansic: 3,759; java: 309; python: 126; perl: 91; makefile: 53; sh: 8
file content (76 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package Tabix;

use strict;
use warnings;
use Carp qw/croak/;

use TabixIterator;

require Exporter;

our @ISA = qw/Exporter/;
our @EXPORT = qw/tabix_open tabix_close tabix_read tabix_query tabix_getnames tabix_iter_free/;

our $VERSION = '0.2.0';

require XSLoader;
XSLoader::load('Tabix', $VERSION);

sub new {
  my $invocant = shift;
  my %args = @_;
  $args{-data} || croak("-data argument required");
  my $class = ref($invocant) || $invocant;
  my $self = {};
  bless($self, $class);
  $self->open($args{-data}, $args{-index});
  return $self;
}

sub open {
  my ($self, $fn, $fnidx) = @_;
  $self->close;
  $self->{_fn} = $fn;
  $self->{_fnidx} = $fnidx;
  $self->{_} = $fnidx? tabix_open($fn, $fnidx) : tabix_open($fn);
}

sub close {
  my $self = shift;
  if ($self->{_}) {
	tabix_close($self->{_});
	delete($self->{_}); delete($self->{_fn}); delete($self->{_fnidx});
  }
}

sub DESTROY {
  my $self = shift;
  $self->close;
}

sub query {
  my $self = shift;
  my $iter;
  if (@_) {
	$iter = tabix_query($self->{_}, @_);
  } else {
	$iter = tabix_query($self->{_});
  }
  my $i = TabixIterator->new;
  $i->set($iter);
  return $i;
}

sub read {
  my $self = shift;
  my $iter = shift;
  return tabix_read($self->{_}, $iter->get);
}

sub getnames {
  my $self = shift;
  return tabix_getnames($self->{_});
}

1;
__END__