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