t/*: remove "use lib '.'" and t/lib/Error.pm
[bioperl-live.git] / t / LocalDB / Flat.t
blob0df39453569ff1c9f7f8fc10fe5afea3b7286fb5
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
9     test_begin(-tests => 27,
10                -requires_module => 'DB_File');
12     use_ok('Bio::DB::Flat');
15 my $verbose = test_debug();
17 # First of all we need to create an flat db
19 my $tmpdir = test_output_dir();
21 my $db = Bio::DB::Flat->new(-directory  => $tmpdir,
22                             -index      => 'bdb',
23                             -dbname     => 'mydb',
24                             -format     => 'fasta',
25                             -verbose    => $verbose,
26                             -write_flag => 1 );
27 ok($db);
28 my $dir = test_input_file('AAC12660.fa');
29 my $result = $db->build_index(glob($dir));
30 ok($result);
32 # Now let's get the sequence out again
33 my $seq = $db->get_Seq_by_id('AAC12660');
34 ok($seq);
35 is($seq->length,504);
36 undef $db;
38 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
39                          -index      => 'bdb',
40                          -format     => 'embl',
41                          -dbname     => 'myembl',
42                          -verbose    => $verbose,
43                          -write_flag => 1 );
45 $dir= test_input_file('cds_sample.embl');
47 $result = $db->build_index(glob($dir));
49 is ($db->get_all_primary_ids, 1);
50 #is ($db->get_all_accs, 1);
51 ok($result);
52 $seq = $db->get_Seq_by_id('EAL24309');
53 ok($seq);
54 is($seq->length,192);
56 # deal with wantarray conditions
57 $seq = $db->get_Seq_by_acc('CH236947.1');
58 ok($seq && ref($seq));
59 is($seq->length,192);
61 undef $db;
63 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
64                          -index      => 'binarysearch',
65                          -format     => 'fasta',
66                          -dbname     => 'mybinfa',
67                          -verbose    => $verbose,
68                          -write_flag => 1
69                          );
71 $dir = test_input_file('dbfa', '1.fa');
72 $result = $db->build_index($dir);
73 ok($result);
74 $seq = $db->get_Seq_by_id('AW057119');
75 ok($seq);
76 is($seq->length, 808);
77 $seq = $db->get_Seq_by_id('AW057118');
78 ok($seq);
79 is($seq->length, 299);
81 undef $db;
83 SKIP: {
84     test_skip(-tests => 4, -requires_module => 'Data::Stag');
85     $db = Bio::DB::Flat->new(-directory  => $tmpdir,
86                              -index      => 'binarysearch',
87                              -format     => 'swiss',
88                              -dbname     => 'mybinswiss',
89                              -verbose    => $verbose,
90                              -write_flag => 1
91                              );
92     $dir= test_input_file('swiss.dat');
93     $result = $db->build_index($dir);
95     ok($result);
96     $seq = $db->get_Seq_by_id('ACON_CAEEL');
97     ok($seq);
98     is($seq->length,788);
100     $seq = $db->get_Seq_by_id('ACON_CAEEL');
101     ok($seq && ref($seq));
103     undef $db;
105 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
106                          -index      => 'binarysearch',
107                          -format     => 'fasta',
108                          -dbname     => 'myfasta',
109                          -verbose    => $verbose,
110                          -write_flag => 1 );
112 $dir = test_input_file('tmp.fst');
113 $result = $db->build_index(glob($dir));
114 ok($result);
115 $seq = $db->get_Seq_by_id('TEST00004');
116 is($seq->length,98);
118 undef $db;
120 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
121                          -index      => 'bdb',
122                          -format     => 'fasta',
123                          -dbname     => 'mybfasta',
124                          -verbose    => $verbose,
125                          -write_flag => 1 );
127 $dir = test_input_file('tmp.fst');
128 $result = $db->build_index(glob($dir));
129 ok($result);
130 for my $id ( qw(TEST00001 TEST00002 TEST00003 TEST00004) ) {
131     $seq = $db->get_Seq_by_id($id);
132     is($seq->length,98);