Skip to content
Browse files

Reverted to previous behaviour, i.e. override PrimarySeqI trunc()

Because it is more efficient to have a special object that does not keep the full sequence in memory
+ documented this behaviour
+ added tests for it
  • Loading branch information...
1 parent baccddd commit 5a954431e620ac9884e3c257044d3c665168d75f @fangly fangly committed Nov 6, 2012
Showing with 18 additions and 6 deletions.
  1. +9 −2 Bio/DB/Fasta.pm
  2. +9 −4 t/LocalDB/Fasta.t
View
11 Bio/DB/Fasta.pm
@@ -379,6 +379,13 @@ sub seq {
}
sub subseq {
+ my $self = shift;
+ return $self->trunc(@_)->seq();
+}
+
+sub trunc {
+ # Override Bio::PrimarySeqI trunc() method. This way, we create a
+ # Bio::PrimarySeq::Fasta 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}) {
@@ -388,7 +395,7 @@ sub subseq {
$start = $self->{start}-($start-1);
$stop = $self->{start}-($stop-1);
}
- return $self->{db}->seq($self->{id}, $start, $stop);
+ return $self->new( $self->{db}, $self->{id}, $start, $stop );
}
sub is_circular {
@@ -431,7 +438,7 @@ sub length {
sub description {
my $self = shift;
my $header = $self->{'db'}->header($self->{id});
- # remove the ID from the header
+ # Remove the ID from the header
return (split(/\s+/, $header, 2))[1];
}
*desc = \&description;
View
13 t/LocalDB/Fasta.t
@@ -61,12 +61,17 @@ my $test_files = [
is $primary_seq->accession_number, 'unknown';
is $primary_seq->is_circular, undef;
is $primary_seq->subseq(11, 20), 'ttctcggggt';
- is $primary_seq->trunc(11, 20)->length, 10;
- is $primary_seq->trunc(11, 20)->seq, 'ttctcggggt';
- is $primary_seq->trunc(11, 20)->revcom->seq, 'accccgagaa';
is $primary_seq->description, 'test description', 'bug 3126';
is $primary_seq->seq, 'tcatgttggcttctcggggtttttatggattaatacattttccaaacgattctttgcgccttctgtggtgccgccttctccgaaggaactgacgaaaaatgacgtggatttgctgacaaatccaggcgaggaatatttggacggattgatgaaatggcacggcgacgagcgacccgtgttcaaaagagaggacatttatcgttggtcggatagttttccagaatatcggctaagaatgatttgtctgaaagacacgacaagggtcattgcagtcggtcaatattgttactttgatgctctgaaagaaaggagagcagccattgttcttcttaggattgggatggacggatcctgaatatcgtaatcgggcagttatggagcttcaagcttcgatggcgctggaggagagggatcggtatccgactgccaacgcggcatcgcatccaaataagttcatgaaacgattttggcacatattcaacggcctcaaagagcacgaggacaaaggtcacaaggctgccgctgtttcatacaagagcttctacgacctcanagacatgatcattcctgaaaatctggatgtcagtggtattactgtaaatgatgcacgaaaggtgccacaaagagatataatcaactacgatcaaacatttcatccatatcatcgagaaatggttataatttctcacatgtatgacaatgatgggtttggaaaagtgcgtatgatgaggatggaaatgtacttggaattgtctagcgatgtctttanaccaacaagactgcacattagtcaattatgcagatagcc';
-
+ ok my $trunc = $primary_seq->trunc(11,20);
+ isa_ok $trunc, 'Bio::PrimarySeq::Fasta';
+ isa_ok $trunc, 'Bio::PrimarySeqI';
+ is $trunc->length, 10;
+ is $trunc->seq, 'ttctcggggt';
+ ok my $rev = $trunc->revcom;
+ isa_ok $trunc, 'Bio::PrimarySeq::Fasta';
+ isa_ok $trunc, 'Bio::PrimarySeqI';
+ is $rev->seq, 'accccgagaa';
}

0 comments on commit 5a95443

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