Skip to content

Commit

Permalink
Initialize Bio::SeqIO object throught the seqio() method instead of n…
Browse files Browse the repository at this point in the history
…ext_read() and not no initialize Bio::SeqIO before we have reached the ##FASTA section of the GFF stream
  • Loading branch information
fangly committed Oct 10, 2011
1 parent 3d9043a commit bab00a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
27 changes: 15 additions & 12 deletions Bio/FeatureIO/gff.pm
Expand Up @@ -241,7 +241,7 @@ sub next_feature_group {
Usage : $featureio->next_seq( );
Function: access the FASTA section (if any) at the end of the GFF stream. Note
that this method will return undef until all the features in the GFF
that this method will return undef before all the features in the GFF
stream have been handled.
Returns : a Bio::SeqI object or undef
Args : none
Expand All @@ -250,12 +250,7 @@ sub next_feature_group {

sub next_seq() {
my $self = shift;
return unless $self->fasta_mode();

#first time next_seq has been called. initialize Bio::SeqIO instance
if(!$self->seqio){
$self->seqio( Bio::SeqIO->new(-format => 'fasta', -fh => $self->_fh()) );
}
return undef unless $self->fasta_mode();
return $self->seqio->next_seq();
}

Expand Down Expand Up @@ -326,20 +321,28 @@ sub fasta_mode {
=head2 seqio()
Usage : $obj->seqio($newval)
Function: get/set a Bio::SeqIO instance for handling the GFF3 ##FASTA section.
Note that this method will return undef until all the features in the
GFF stream have been handled.
Returns : value of seqio (a scalar) or undef
Function: get/set a Bio::SeqIO instance to handle the GFF3 ##FASTA section.
Returns : a Bio::SeqIO object or undef
Args : on set, new value (a scalar or undef, optional)
=cut

sub seqio {
my($self,$val) = @_;
$self->{'seqio'} = $val if defined($val);
if (defined $val) {
$self->{'seqio'} = $val;
} else {
# Cannot get seqio before we've reached the ##FASTA section
return undef unless $self->fasta_mode();
if (not defined $self->{'seqio'}) {
# Initialize Bio::SeqIO instance
$self->{'seqio'} = Bio::SeqIO->new(-format => 'fasta', -fh => $self->_fh());
}
}
return $self->{'seqio'};
}


=head2 sequence_region()
Usage :
Expand Down
8 changes: 6 additions & 2 deletions t/SeqFeature/FeatureIO.t
Expand Up @@ -7,8 +7,8 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 47,
-requires_module => 'Graph');
test_begin(-tests => 50,
-requires_module => 'Graph');

use_ok('Bio::FeatureIO');
}
Expand All @@ -35,6 +35,7 @@ while($f = $io->next_feature()){
}
is($fcount, 0);


#then try to read sequences again. should get seqs now
while($s = $io->next_seq()){
$scount++;
Expand Down Expand Up @@ -84,6 +85,7 @@ $scount = 0;
ok( $io = Bio::FeatureIO->new( -file => test_input_file('hybrid1.gff3') ) );

#try to read sequences first. should be undef
is $io->seqio, undef;
while($s = $io->next_seq()){
$scount++;
}
Expand All @@ -96,8 +98,10 @@ while($f = $io->next_feature()){
is($fcount , 6);

#then try to read sequences again.
isa_ok $io->seqio, 'Bio::SeqIO';
while($s = $io->next_seq()){
$scount++;
isa_ok $s, 'Bio::Seq';
TODO: {
local $TODO = 'How did this ever work?!?';
if ($scount == 1) {
Expand Down

0 comments on commit bab00a6

Please sign in to comment.