Skip to content

Commit

Permalink
Fixed 'missing sequence' problem with nested SubSeq objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fangly committed Mar 14, 2012
1 parent 6ebef81 commit 93fc11b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
17 changes: 15 additions & 2 deletions Bio/SeqFeature/SubSeq.pm
Expand Up @@ -97,7 +97,8 @@ use base qw(Bio::SeqFeature::Generic);
Usage : my $subseq = Bio::SeqFeature::SubSeq( -start => 1, -end => 10, -strand => -1);
Function: Instantiate a new Bio::SeqFeature::SubSeq feature object
Args : -seq , the sequence object or sequence string of the feature (optional)
-template , attach the feature to the provided template (parent) sequence (optional). Note that you must specify the feature location to do this.
-template , attach the feature to the provided parent template sequence or feature (optional).
Note that you must specify the feature location to do this.
-start, -end, -location, -strand and all other L<Bio::SeqFeature::Generic> argument can be used.
Returns : A Bio::SeqFeature::SubSeq object
Expand All @@ -122,9 +123,21 @@ sub new {
}
if ($template) {
if ( not($self->start) || not($self->end) ) {
$self->throw('Could not attach SubSeq feature to template sequence because the SubSeq location was unknown.');
$self->throw('Could not attach feature to template $template because'.
' the feature location was not specified.');
}

# Need to attach to parent sequence and then add sequence feature
my $template_seq;
if ($template->isa('Bio::SeqFeature::Generic')) {
$template_seq = $template->entire_seq;
} elsif ($template->isa('Bio::SeqI')) {
$template_seq = $template;
} else {
$self->throw("Expected a Bio::SeqFeature::Generic or Bio::SeqI object".
" as template, but got '$template'.");
}
$self->attach_seq($template_seq);
$template->add_SeqFeature($self);

}
Expand Down
21 changes: 19 additions & 2 deletions t/SeqFeature/SubSeq.t
Expand Up @@ -4,13 +4,13 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 32);
test_begin(-tests => 37);

use_ok 'Bio::PrimarySeq';
use_ok 'Bio::SeqFeature::SubSeq';
}

my ($subseq, $subseq_seq, $template);
my ($subseq, $subseq_seq, $subsubseq, $subsubseq_seq, $template);


# Basic SubSeq object
Expand Down Expand Up @@ -89,4 +89,21 @@ ok $subseq_seq = $subseq->seq;
isa_ok $subseq_seq, 'Bio::PrimarySeq';
is $subseq_seq->seq, 'AAAAACCCCCTTTTTGGGGG';


# Sub SubSeq

ok $subsubseq = Bio::SeqFeature::SubSeq->new(
-start => 11,
-end => 15,
-strand => 1,
-template => $subseq,
);
is $subsubseq->length, 5;
ok $subsubseq_seq = $subsubseq->seq;
isa_ok $subsubseq_seq, 'Bio::PrimarySeq';
is $subsubseq_seq->seq, 'CCCCC';


# One-liner

is( Bio::SeqFeature::SubSeq->new(-start=>11,-end=>30,-strand=>1,-template=>$template)->seq->seq, 'CCCCCAAAAAGGGGGTTTTT' );
6 changes: 3 additions & 3 deletions t/Tools/AmpliconSearch.t
Expand Up @@ -2,7 +2,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin(-tests => 158);
test_begin(-tests => 160);

use_ok 'Bio::PrimarySeq';
use_ok 'Bio::SeqFeature::Primer';
Expand Down Expand Up @@ -46,8 +46,8 @@ is $amplicon->end, 56;
is $amplicon->strand, 1;
is $amplicon->seq->seq, 'AAACTTAAAGGAATTGACGGacgtacgtacgtGTACACACCGCCCGTacgtac';
ok $primer = $amplicon->fwd_primer;
###ok $primer_seq = $primer->seq;
###is $primer_seq->seq, 'AAACTTAAAGGAATTGACGG';
ok $primer_seq = $primer->seq;
is $primer_seq->seq, 'AAACTTAAAGGAATTGACGG';
is $primer->start, 4;
is $primer->end, 23;
is $primer->strand, 1;
Expand Down

0 comments on commit 93fc11b

Please sign in to comment.