t/*: remove "use lib '.'" and t/lib/Error.pm
[bioperl-live.git] / t / RemoteDB / GenPept.t
blob73c49c9abbfca36f8feb152686ef1e2821f136a8
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         use Bio::Root::Test;
9         test_begin(-tests => 21,
10                            -requires_modules => [qw(IO::String
11                                                                             LWP::UserAgent
12                                                                                 HTTP::Request::Common)],
13                            -requires_networking => 1);
15         use_ok('Bio::DB::GenPept');
18 my %expected_lengths = (
19     'AAC06201'  => 353,
20     'AAD15290'  => 136,
21     'P31383'    => 635,
22     '2AAA_YEAST' => 635
25 my ($gb, $seq, $seqio);
28 # Bio::DB::GenPept
30 ok $gb = Bio::DB::GenPept->new();
31 SKIP: {
32     eval {$seqio = $gb->get_seq_stream(-uids => [2981015, 1621261, 195055], -mode => 'batch');};
33     skip "Couldn't connect to complete GenPept tests. Skipping those tests", 8 if $@;
34     my %result = ('AAC06201' => 353, 'CAB02640' => 193, 'AAD15290' => 136);
35     my $ct = 0;
36     while ($seq = $seqio->next_seq) {
37                 $ct++;
38                 my $acc = $seq->accession;
39         ok exists $result{ $acc };
40         is $seq->length, $result{ $acc };
41                 delete $result{$acc};
42     }
43     skip('No seqs returned', 8) if !$ct;
44         is $ct, 3;
45     is %result, 0;
48 $seq = $seqio = undef;
50 ok $gb = Bio::DB::GenPept->new('-delay' => 0);
51 SKIP: {
52     eval {$seq = $gb->get_Seq_by_id('195055');};
53     skip "Couldn't connect to Genbank with Bio::DB::GenPept.pm. Skipping those tests", 10 if $@;
54     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
55     eval {$seq = $gb->get_Seq_by_acc('AAC06201');};
56     skip "Couldn't connect to Genbank with Bio::DB::GenPept.pm. Skipping those tests", 9 if $@;
57     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
58     eval {$seqio = $gb->get_Stream_by_id([qw(AAC06201 195055)]);};
59     skip "Couldn't connect to Genbank with Bio::DB::GenPept.pm. Skipping those tests", 8 if $@;
60     my $done = 0;
61     while( my $s = $seqio->next_seq ) {
62         is $s->length, $expected_lengths{$s->display_id}, $s->display_id;
63         $done++;
64     }
65     skip('No seqs returned', 8) if !$done;
66     is $done, 2;
67     # swissprot genpept parsing
68     eval {$seq = $gb->get_Seq_by_acc('P31383');};
69     skip "Couldn't connect to Genbank with Bio::DB::GenPept.pm. Skipping those tests", 5 if $@;
70     is $seq->length, $expected_lengths{$seq->display_id}, $seq->display_id;
72     # test dbsource stuff
73     # small chance this might change but hopefully not
74     my @annot = $seq->annotation->get_Annotations('dblink');
75     cmp_ok(scalar(@annot), '>', 31);
76     is $annot[0]->database, 'UniProtKB';
77     is $annot[0]->primary_id, '2AAA_YEAST';
78     is (($seq->annotation->get_Annotations('swissprot_dates'))[0]->value, 'Jul 1, 1993');