1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 44,
11 -requires_modules => [qw(IO::String
13 HTTP::Request::Common)],
14 -requires_networking => 1);
16 use_ok('Bio::DB::GenBank');
19 my %expected_lengths = (
29 my ($gb, $seq, $seqio, $seqin);
35 ok $gb = Bio::DB::GenBank->new('-delay'=>0), 'Bio::DB::GenBank';
39 eval {$seq = $gb->get_Seq_by_id('J00522');1};
40 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Do you have network access? Skipping GenBank tests: $@", 4 if $@;
41 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
42 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
43 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 3 if $@;
44 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
45 eval {$seq = $gb->get_Seq_by_version('AF303112.1');};
46 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 2 if $@;
47 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
48 eval {$seq = $gb->get_Seq_by_gi('405830');};
49 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 1 if $@;
50 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
53 $seq = $seqio = undef;
57 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
58 skip "Batch access test failed for Genbank. Skipping those tests", 4 if $@;
60 while (my $s = $seqio->next_seq) {
61 is $s->length, $expected_lengths{$s->display_id}, $s->display_id;
64 skip('No seqs returned', 4) if !$done;
68 $seq = $seqio = undef;
70 # test the temporary file creation and fasta
71 ok $gb = Bio::DB::GenBank->new('-format' => 'fasta', '-retrievaltype' => 'tempfile', '-delay' => 0);
73 eval {$seq = $gb->get_Seq_by_id('J00522');};
74 skip "Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 6 if $@;
75 # last part of id holds the key
76 is $seq->length, $expected_lengths{(split(/\|/,$seq->display_id))[-1]}, $seq->display_id;
77 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
78 skip "Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 5 if $@;
79 # last part of id holds the key
80 is $seq->length, $expected_lengths{(split(/\|/,$seq->display_id))[-1]}, $seq->display_id;
81 # batch mode requires genbank format
82 $gb->request_format("gb");
83 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
84 skip "Couldn't connect to complete GenBank batch tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 4 if $@;
86 while (my $s = $seqio->next_seq) {
87 is $s->length, $expected_lengths{$s->display_id};
88 undef $gb; # test the case where the db is gone,
89 # but a temp file should remain until seqio goes away.
92 skip('No seqs returned', 4) if !$done;
96 $seq = $seqio = undef;
98 # test pipeline creation
99 ok $gb = Bio::DB::GenBank->new('-retrievaltype' => 'pipeline', '-delay' => 0);
101 eval {$seq = $gb->get_Seq_by_id('J00522');};
102 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 6 if $@;
103 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
104 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
105 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 5 if $@;
106 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
107 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
108 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 4 if $@;
110 while (my $s = $seqio->next_seq) {
111 is $s->length, $expected_lengths{$s->display_id}, $s->display_id;
112 undef $gb; # test the case where the db is gone,
113 # but the pipeline should remain until seqio goes away
116 skip('No seqs returned', 4) if !$done;
120 $seq = $seqio = undef;
122 # test contig retrieval
123 ok $gb = Bio::DB::GenBank->new('-delay' => 0, '-format' => 'gbwithparts');
125 eval {$seq = $gb->get_Seq_by_id('JH374761');};
126 skip "Couldn't connect to GenBank with Bio::DB::GenBank.pm. Skipping those tests", 3 if $@;
127 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
128 # now to check that postprocess_data in NCBIHelper catches CONTIG...
129 ok $gb = Bio::DB::GenBank->new('-delay' => 0, '-format' => 'gb');
130 eval {$seq = $gb->get_Seq_by_id('JH374761');};
131 skip "Couldn't connect to GenBank with Bio::DB::GenBank.pm. Skipping those tests", 1 if $@;
132 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
135 $seq = $seqio = undef;
139 ok $gb = Bio::DB::GenBank->new(-format => 'Fasta', -seq_start => 2, -seq_stop => 7);
141 eval {$seq = $gb->get_Seq_by_acc("A11111");};
142 skip "Couldn't connect to complete GenBank tests. Skipping those tests", 15 if $@;
145 ok $gb = Bio::DB::GenBank->new(-format => 'Fasta', -complexity => 0);
146 eval {$seqin = $gb->get_Stream_by_acc("5");};
147 skip "Couldn't connect to complete GenBank tests. Skipping those tests", 13 if $@;
148 @result = (1136, 'dna', 342, 'protein');
149 while ($seq = $seqin->next_seq) {
150 is $seq->length, shift(@result);
151 is $seq->alphabet, shift(@result);
154 # Real batch retrieval using epost/efetch
155 # these tests may change if integrated further into Bio::DB::Gen*
156 # Currently only useful for retrieving GI's via get_seq_stream
157 $gb = Bio::DB::GenBank->new();
158 eval {$seqin = $gb->get_seq_stream(-uids => [4887706 ,431229, 147460], -mode => 'batch');};
159 skip "Couldn't connect to complete GenBank batchmode epost/efetch tests. Skipping those tests", 8 if $@;
160 my %result = ('M59757' => 12611 ,'X76083'=> 3140, 'J01670'=> 1593);
162 while ($seq = $seqin->next_seq) {
164 my $acc = $seq->accession;
165 ok exists $result{ $acc };
166 is $seq->length, $result{ $acc };
167 delete $result{$acc};
169 skip('No seqs returned', 8) if !$ct;