Allow falling back to any strigified Bio::AnnotationI for 'gene_name'
[bioperl-live.git] / t / LocalDB / Flat.t
blob41c551898dc04fb60827822e0ecab5a11feac188
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN { 
7         use lib '.';
8         use Bio::Root::Test;
9         
10         test_begin(-tests => 24,
11                                   -requires_module => 'DB_File');
12         
13         use_ok('Bio::DB::Flat');
16 my $verbose = test_debug();
18 # First of all we need to create an flat db
20 my $tmpdir = test_output_dir();
22 my $db = Bio::DB::Flat->new(-directory  => $tmpdir,
23                             -index      => 'bdb',
24                                                                          -dbname     => 'mydb',
25                                                                          -format     => 'fasta',
26                                                                          -verbose    => $verbose,
27                                                                          -write_flag => 1 );
28 ok($db);
29 my $dir = test_input_file('AAC12660.fa');
30 my $result = $db->build_index(glob($dir));
31 ok($result);
33 # Now let's get the sequence out again
34 my $seq = $db->get_Seq_by_id('AAC12660');
35 ok($seq);
36 is($seq->length,504);
37 undef $db;
39 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
40                          -index      => 'bdb',
41                          -format     => 'embl',
42                                                                  -dbname     => 'myembl',
43                          -verbose    => $verbose,
44                          -write_flag => 1 );
46 $dir= test_input_file('factor7.embl');
48 $result = $db->build_index(glob($dir));
49 ok($result);
50 $seq = $db->get_Seq_by_id('HSCFVII');
51 ok($seq);
52 is($seq->length,12850);
54 # deal with wantarray conditions
55 $seq = $db->get_Seq_by_acc('J02933');
56 ok($seq && ref($seq));
57 is($seq->length,12850);
60 undef $db;
62 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
63                          -index      => 'binarysearch',
64                          -format     => 'fasta',
65                          -dbname     => 'mybinfa',
66                          -verbose    => $verbose,
67                          -write_flag => 1
68                          );
70 $dir= test_input_file('dbfa', '1.fa');
71 $result = $db->build_index($dir);
72 ok($result);
73 $seq = $db->get_Seq_by_id('AW057119');
74 ok($seq);
75 is($seq->length,808);
76 undef $db;
78 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
79                          -index      => 'binarysearch',
80                          -format     => 'swiss',
81                          -dbname     => 'mybinswiss',
82                          -verbose    => $verbose,
83                          -write_flag => 1
84                          );
85 $dir= test_input_file('swiss.dat');
86 $result = $db->build_index($dir);
88 ok($result);
89 $seq = $db->get_Seq_by_id('ACON_CAEEL');
90 ok($seq);
91 is($seq->length,788);
93 $seq = $db->get_Seq_by_id('ACON_CAEEL');
94 ok($seq && ref($seq));
96 undef $db;
98 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
99                          -index      => 'binarysearch',
100                          -format     => 'fasta',
101                                                                  -dbname     => 'myfasta',
102                          -verbose    => $verbose,
103                          -write_flag => 1 );
105 $dir = test_input_file('tmp.fst');
106 $result = $db->build_index(glob($dir));
107 ok($result);
108 $seq = $db->get_Seq_by_id('TEST00004');
109 is($seq->length,98);
111 undef $db;
113 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
114                          -index      => 'bdb',
115                          -format     => 'fasta',
116                                                                  -dbname     => 'mybfasta',
117                          -verbose    => $verbose,
118                          -write_flag => 1 );
120 $dir = test_input_file('tmp.fst');
121 $result = $db->build_index(glob($dir));
122 ok($result);
123 for my $id ( qw(TEST00001 TEST00002 TEST00003 TEST00004) ) {
124         $seq = $db->get_Seq_by_id($id);
125         is($seq->length,98);