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 = (
28 my ($gb, $seq, $seqio, $seqin);
34 ok $gb = Bio::DB::GenBank->new('-delay'=>0), 'Bio::DB::GenBank';
38 eval {$seq = $gb->get_Seq_by_id('J00522');1};
39 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Do you have network access? Skipping GenBank tests: $@", 4 if $@;
40 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
41 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
42 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 3 if $@;
43 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
44 eval {$seq = $gb->get_Seq_by_version('AF303112.1');};
45 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 2 if $@;
46 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
47 eval {$seq = $gb->get_Seq_by_gi('405830');};
48 skip "Couldn't connect to Genbank with Bio::DB::GenBank.pm. Transient network problems? Skipping GenBank tests: $@", 1 if $@;
49 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
52 $seq = $seqio = undef;
56 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
57 skip "Batch access test failed for Genbank. Skipping those tests", 4 if $@;
59 while (my $s = $seqio->next_seq) {
60 is $s->length, $expected_lengths{$s->display_id}, $s->display_id;
63 skip('No seqs returned', 4) if !$done;
67 $seq = $seqio = undef;
69 # test the temporary file creation and fasta
70 ok $gb = Bio::DB::GenBank->new('-format' => 'fasta', '-retrievaltype' => 'tempfile', '-delay' => 0);
72 eval {$seq = $gb->get_Seq_by_id('J00522');};
73 skip "Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 6 if $@;
74 # last part of id holds the key
75 is $seq->length, $expected_lengths{(split(/\|/,$seq->display_id))[-1]}, $seq->display_id;
76 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
77 skip "Couldn't connect to complete GenBank tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 5 if $@;
78 # last part of id holds the key
79 is $seq->length, $expected_lengths{(split(/\|/,$seq->display_id))[-1]}, $seq->display_id;
80 # batch mode requires genbank format
81 $gb->request_format("gb");
82 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
83 skip "Couldn't connect to complete GenBank batch tests with a tempfile with Bio::DB::GenBank.pm. Skipping those tests", 4 if $@;
85 while (my $s = $seqio->next_seq) {
86 is $s->length, $expected_lengths{$s->display_id};
87 undef $gb; # test the case where the db is gone,
88 # but a temp file should remain until seqio goes away.
91 skip('No seqs returned', 4) if !$done;
95 $seq = $seqio = undef;
97 # test pipeline creation
98 ok $gb = Bio::DB::GenBank->new('-retrievaltype' => 'pipeline', '-delay' => 0);
100 eval {$seq = $gb->get_Seq_by_id('J00522');};
101 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 6 if $@;
102 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
103 eval {$seq = $gb->get_Seq_by_acc('AF303112');};
104 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 5 if $@;
105 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
106 eval {$seqio = $gb->get_Stream_by_id([qw(J00522 AF303112 2981014)]);};
107 skip "Couldn't connect to complete GenBank tests with a pipeline with Bio::DB::GenBank.pm. Skipping those tests", 4 if $@;
109 while (my $s = $seqio->next_seq) {
110 is $s->length, $expected_lengths{$s->display_id}, $s->display_id;
111 undef $gb; # test the case where the db is gone,
112 # but the pipeline should remain until seqio goes away
115 skip('No seqs returned', 4) if !$done;
119 $seq = $seqio = undef;
121 # test contig retrieval
122 ok $gb = Bio::DB::GenBank->new('-delay' => 0, '-format' => 'gbwithparts');
124 eval {$seq = $gb->get_Seq_by_id('JH374761');};
125 skip "Couldn't connect to GenBank with Bio::DB::GenBank.pm. Skipping those tests", 3 if $@;
126 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
127 # now to check that postprocess_data in NCBIHelper catches CONTIG...
128 ok $gb = Bio::DB::GenBank->new('-delay' => 0, '-format' => 'gb');
129 eval {$seq = $gb->get_Seq_by_id('JH374761');};
130 skip "Couldn't connect to GenBank with Bio::DB::GenBank.pm. Skipping those tests", 1 if $@;
131 is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
134 $seq = $seqio = undef;
138 ok $gb = Bio::DB::GenBank->new(-format => 'Fasta', -seq_start => 2, -seq_stop => 7);
140 eval {$seq = $gb->get_Seq_by_acc("A11111");};
141 skip "Couldn't connect to complete GenBank tests. Skipping those tests", 15 if $@;
144 ok $gb = Bio::DB::GenBank->new(-format => 'Fasta', -complexity => 0);
145 eval {$seqin = $gb->get_Stream_by_acc("5");};
146 skip "Couldn't connect to complete GenBank tests. Skipping those tests", 13 if $@;
147 @result = (1136, 'dna', 342, 'protein');
148 while ($seq = $seqin->next_seq) {
149 is $seq->length, shift(@result);
150 is $seq->alphabet, shift(@result);
153 # Real batch retrieval using epost/efetch
154 # these tests may change if integrated further into Bio::DB::Gen*
155 # Currently only useful for retrieving GI's via get_seq_stream
156 $gb = Bio::DB::GenBank->new();
157 eval {$seqin = $gb->get_seq_stream(-uids => [4887706 ,431229, 147460], -mode => 'batch');};
158 skip "Couldn't connect to complete GenBank batchmode epost/efetch tests. Skipping those tests", 8 if $@;
159 my %result = ('M59757' => 12611 ,'X76083'=> 3140, 'J01670'=> 1593);
161 while ($seq = $seqin->next_seq) {
163 my $acc = $seq->accession;
164 ok exists $result{ $acc };
165 is $seq->length, $result{ $acc };
166 delete $result{$acc};
168 skip('No seqs returned', 8) if !$ct;