1
1
# This is -*-Perl-*- code
2
2
## Bioperl Test Harness Script for Modules
4
# $Id: DB.t,v 1.29 2002/01/19 22:26:17 jason Exp $
4
# $Id: DB.t,v 1.42 2003/11/13 12:57:06 heikki Exp $
6
6
# Before `make install' is performed this script should be runnable with
7
7
# `make test'. After `make install' it should work as `perl test.t'
10
use vars qw($NUMTESTS);
10
use lib '..','.','./blib/lib';
11
use vars qw($NUMTESTS $DEBUG);
12
$DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
26
28
plan tests => $NUMTESTS;
27
eval { require IO::String };
30
eval { require IO::String;
31
require LWP::UserAgent;
32
require HTTP::Request::Common;
29
print STDERR "IO::String not installed. This means the Bio::DB::* modules are not usable. Skipping tests.\n";
35
print STDERR "IO::String or LWP::UserAgent or HTTP::Request not installed. This means the Bio::DB::* modules are not usable. Skipping tests.\n";
30
36
for( 1..$NUMTESTS ) {
31
skip("IO::String not installed",1);
37
skip("IO::String, LWP::UserAgent,or HTTP::Request not installed",1);
44
foreach ( $Test::ntest..$NUMTESTS) {
45
skip('Unable to run all of the DB tests',1);
37
50
if( $error == 1 ) {
41
55
require Bio::DB::GenBank;
42
56
require Bio::DB::GenPept;
43
57
require Bio::DB::SwissProt;
52
67
## total number of tests that will be run.
70
my ($gb,$seq,$seqio,$query);
60
ok defined ( $gb = new Bio::DB::GenBank('-verbose'=>$verbose) );
61
ok( defined ($seq = $gb->get_Seq_by_id('MUSIGHBA1')));
73
ok defined ( $gb = new Bio::DB::GenBank('-verbose'=>$verbose,'-delay'=>0) );
74
$seq = $gb->get_Seq_by_id('MUSIGHBA1');
62
76
ok( $seq->length, 408);
63
ok( defined ($seq = $gb->get_Seq_by_acc('AF303112')));
64
ok($seq->length, 1611);
65
ok( defined ($seq = $gb->get_Seq_by_version('AF303112.1')));
66
ok($seq->length, 1611);
67
ok( defined ($seq = $gb->get_Seq_by_gi('405830')));
77
ok( defined ($seq = $gb->get_Seq_by_acc('AF303112')));
78
ok($seq->length, 1611);
79
ok( defined ($seq = $gb->get_Seq_by_version('AF303112.1')));
80
ok($seq->length, 1611);
81
ok( defined ($seq = $gb->get_Seq_by_gi('405830')));
68
82
ok($seq->length, 1743);
71
warn "Warning: Couldn't connect to Genbank with Bio::DB::GenBank.pm!\nError: $@\nDo you have network access? Skipping all other tests";
86
warn "Warning: Couldn't connect to Genbank with Bio::DB::GenBank.pm!\nError: $@\nDo you have network access? Skipping all other tests";
72
88
foreach ( $Test::ntest..$NUMTESTS ) { skip('no network access',1); }
76
91
$seq = $seqio = undef;
79
ok( defined($seqio = $gb->get_Stream_by_batch([ qw(J00522 AF303112
94
ok( defined($seqio = $gb->get_Stream_by_id([ qw(J00522 AF303112
81
96
ok($seqio->next_seq->length, 408);
82
97
ok($seqio->next_seq->length, 1611);
87
warn "Batch access test failed.\nError: $@\n";
102
if( $DEBUG ) { warn "Batch access test failed.\nError: $@\n"; }
88
103
foreach ( $Test::ntest..$NUMTESTS ) { skip('no network access',1); }
91
106
$seq = $seqio = undef;
94
ok defined($gb = new Bio::DB::GenPept('-verbose'=>$verbose));
109
ok defined($gb = new Bio::DB::GenPept('-verbose'=>$verbose,'-delay'=>0));
95
110
ok( defined($seq = $gb->get_Seq_by_id('195055')));
96
111
ok( $seq->length, 136);
97
112
$seq = $gb->get_Seq_by_acc('AAC06201');
99
114
ok($seq->length, 353);
100
$seqio = $gb->get_Stream_by_batch([ qw(AAC06201 195055)]);
115
$seqio = $gb->get_Stream_by_id([ qw(AAC06201 195055)]);
101
116
ok( defined $seqio);
102
117
ok( $seqio->next_seq->length(), 353);
103
118
ok( $seqio->next_seq->length(), 136);
107
warn "Warning: Couldn't connect to Genbank with Bio::DB::GenPept.pm!\n$@";
123
warn "Warning: Couldn't connect to Genbank with Bio::DB::GenPept.pm!\n$@";
108
125
foreach( $Test::ntest..$NUMTESTS ) {
109
126
skip('could not connect with GenPept',1);
113
130
$seq = $seqio = undef;
116
ok defined($gb = new Bio::DB::SwissProt('-verbose'=>$verbose));
133
ok defined($gb = new Bio::DB::SwissProt('-verbose'=>$verbose,-retrievaltype=>'pipeline','-delay'=>0));
117
134
ok(defined($seq = $gb->get_Seq_by_id('YNB3_YEAST')));
118
135
ok( $seq->length, 125);
119
136
ok($seq->division, 'YEAST');
120
138
ok(defined($seq = $gb->get_Seq_by_acc('P43780')));
121
139
ok( $seq->length, 103);
122
141
ok( defined( $seq = $gb->get_Seq_by_acc('O39869')));
123
142
ok( $seq->length, 56);
124
144
ok($seq->primary_id, 'O39869');
125
145
ok($seq->division, 'UNK');
127
147
# test for bug #958
128
148
$seq = $gb->get_Seq_by_id('P18584');
129
149
ok( defined $seq );
130
150
ok( $seq->length, 497);
131
ok( $seq->primary_id, 'DEGP');
151
skip($seq->primary_id =~ /^Bio::Seq/, $seq->primary_id, 'DEGP');
132
152
ok( $seq->display_id, 'DEGP_CHLTR');
133
153
ok( $seq->division, 'CHLTR');
135
155
ok( defined($gb = new Bio::DB::SwissProt('-verbose'=>$verbose,
136
'-retrievaltype' => 'tempfile')));
156
'-retrievaltype' => 'tempfile',
137
159
ok(defined($seqio = $gb->get_Stream_by_id(['KPY1_ECOLI', 'KPY1_HUMAN'])));
138
160
undef $gb; # testing to see if we can remove gb
139
161
ok( defined($seq = $seqio->next_seq()));
156
180
ok defined ( $gb = new Bio::DB::GenBank('-verbose' =>$verbose,
157
181
'-format' => 'fasta',
158
'-retrievaltype' => 'tempfile') );
182
'-retrievaltype' => 'tempfile',
159
184
ok( defined ($seq = $gb->get_Seq_by_id('MUSIGHBA1')));
160
185
ok($seq->length, 408);
161
186
$seq = $gb->get_Seq_by_acc('AF303112');
162
187
ok( defined $seq);
163
188
ok( $seq->length, 1611);
164
189
# batch mode requires genbank format
165
$gb->request_format("genbank");
166
ok(defined($seqio = $gb->get_Stream_by_batch([ qw(J00522 AF303112
190
$gb->request_format("gb");
191
ok(defined($seqio = $gb->get_Stream_by_id([ qw(J00522 AF303112
168
193
ok( $seqio->next_seq->length, 408);
169
194
undef $gb; # test the case where the db is gone,
172
197
ok($seqio->next_seq->length, 1611);
173
198
ok($seqio->next_seq->length, 1156);
178
warn "Warning: Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm!\n $@\n";
179
foreach ( $Test::ntest..$NUMTESTS ) {
180
skip('could not connect to Genbank',1);
183
$seq = $seqio = undef;
203
warn "Warning: Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm!\n $@\n";
205
foreach ( $Test::ntest..$NUMTESTS ) {
206
skip('could not connect to Genbank',1);
209
$seq = $seqio = undef;
212
# test pipeline creation
214
ok defined ( $gb = new Bio::DB::GenBank('-verbose' =>$verbose,
215
'-retrievaltype' => 'pipeline',
218
ok( defined ($seq = $gb->get_Seq_by_id('MUSIGHBA1')));
219
ok($seq->length, 408);
220
$seq = $gb->get_Seq_by_acc('AF303112');
222
ok( $seq->length, 1611);
223
ok(defined($seqio = $gb->get_Stream_by_id([ qw(J00522 AF303112
225
ok( $seqio->next_seq->length, 408);
226
undef $gb; # test the case where the db is gone,
227
# but the pipeline should remain until seqio goes away
229
ok($seqio->next_seq->length, 1611);
230
ok($seqio->next_seq->length, 1156);
235
warn "Warning: Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm!\n $@\n";
237
foreach ( $Test::ntest..$NUMTESTS ) {
238
skip('could not connect to Genbank',1);
241
$seq = $seqio = undef;
244
# test query facility
246
ok defined ( $query = Bio::DB::Query::GenBank->new('-verbose' => $verbose,
247
'-db' => 'nucleotide',
248
'-query' => 'Onchocerca volvulus[Organism]',
249
'-mindate' => '1/1/2002',
250
'-maxdate' => '1/30/2002'));
251
ok $query->count > 0;
252
my @ids = $query->ids;
254
ok @ids == $query->count;
255
ok defined ($gb = Bio::DB::GenBank->new('-verbose' =>$verbose,
258
ok defined ($seqio = $gb->get_Stream_by_query($query));
259
ok($seqio->next_seq->length,3766);
260
ok($seqio->next_seq->length,3857);
261
ok($seqio->next_seq->length,508);
266
warn "Warning: Couldn't connect to complete GenBank query tests!\n $@\n";
268
foreach ( $Test::ntest..$NUMTESTS ) {
269
skip('could not connect to Genbank',1);
272
$seq = $seqio = undef;
274
# test query facility
276
ok defined ( $query = Bio::DB::Query::GenBank->new('-verbose' => $verbose,
277
'-db' => 'nucleotide',
281
ok $query->count > 0;
282
my @ids = $query->ids;
284
ok @ids == $query->count;
285
ok defined ($gb = Bio::DB::GenBank->new('-verbose' =>$verbose,
288
ok defined ($seqio = $gb->get_Stream_by_query($query));
289
ok($seqio->next_seq->length, 408);
290
ok($seqio->next_seq->length, 1611);
291
ok($seqio->next_seq->length, 1156);
292
$seqio->close(); # the key to preventing errors during make test, no idea why
297
warn "Warning: Couldn't connect to complete GenBank query tests!\n $@\n";
299
foreach ( $Test::ntest..$NUMTESTS ) {
300
skip('could not connect to Genbank',1);
303
$seq = $seqio = undef;