1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 17,
10 -requires_modules => [qw(Bio::DB::Fasta Bio::SeqIO)]);
16 my $DEBUG = test_debug();
20 my $test_dbdir = setup_temp_dir('dbfa');
22 # now use this temporary dir for the db file
23 my $db = Bio::DB::Fasta->new($test_dbdir, -reindex => 1);
25 cmp_ok($db->length('CEESC13F'), '>', 0);
26 is(length $db->seq('CEESC13F:1,10'), 10);
27 is(length $db->seq('AW057119',1,10), 10);
28 my $primary_seq = $db->get_Seq_by_id('AW057119');
30 cmp_ok(length($primary_seq->seq), '>', 0);
31 is($primary_seq->trunc(1,10)->length, 10);
32 is($primary_seq->description, 'test description', 'bug 3126');
33 ok(!defined $db->get_Seq_by_id('foobarbaz'));
38 ok(tie(%h,'Bio::DB::Fasta',$test_dbdir));
40 ok($dna1 = $h{'AW057146:1,10'});
41 ok($dna2 = $h{'AW057146:10,1'});
43 my $revcom = reverse $dna1;
44 $revcom =~ tr/gatcGATC/ctagCTAG/;
47 # test out writing the Bio::PrimarySeq::Fasta objects with SeqIO
49 $db = Bio::DB::Fasta->new($test_dbdir, -reindex => 1);
50 my $out = Bio::SeqIO->new(-format => 'genbank',
51 -file => '>'.test_output_file());
52 $primary_seq = Bio::Seq->new(-primary_seq => $db->get_Seq_by_acc('AW057119'));
54 #warn(ref($primary_seq),"\n");
55 $out->write_seq($primary_seq)
59 $out = Bio::SeqIO->new(-format => 'embl', -file => '>'.test_output_file());
62 $out->write_seq($primary_seq)
68 $test_dbdir = setup_temp_dir('bad_dbfa');
70 throws_ok {$db = Bio::DB::Fasta->new($test_dbdir, -reindex => 1)} qr/FASTA header doesn't match/;
76 # this obfuscation is to deal with lockfiles by GDBM_File which can
77 # only be created on local filesystems apparently so will cause test
78 # to block and then fail when the testdir is on an NFS mounted system
82 my $io = Bio::Root::IO->new();
83 my $tempdir = test_output_dir();
84 my $test_dbdir = $io->catfile($tempdir, $data_dir);
85 mkdir($test_dbdir); # make the directory
86 my $indir = test_input_file($data_dir);
87 opendir(my $INDIR,$indir) || die("cannot open dir $indir");
88 # effectively do a cp -r but only copy the files that are in there, no subdirs
89 for my $file ( map { $io->catfile($indir,$_) } readdir($INDIR) ) {
90 next unless (-f $file );
91 copy($file, $test_dbdir);