Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Better support for 0-length sequences

  • Loading branch information...
commit 92673e2531b7fb927a2a7554e4e1c42e4876d978 1 parent 9d8f5f9
@fangly fangly authored
Showing with 8 additions and 3 deletions.
  1. +2 −1  Bio/DB/Fasta.pm
  2. +1 −1  Bio/DB/IndexedBase.pm
  3. +5 −1 t/LocalDB/Fasta.t
View
3  Bio/DB/Fasta.pm
@@ -288,6 +288,7 @@ sub subseq {
read($fh, $data, $filestop-$filestart+1);
$data =~ s/\n//g;
$data =~ s/\r//g;
+
if ($strand == -1) {
# Reverse-complement the sequence
$data = Bio::PrimarySeqI::_revcom_from_string($self, $data, $self->alphabet($id));
@@ -359,8 +360,8 @@ sub new {
@args);
$self->{db} = $db;
$self->{id} = $id;
- $self->{start} = $start || 1;
$self->{stop} = $stop || $db->length($id);
+ $self->{start} = $start || ($self->{stop} > 0 ? 1 : 0); # handle 0-length seqs
return $self;
}
View
2  Bio/DB/IndexedBase.pm
@@ -695,8 +695,8 @@ sub _parse_compound_id {
}
# Start, stop and strand defaults
- $start ||= 1;
$stop ||= $self->length($id) || 0; # 0 if sequence not found in database
+ $start ||= ($stop > 0) ? 1 : 0;
$strand ||= 1;
# Convert numbers such as 1_000_000 to 1000000
View
6 t/LocalDB/Fasta.t
@@ -2,7 +2,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;
- test_begin( -tests => 69,
+ test_begin( -tests => 70,
-requires_modules => [qw(Bio::DB::Fasta Bio::SeqIO)]);
}
use strict;
@@ -115,6 +115,9 @@ my $test_files = [
is $db->alphabet('123'), '';
is $db->seq('gi|352962148|ref|NM_001251825.1|', 20, 29, 1 ), 'GUCAGCGUCC';
is $db->seq('gi|352962148|ref|NM_001251825.1|', 20, 29, -1), 'GGACGCUGAC';
+
+ # Test empty sequence
+ is $db->seq('123'), '';
}
@@ -242,6 +245,7 @@ my $test_files = [
unlink $outfile;
}
+
exit;
Please sign in to comment.
Something went wrong with that request. Please try again.