[BUG] bug 2598
[bioperl-live.git] / t / flat.t
blob11f9bb5b637a8f81dd0606b0116997e73df343d1
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
5 use File::Temp qw(tempdir);
7 BEGIN { 
8     use lib 't/lib';
9         use BioperlTest;
10         
11         test_begin(-tests => 17,
12                            -requires_module => 'DB_File');
13         
14         use_ok('Bio::DB::Flat');
17 my $verbose = test_debug();
19 #First of all we need to create an flat db
21 my $tmpdir = tempdir( CLEANUP => 1 );
23 my $db = Bio::DB::Flat->new(-directory  => $tmpdir,
24                             -index      => 'bdb',
25                             -dbname     => 'mydb',
26                             -format     => 'fasta',
27                             -verbose    => $verbose,
28                             -write_flag => 1
29                             );
30 ok($db);
31 my $dir = test_input_file('AAC12660.fa');
32 my $result = $db->build_index(glob($dir));
33 ok($result);
35 #Now let's get the sequence out again
36 my $seq = $db->get_Seq_by_id('AAC12660');
37 ok($seq);
38 is($seq->length,504);
39 undef $db;
41 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
42                          -index      => 'bdb',
43                          -format     => 'embl',
44                          -dbname     => 'myembl',
45                          -verbose    => $verbose,
46                          -write_flag => 1
47                          );
49 $dir= test_input_file('factor7.embl');
51 $result = $db->build_index(glob($dir));
52 ok($result);
53 $seq = $db->get_Seq_by_id('HSCFVII');
54 ok($seq);
55 is($seq->length,12850);
57 # deal with wantarray conditions
58 $seq = $db->get_Seq_by_acc('J02933');
59 ok($seq && ref($seq));
60 is($seq->length,12850);
63 undef $db;
65 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
66                          -index      => 'binarysearch',
67                          -format     => 'fasta',
68                          -dbname     => 'mybinfa',
69                          -verbose    => $verbose,
70                          -write_flag => 1
71                          );
73 $dir= test_input_file('dbfa', '1.fa');
74 $result = $db->build_index($dir);
75 ok($result);
76 $seq = $db->get_Seq_by_id('AW057119');
77 ok($seq);
78 is($seq->length,808);
79 undef $db;
81 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
82                          -index      => 'binarysearch',
83                          -format     => 'swiss',
84                          -dbname     => 'mybinswiss',
85                          -verbose    => $verbose,
86                          -write_flag => 1
87                          );
88 $dir= test_input_file('swiss.dat');
89 $result = $db->build_index($dir);
91 ok($result);
92 $seq = $db->get_Seq_by_id('ACON_CAEEL');
93 ok($seq);
94 is($seq->length,788);
96 $seq = $db->get_Seq_by_id('ACON_CAEEL');
97 ok($seq && ref($seq));
99 undef $db;