Bio::DB::MeSH move to its own distribution.
[bioperl-live.git] / t / LocalDB / Flat.t
blob7d8a67382d90810fa5f33b6dd643af2110312adb
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib '.';
8     use Bio::Root::Test;
10     test_begin(-tests => 27,
11                -requires_module => 'DB_File');
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('cds_sample.embl');
48 $result = $db->build_index(glob($dir));
50 is ($db->get_all_primary_ids, 1);
51 #is ($db->get_all_accs, 1);
52 ok($result);
53 $seq = $db->get_Seq_by_id('EAL24309');
54 ok($seq);
55 is($seq->length,192);
57 # deal with wantarray conditions
58 $seq = $db->get_Seq_by_acc('CH236947.1');
59 ok($seq && ref($seq));
60 is($seq->length,192);
62 undef $db;
64 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
65                          -index      => 'binarysearch',
66                          -format     => 'fasta',
67                          -dbname     => 'mybinfa',
68                          -verbose    => $verbose,
69                          -write_flag => 1
70                          );
72 $dir = test_input_file('dbfa', '1.fa');
73 $result = $db->build_index($dir);
74 ok($result);
75 $seq = $db->get_Seq_by_id('AW057119');
76 ok($seq);
77 is($seq->length, 808);
78 $seq = $db->get_Seq_by_id('AW057118');
79 ok($seq);
80 is($seq->length, 299);
82 undef $db;
84 SKIP: {
85     test_skip(-tests => 4, -requires_module => 'Data::Stag');
86     $db = Bio::DB::Flat->new(-directory  => $tmpdir,
87                              -index      => 'binarysearch',
88                              -format     => 'swiss',
89                              -dbname     => 'mybinswiss',
90                              -verbose    => $verbose,
91                              -write_flag => 1
92                              );
93     $dir= test_input_file('swiss.dat');
94     $result = $db->build_index($dir);
96     ok($result);
97     $seq = $db->get_Seq_by_id('ACON_CAEEL');
98     ok($seq);
99     is($seq->length,788);
101     $seq = $db->get_Seq_by_id('ACON_CAEEL');
102     ok($seq && ref($seq));
104     undef $db;
106 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
107                          -index      => 'binarysearch',
108                          -format     => 'fasta',
109                          -dbname     => 'myfasta',
110                          -verbose    => $verbose,
111                          -write_flag => 1 );
113 $dir = test_input_file('tmp.fst');
114 $result = $db->build_index(glob($dir));
115 ok($result);
116 $seq = $db->get_Seq_by_id('TEST00004');
117 is($seq->length,98);
119 undef $db;
121 $db = Bio::DB::Flat->new(-directory  => $tmpdir,
122                          -index      => 'bdb',
123                          -format     => 'fasta',
124                          -dbname     => 'mybfasta',
125                          -verbose    => $verbose,
126                          -write_flag => 1 );
128 $dir = test_input_file('tmp.fst');
129 $result = $db->build_index(glob($dir));
130 ok($result);
131 for my $id ( qw(TEST00001 TEST00002 TEST00003 TEST00004) ) {
132     $seq = $db->get_Seq_by_id($id);
133     is($seq->length,98);