Skip to content
Browse files

Also revert to old revcom() + test + doc

  • Loading branch information...
1 parent 5a95443 commit e766ed724f6ebf4272da2978b2d6e8611b78cfd5 @fangly fangly committed
Showing with 13 additions and 7 deletions.
  1. +10 −4 Bio/DB/Fasta.pm
  2. +3 −3 t/LocalDB/Fasta.t
View
14 Bio/DB/Fasta.pm
@@ -384,8 +384,8 @@ sub subseq {
}
sub trunc {
- # Override Bio::PrimarySeqI trunc() method. This way, we create a
- # Bio::PrimarySeq::Fasta that does not store the sequence in memory.
+ # Override Bio::PrimarySeqI trunc() method. This way, we create an object
+ # that does not store the sequence in memory.
my ($self, $start, $stop) = @_;
$self->throw("Stop cannot be smaller than start") if $stop < $start;
if ($self->{start} <= $self->{stop}) {
@@ -429,10 +429,16 @@ sub alphabet {
return $self->{db}->alphabet($self->{id});
}
+sub revcom {
+ # Override Bio::PrimarySeqI revcom() with optimized method.
+ my $self = shift;
+ return $self->new(@{$self}{'db', 'id', 'stop', 'start'});
+}
+
sub length {
- # For efficiency, get length from the database, not from the sequence string
+ # Get length from sequence location, not the sequence string (too expensive)
my $self = shift;
- return $self->{db}->length($self->{id});
+ return $self->{stop} - $self->{start} + 1;
}
sub description {
View
6 t/LocalDB/Fasta.t
@@ -2,7 +2,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;
- test_begin( -tests => 85,
+ test_begin( -tests => 91,
-requires_modules => [qw(Bio::DB::Fasta Bio::SeqIO)]);
}
use strict;
@@ -69,8 +69,8 @@ my $test_files = [
is $trunc->length, 10;
is $trunc->seq, 'ttctcggggt';
ok my $rev = $trunc->revcom;
- isa_ok $trunc, 'Bio::PrimarySeq::Fasta';
- isa_ok $trunc, 'Bio::PrimarySeqI';
+ isa_ok $rev, 'Bio::PrimarySeq::Fasta';
+ isa_ok $rev, 'Bio::PrimarySeqI';
is $rev->seq, 'accccgagaa';
}

0 comments on commit e766ed7

Please sign in to comment.
Something went wrong with that request. Please try again.