Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added select_noncont_by_name method to Bio::SimpleAlign.
Added tests. All tests pass, although test count was off beforehand and was corrected.

Signed-off-by: DaveMessina <online@davemessina.com>
  • Loading branch information
DaveMessina committed Oct 11, 2011
1 parent 22a1b41 commit 92c6c56
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Bio/SimpleAlign.pm
Expand Up @@ -1064,6 +1064,29 @@ sub select_noncont {
return $aln;
}

=head2 select_noncont_by_name
Title : select_noncont_by_name
Usage : my $aln2 = $aln->select_noncont_by_name('A123', 'B456');
Function : Creates a new alignment from a subset of sequences which are
selected by name (sequence ID).
Returns : a Bio::SimpleAlign object
Args : array of names (i.e., identifiers) for the sequences.
=cut

sub select_noncont_by_name {
my ($self, @names) = @_;

my $aln = $self->new;
foreach my $name (@names) {
$aln->add_seq($self->get_seq_by_id($name));
}
$aln->id($self->id);

return $aln;
}

=head2 slice
Title : slice
Expand Down
15 changes: 12 additions & 3 deletions t/Align/SimpleAlign.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {
use lib '.';
use Bio::Root::Test;

test_begin( -tests => 201 );
test_begin( -tests => 198 );

use_ok('Bio::SimpleAlign');
use_ok('Bio::AlignIO');
Expand Down Expand Up @@ -38,7 +38,7 @@ my $aln2 = $aln->select( 1, 3 );
isa_ok( $aln2, 'Bio::Align::AlignI' );
is( $aln2->num_sequences, 3, 'num_sequences' );

# test select non continuous-sorted by default
# test select non contiguous-sorted by default
$aln2 = $aln->select_noncont( 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 );
is( $aln2->num_sequences, 10, 'num_sequences' );
is(
Expand All @@ -52,7 +52,7 @@ is(
'select_noncont'
);

# test select non continuous-nosort option
# test select non contiguous-nosort option
$aln2 = $aln->select_noncont( 'nosort', 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 );
is( $aln2->num_sequences, 10, 'num_sequences' );
is(
Expand All @@ -66,6 +66,15 @@ is(
'select_noncont'
);

# test select non contiguous by name
my $aln3 = $aln->select_noncont_by_name('1433_LYCES','BMH1_YEAST','143T_HUMAN');
is( $aln3->num_sequences, 3, 'select_noncont_by_name' );
my @seqs3 = $aln3->each_seq();
is $seqs3[0]->id, '1433_LYCES', 'select_noncont_by_name';
is $seqs3[1]->id, 'BMH1_YEAST', 'select_noncont_by_name';
is $seqs3[2]->id, '143T_HUMAN', 'select_noncont_by_name';


@seqs = $aln->each_seq();
is scalar @seqs, 16, 'each_seq';
is $seqs[0]->get_nse, '1433_LYCES/9-246', 'get_nse';
Expand Down

0 comments on commit 92c6c56

Please sign in to comment.