[bug 2262]
[bioperl-live.git] / t / DBFasta.t
blob80826d463a584ae4fd8b084c6896158e3a1f66cf
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
5 BEGIN {     
6     use lib 't/lib';
7         use BioperlTest;
8         
9         test_begin(-tests => 14,
10                            -requires_module => 'Bio::DB::Fasta');
11         
12         use_ok('Bio::Root::IO');
13         use_ok('File::Copy');
16 my $DEBUG = test_debug();
18 # this obfuscation is to deal with lockfiles by GDBM_File which can
19 # only be created on local filesystems apparently so will cause test
20 # to block and then fail when the testdir is on an NFS mounted system
22 my $io = Bio::Root::IO->new(-verbose => $DEBUG);
23 my $tempdir = $io->tempdir('CLEANUP' => 1);
24 my $test_dbdir = $io->catfile($tempdir, 'dbfa');
25 mkdir($test_dbdir); # make the directory
26 my $indir = test_input_file('dbfa'); 
27 opendir(INDIR,$indir) || die("cannot open dir $indir");
28 # effectively do a cp -r but only copy the files that are in there, no subdirs
29 for my $file ( map { $io->catfile($indir,$_) } readdir(INDIR) ) {
30         next unless (-f $file );
31         copy($file, $test_dbdir);
33 closedir(INDIR);
35 # now use this temporary dir for the db file
36 my $db = Bio::DB::Fasta->new($test_dbdir, -reindex => 1);
37 ok($db);
38 cmp_ok($db->length('CEESC13F'), '>', 0);
39 is(length $db->seq('CEESC13F:1,10'), 10);
40 is(length $db->seq('AW057119',1,10), 10);
41 my $primary_seq = $db->get_Seq_by_id('AW057119');
42 ok($primary_seq);
43 cmp_ok(length($primary_seq->seq), '>', 0);
44 ok(!defined $db->get_Seq_by_id('foobarbaz'));
45 undef $db;
46 undef $primary_seq;
48 my (%h,$dna1,$dna2);
49 ok(tie(%h,'Bio::DB::Fasta',$test_dbdir));
50 ok($h{'AW057146'});
51 ok($dna1 = $h{'AW057146:1,10'});
52 ok($dna2 = $h{'AW057146:10,1'});
54 my $revcom = reverse $dna1;
55 $revcom =~ tr/gatcGATC/ctagCTAG/;
56 is($dna2, $revcom);