Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bed passes, but needs real tests
  • Loading branch information
Chris Fields committed Aug 25, 2010
1 parent 98d2333 commit 7122446
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 65 deletions.
63 changes: 49 additions & 14 deletions lib/Bio/FeatureIO.pm
Expand Up @@ -265,8 +265,9 @@ package Bio::FeatureIO;

use strict;
use warnings;
use Config::Tiny;

use Scalar::Util qw(blessed);
use Bio::FeatureIO::Handler::GenericFeatureHandler;
use Config::Any;
use Symbol;

use base qw(Bio::Root::IO);
Expand Down Expand Up @@ -322,6 +323,33 @@ sub new {
}
}

# _initialize is chained for all FeatureIO classes

sub _initialize {
my ( $self, @args) = @_;

# flush is initialized by the Root::IO init

# initialize the IO part
$self->_initialize_io(@args);

my ($handler, $handler_args, $format, $conf, $seq) =
$self->_rearrange([qw(HANDLER HANDLER_ARGS FORMAT CONF SEQ)] , @args);
$format ||= 'GFF3';
$handler_args ||= {};
(ref($handler_args) eq 'HASH') ||
$self->throw("-handler_args must be a hash reference");
$handler ||= Bio::FeatureIO::Handler::GenericFeatureHandler->new(
-verbose => $self->verbose,
-fh => $self->_fh,
-format => $format,
%$handler_args);
$seq && $self->seq( $seq);

$self->_init_stream();
$self->handler($handler);
}

=head2 newFh
Title : newFh
Expand Down Expand Up @@ -364,18 +392,6 @@ sub fh {
return $s;
}

# _initialize is chained for all FeatureIO classes

sub _initialize {
my ( $self, %arg ) = @_;

# flush is initialized by the Root::IO init

# initialize the IO part
$self->seq( $arg{-seq} );
$self->_initialize_io(%arg);
}

=head2 next_feature
Title : next_feature
Expand Down Expand Up @@ -439,6 +455,17 @@ sub seq {
return $self->{'seq'};
}

sub handler {
my ($self, $handler) = @_;
if ($handler) {
$self->throw("Handler must be a Bio::HandlerBaseI") unless
blessed($handler) && $handler->isa('Bio::HandlerBaseI');
$self->{handler} = $handler;
}
return $self->{handler} if $self->{handler};
$self->throw("Handler not set");
}

=head2 _load_format_module
Title : _load_format_module
Expand Down Expand Up @@ -491,6 +518,14 @@ sub _guess_format {
return 'gff'; #the default
}

sub _init_stream {
my $self = shift;
my $fh = $self->_fh;
my $start = tell $fh;
@{$self}{qw(stream_start stream_type)} =
($start >= 0) ? ($start, 'seekable') : (0, 'string')
}

sub DESTROY {
my $self = shift;
$self->close();
Expand Down
48 changes: 0 additions & 48 deletions lib/Bio/FeatureIO/gff.pm
Expand Up @@ -5,35 +5,6 @@ use warnings;
use 5.010;
use base qw(Bio::FeatureIO);
use Bio::FeatureIO::Handler::GenericFeatureHandler;
use Scalar::Util qw(blessed);
use Config::Any;

my %CONFIG;

sub _initialize {
my($self, @args) = @_;

$self->SUPER::_initialize(@args);

my ($handler, $handler_args, $format, $conf) =
$self->_rearrange([qw(HANDLER HANDLER_ARGS FORMAT CONF)] , @args);
$format ||= 'GFF3';
$handler_args ||= {};
(ref($handler_args) eq 'HASH') ||
$self->throw("-handler_args must be a hash reference");

$handler ||= Bio::FeatureIO::Handler::GenericFeatureHandler->new(
-verbose => $self->verbose,
-fh => $self->_fh,
-format => $format,
%$handler_args);
if (!ref($handler) || !$handler->isa('Bio::HandlerBaseI')) {
$self->throw('Passed object must be a Bio::HandlerBaseI');
}

$self->_init_stream();
$self->handler($handler);
}

# raw feature stream; returned features are as-is, may be modified post-return
sub next_feature {
Expand Down Expand Up @@ -130,25 +101,6 @@ sub directive {
\%data;
}

sub handler {
my ($self, $handler) = @_;
if ($handler) {
$self->throw("Handler must be a Bio::HandlerBaseI") unless
blessed($handler) && $handler->isa('Bio::HandlerBaseI');
$self->{handler} = $handler;
}
return $self->{handler} if $self->{handler};
$self->throw("Handler not set");
}

sub _init_stream {
my $self = shift;
my $fh = $self->_fh;
my $start = tell $fh;
@{$self}{qw(stream_start stream_type)} =
($start >= 0) ? ($start, 'seekable') : (0, 'string')
}

sub next_feature_group {
my $self = shift;
return if $self->fasta_mode;
Expand Down
6 changes: 3 additions & 3 deletions t/bed.t
Expand Up @@ -19,8 +19,8 @@ ok($io = Bio::FeatureIO->new(-file => test_input_file('hg19_sample.bed')));

ok($f = $io->next_feature);

## Check correct conversion of [0, feature-end+1) bed-coordinates into [1, feature-end]
## bioperl coordinates. (here: bed [0, 10))
# Check correct conversion of [0, feature-end+1) bed-coordinates into [1, feature-end]
# bioperl coordinates. (here: bed [0, 10))
#is($f->start, 1);
#is($f->end, 10);
#
Expand All @@ -30,7 +30,7 @@ ok($f = $io->next_feature);
#is($tags[0], "test-coordinates-1");
#
#is($f->seq_id, "chr1");
#

done_testing();

exit;

0 comments on commit 7122446

Please sign in to comment.