Bio-BLAST
view release on metacpan or search on metacpan
BEGIN {
if( can_run('fastacmd') ) {
plan tests => 302;
}
else {
plan skip_all => 'fastacmd is not installed (in PATH), required to test Bio::BLAST::Database';
}
}
use Test::Warn;
my $DATADIR = catdir('t','data');
-d $DATADIR or die "missing data dir $DATADIR";
BEGIN {
use_ok( 'Bio::BLAST::Database' )
or BAIL_OUT('could not include the module being tested');
}
my $tempdir = tempdir( CLEANUP => 1);
### test die cases
throws_ok {
Bio::BLAST::Database->open( full_file_basename => catfile( $tempdir, 'testy', 'blowup' ),
type => 'protein',
write => 1,
);
} qr/create_dirs must be set/,
'creation in nonexistent dir without create flag dies';
my $intheway;
my @t = (['nin','nucleotide'], ['pin','protein']);
for my $t ( \@t, [reverse @t] ) {
$intheway = catfile( $tempdir, 'fooey.'.$t->[0][0] );
my $fs = Bio::BLAST::Database->open( full_file_basename => catfile( $tempdir, 'fooey' ),
write => 1,
type => $t->[1][1],
);
ok( $fs, 'write-open succeeds even if existing files are present for a different db type' );
ok( ! $fs->is_split, 'returns false for is_split');
unlink $intheway;
}
foreach my $type ('nucleotide','protein') {
my $test_seq_file = catfile( $DATADIR, "blastdb_test.$type.seq" );
#use Smart::Comments;
### test new creation...
my $test_ffbn = catfile( $tempdir, "testdb_$type" );
throws_ok {
Bio::BLAST::Database->open( full_file_basename => $test_ffbn,
write => 1,
);
} qr/type.+could not guess/,
'de novo creation dies without type';
my $fs = Bio::BLAST::Database->open( full_file_basename => $test_ffbn,
type => $type,
write => 1,
);
is( scalar $fs->list_files, 0, 'new db does not have any files' );
ok( !$fs->format_time, 'format_time returns nothing for no files');
ok( !$fs->files_are_complete, 'files_are_complete returns false for empty DB');
ok( !$fs->is_split, 'returns false for is_split');
is( $fs->type, $type, 'correct initial type');
### test formatting from file
foreach my $index (0,1) {
my $st = time;
unlink $fs->list_files;
ok(! $fs->check_format_permissions, 'check_format_permissions should be OK' );
my $test_title = "test title,dflgksjdf;\nholycow";
$fs->format_from_file( seqfile => $test_seq_file,
title => $test_title,
indexed_seqs => $index,
);
my $et = time;
is( scalar $fs->list_files, ($index ? 5 : 3), 'newly formatted db has the right number of files' )
or diag "actual files:\n",map " $_\n",$fs->list_files;
is( $fs->title, $test_title, 'got correct title' );
my $ftime = $fs->format_time;
# do times within 60 seconds because format_time only has
# resolution of nearest minute
cmp_ok( $ftime, '>=', $st-60, 'format time reasonable 1');
cmp_ok( $ftime, '<=', $et+60, 'format time reasonable 2');
my $mtime = $fs->file_modtime;
cmp_ok( $mtime, '>=', $st-1, 'modtime reasonable 1');
cmp_ok( $mtime, '<=', $et+1, 'modtime reasonable 2');
is( $fs->title, $test_title, 'got correct title' );
ok( $fs->files_are_complete, 'files read as complete' );
ok( ! $fs->is_split, 'returns false for is_split');
#try to fake a split db
my $c = 0;
my @fake_split = map { s/\./sprintf('.%02d.',++$c)/e; $_ } $fs->list_files;
open my $f, '>', $_ foreach @fake_split;
ok( $fs->is_split, 'faked out is_split' )
or diag "faked files:\n", map " $_\n", $fs->list_files;
unlink @fake_split;
}
( run in 0.572 second using v1.01-cache-2.11-cpan-39bf76dae61 )