Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initialize Bio::SeqIO object throught the seqio() method instead of n…

…ext_read() and not no initialize Bio::SeqIO before we have reached the ##FASTA section of the GFF stream
  • Loading branch information...
commit bab00a62dabaec47d39cc4640c738d6b40a60bf0 1 parent 3d9043a
@fangly fangly authored
Showing with 21 additions and 14 deletions.
  1. +15 −12 Bio/FeatureIO/gff.pm
  2. +6 −2 t/SeqFeature/FeatureIO.t
View
27 Bio/FeatureIO/gff.pm
@@ -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
@@ -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();
}
@@ -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 :
View
8 t/SeqFeature/FeatureIO.t
@@ -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');
}
@@ -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++;
@@ -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++;
}
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.