~ubuntu-branches/ubuntu/intrepid/bioperl/intrepid

« back to all changes in this revision

Viewing changes to t/DB.t

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# This is -*-Perl-*- code
2
2
## Bioperl Test Harness Script for Modules
3
3
##
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 $
5
5
 
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'
8
8
 
9
9
use strict;
10
 
use vars qw($NUMTESTS);
 
10
use lib '..','.','./blib/lib';
 
11
use vars qw($NUMTESTS $DEBUG);
 
12
$DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
11
13
 
12
14
my $error;
13
15
 
22
24
    }
23
25
    use Test;
24
26
 
25
 
    $NUMTESTS =51;
 
27
    $NUMTESTS = 78;
26
28
    plan tests => $NUMTESTS;
27
 
    eval { require IO::String };
 
29
    
 
30
    eval { require IO::String; 
 
31
           require LWP::UserAgent;
 
32
           require HTTP::Request::Common;
 
33
       };
28
34
    if( $@ ) {
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);
32
38
        }
33
39
       $error = 1; 
34
40
    }
35
41
}
36
42
 
 
43
END { 
 
44
    foreach ( $Test::ntest..$NUMTESTS) {
 
45
        skip('Unable to run all of the DB tests',1);
 
46
    }
 
47
}
 
48
 
 
49
 
37
50
if( $error ==  1 ) {
38
51
    exit(0);
39
52
}
40
53
 
 
54
 
41
55
require Bio::DB::GenBank;
42
56
require Bio::DB::GenPept;
43
57
require Bio::DB::SwissProt;
44
58
 
 
59
 
45
60
my $testnum;
46
61
my $verbose = 0;
47
62
 
52
67
## total number of tests that will be run. 
53
68
 
54
69
 
55
 
my ($gb,$seq,$seqio);
 
70
my ($gb,$seq,$seqio,$query);
56
71
# get a single seq
57
 
 
58
 
 
59
 
eval {         
60
 
    ok defined ( $gb = new Bio::DB::GenBank('-verbose'=>$verbose) );     
61
 
    ok( defined ($seq = $gb->get_Seq_by_id('MUSIGHBA1')));
 
72
eval {
 
73
    ok defined ( $gb = new Bio::DB::GenBank('-verbose'=>$verbose,'-delay'=>0) );
 
74
    $seq = $gb->get_Seq_by_id('MUSIGHBA1');
 
75
    $seq ? ok 1 : exit 0;
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);
69
83
};
70
84
if ($@) {
71
 
    warn "Warning: Couldn't connect to Genbank with Bio::DB::GenBank.pm!\nError: $@\nDo you have network access? Skipping all other tests";
 
85
    if( $DEBUG ) { 
 
86
        warn "Warning: Couldn't connect to Genbank with Bio::DB::GenBank.pm!\nError: $@\nDo you have network access? Skipping all other tests";
 
87
    }
72
88
    foreach ( $Test::ntest..$NUMTESTS ) { skip('no network access',1); }
73
89
    exit(0);
74
90
}
75
 
 
76
91
$seq = $seqio = undef;
77
92
 
78
93
eval {
79
 
    ok( defined($seqio = $gb->get_Stream_by_batch([ qw(J00522 AF303112 
 
94
    ok( defined($seqio = $gb->get_Stream_by_id([ qw(J00522 AF303112 
80
95
                                                         2981014)])));
81
96
    ok($seqio->next_seq->length, 408);
82
97
    ok($seqio->next_seq->length, 1611);
84
99
};
85
100
 
86
101
if ($@) {
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); }
89
104
    exit(0);
90
105
}
91
106
$seq = $seqio = undef;
92
107
 
93
108
eval { 
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');
98
113
    ok(defined $seq);
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);
104
119
};
105
120
 
106
121
if ($@) {
107
 
    warn "Warning: Couldn't connect to Genbank with Bio::DB::GenPept.pm!\n$@";
 
122
    if( $DEBUG ) { 
 
123
        warn "Warning: Couldn't connect to Genbank with Bio::DB::GenPept.pm!\n$@";
 
124
    }
108
125
    foreach( $Test::ntest..$NUMTESTS ) { 
109
126
        skip('could not connect with GenPept',1); 
110
127
    }
112
129
}
113
130
$seq  = $seqio = undef;
114
131
 
115
 
eval { 
116
 
    ok defined($gb = new Bio::DB::SwissProt('-verbose'=>$verbose)); 
 
132
eval {
 
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');
 
137
 
120
138
    ok(defined($seq = $gb->get_Seq_by_acc('P43780')));
121
139
    ok( $seq->length, 103); 
 
140
 
122
141
    ok( defined( $seq = $gb->get_Seq_by_acc('O39869')));
123
142
    ok( $seq->length, 56);
 
143
 
124
144
    ok($seq->primary_id, 'O39869');
125
145
    ok($seq->division, 'UNK');
126
 
 
 
146
 
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');
134
154
 
135
155
    ok( defined($gb = new Bio::DB::SwissProt('-verbose'=>$verbose, 
136
 
                                             '-retrievaltype' => 'tempfile')));
 
156
                                             '-retrievaltype' => 'tempfile',
 
157
                                             '-delay' => 0,
 
158
                                            )));
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()));
144
166
};
145
167
 
146
168
if ($@) {
147
 
    print STDERR "Warning: Couldn't connect to SwissProt with Bio::DB::Swiss.pm!\n$@";
 
169
    if( $DEBUG ) { 
 
170
        print STDERR "Warning: Couldn't connect to SwissProt with Bio::DB::Swiss.pm!\n$@";
 
171
    }
148
172
    foreach ( $Test::ntest..$NUMTESTS) { 
149
173
        skip('could not connect to swissprot',1);
150
174
    }
155
179
eval {
156
180
    ok defined ( $gb = new Bio::DB::GenBank('-verbose' =>$verbose,
157
181
                                            '-format' => 'fasta',
158
 
                                            '-retrievaltype' => 'tempfile') );
 
182
                                            '-retrievaltype' => 'tempfile',
 
183
                                            '-delay' => 0) );
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 
167
192
                                                        2981014)])));
168
193
    ok( $seqio->next_seq->length, 408);
169
194
    undef $gb;  # test the case where the db is gone, 
171
196
 
172
197
    ok($seqio->next_seq->length, 1611);
173
198
    ok($seqio->next_seq->length, 1156);
174
 
    
175
 
};
176
 
 
177
 
if ($@) {
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); 
181
 
    }
182
 
}
183
 
$seq = $seqio = undef;
 
199
};
 
200
 
 
201
if ($@) {
 
202
    if( $DEBUG ) {
 
203
        warn "Warning: Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm!\n $@\n";
 
204
    }
 
205
    foreach ( $Test::ntest..$NUMTESTS ) { 
 
206
        skip('could not connect to Genbank',1); 
 
207
    }
 
208
}
 
209
$seq = $seqio = undef;
 
210
 
 
211
$seq = undef;
 
212
# test pipeline creation
 
213
eval {
 
214
    ok defined ( $gb = new Bio::DB::GenBank('-verbose' =>$verbose,
 
215
                                            '-retrievaltype' => 'pipeline',
 
216
                                            '-delay'  => 0,
 
217
                                           ) );
 
218
    ok( defined ($seq = $gb->get_Seq_by_id('MUSIGHBA1')));
 
219
    ok($seq->length, 408); 
 
220
    $seq = $gb->get_Seq_by_acc('AF303112');
 
221
    ok( defined $seq);
 
222
    ok( $seq->length, 1611);
 
223
    ok(defined($seqio = $gb->get_Stream_by_id([ qw(J00522 AF303112 
 
224
                                                        2981014)])));
 
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
 
228
 
 
229
    ok($seqio->next_seq->length, 1611);
 
230
    ok($seqio->next_seq->length, 1156);
 
231
};
 
232
 
 
233
if ($@) {
 
234
    if( $DEBUG ) {
 
235
        warn "Warning: Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm!\n $@\n";
 
236
    }
 
237
    foreach ( $Test::ntest..$NUMTESTS ) { 
 
238
        skip('could not connect to Genbank',1); 
 
239
    }
 
240
}
 
241
$seq = $seqio = undef;
 
242
 
 
243
 
 
244
# test query facility
 
245
eval {
 
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;
 
253
  ok @ids > 0;
 
254
  ok @ids == $query->count;
 
255
  ok defined ($gb = Bio::DB::GenBank->new('-verbose' =>$verbose,
 
256
                                          '-delay'  => 0,
 
257
                                         ));
 
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);
 
262
};
 
263
 
 
264
if ($@) {
 
265
    if( $DEBUG ) {
 
266
        warn "Warning: Couldn't connect to complete GenBank query tests!\n $@\n";
 
267
    }
 
268
    foreach ( $Test::ntest..$NUMTESTS ) { 
 
269
        skip('could not connect to Genbank',1); 
 
270
    }
 
271
  }
 
272
$seq = $seqio = undef;
 
273
 
 
274
# test query facility
 
275
eval {
 
276
  ok defined ( $query = Bio::DB::Query::GenBank->new('-verbose' => $verbose,
 
277
                                                     '-db'      => 'nucleotide',
 
278
                                                     '-ids'     => [qw(J00522
 
279
                                                                       AF303112
 
280
                                                                       2981014)]));
 
281
  ok $query->count > 0;
 
282
  my @ids = $query->ids;
 
283
  ok @ids > 0;
 
284
  ok @ids == $query->count;
 
285
  ok defined ($gb = Bio::DB::GenBank->new('-verbose' =>$verbose,
 
286
                                          '-delay'  => 0,
 
287
                                         ));
 
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
 
293
};
 
294
 
 
295
if ($@) {
 
296
    if( $DEBUG ) {
 
297
        warn "Warning: Couldn't connect to complete GenBank query tests!\n $@\n";
 
298
    }
 
299
    foreach ( $Test::ntest..$NUMTESTS ) { 
 
300
        skip('could not connect to Genbank',1); 
 
301
    }
 
302
}
 
303
$seq = $seqio = undef;
 
304
print STDERR "\n";