Catch failing tie'd DB_File handle
[bioperl-live.git] / t / RemoteBlast.t
blob1b84cc49c230625e13c61fd4a0fcf943df33253d
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib 't/lib';
8     use BioperlTest;
9     
10     test_begin(-tests => 16,
11                -requires_modules => [qw(IO::String LWP LWP::UserAgent)],
12                -requires_networking => 1);
13     
14     use_ok('Bio::Tools::Run::RemoteBlast');
17 my $prog = 'blastp';
18 my $db   = 'swissprot';
19 my $e_val= '1e-10';
20 my $v = test_debug();
21 my $remote_blast = Bio::Tools::Run::RemoteBlast->new('-verbose' => $v,
22                                                                                                         '-prog' => $prog,
23                                                                                                         '-data' => $db,
24                                                                                                         '-expect' => $e_val,
25                                                           );
26 $remote_blast->submit_parameter('ENTREZ_QUERY', 
27                                                                                   'Escherichia coli[ORGN]');
28 my $inputfilename = test_input_file('ecolitst.fa');
29 ok( -e $inputfilename); 
31 ok(1, 'Text BLAST');
33 my $r = $remote_blast->submit_blast($inputfilename);
34 ok($r);
35 print STDERR "waiting..." if( $v > 0 );
36 while ( my @rids = $remote_blast->each_rid ) {
37         foreach my $rid ( @rids ) {
38                 my $rc = $remote_blast->retrieve_blast($rid);
39                 if( !ref($rc) ) {
40                         if( $rc < 0 ) {                 
41                                 $remote_blast->remove_rid($rid);
42                                 # need a better solution for when 'Server failed to return any data'
43                         }
44                         print STDERR "." if ( $v > 0 );
45                         sleep 5;
46                 } else { 
47                         ok(1);
48                         $remote_blast->remove_rid($rid);
49                         my $result = $rc->next_result;
50                         like($result->database_name, qr/swissprot/i);
51                         my $count = 0;
52                         while( my $hit = $result->next_hit ) {          
53                                 $count++;
54                                 next unless ( $v > 0);
55                                 print "sbjct name is ", $hit->name, "\n";
56                                 while( my $hsp = $hit->next_hsp ) {
57                                         print "score is ", $hsp->score, "\n";
58                                 } 
59                         }
60                         is($count, 3);
61                 }
62         }
65 # test blasttable
67 ok(1, 'Tabular BLAST');
69 my $remote_blast2 = Bio::Tools::Run::RemoteBlast->new
70   ('-verbose'    => $v,
71         '-prog'       => $prog,
72         '-data'       => $db,
73         '-readmethod' => 'blasttable',
74         '-expect'     => $e_val,     
75   );
76 $remote_blast2->submit_parameter('ENTREZ_QUERY', 'Escherichia coli[ORGN]');
78 $remote_blast2->retrieve_parameter('ALIGNMENT_VIEW', 'Tabular');
80 $inputfilename = test_input_file('ecolitst.fa');
82 $r = $remote_blast2->submit_blast($inputfilename);
83 ok($r);
84 print STDERR "waiting..." if( $v > 0 );
85 while ( my @rids = $remote_blast2->each_rid ) {
86         foreach my $rid ( @rids ) {
87                 my $rc = $remote_blast2->retrieve_blast($rid);
88                 if( !ref($rc) ) {
89                         if( $rc < 0 ) {                 
90                                 $remote_blast2->remove_rid($rid);
91                                 # need a better solution for when 'Server failed to return any data'
92                         }
93                         print STDERR "." if ( $v > 0 );
94                         sleep 5;
95                 } else { 
96                         ok(1);
97                         $remote_blast2->remove_rid($rid);
98                         my $result = $rc->next_result;
99                         my $count = 0;
100                         while( my $hit = $result->next_hit ) {          
101                                 $count++;
102                                 next unless ( $v > 0);
103                                 print "sbjct name is ", $hit->name, "\n";
104                                 while( my $hsp = $hit->next_hsp ) {
105                                         print "score is ", $hsp->score, "\n";
106                                 } 
107                         }
108                         is($count, 3);
109                 }
110         }
113 SKIP: {
114     test_skip(-tests => 5, -requires_module => 'Bio::SearchIO::blastxml');
115         
116         my $remote_blastxml = Bio::Tools::Run::RemoteBlast->new('-prog' => $prog,
117                 '-data'       => $db,
118                 '-readmethod' => 'xml',
119                 '-expect'     => $e_val,
120         );
121         $remote_blast->submit_parameter('ENTREZ_QUERY', 
122                                                                         'Escherichia coli[ORGN]');
123         
124         $remote_blastxml->retrieve_parameter('FORMAT_TYPE', 'XML');
125         $inputfilename = test_input_file('ecolitst.fa');
126         
127         ok(1, 'XML BLAST');
128         
129         $r = $remote_blastxml->submit_blast($inputfilename);
130         ok($r);
131         print STDERR "waiting..." if( $v > 0 );
132         while ( my @rids = $remote_blastxml->each_rid ) {
133                 foreach my $rid ( @rids ) {
134                         my $rc = $remote_blastxml->retrieve_blast($rid);
135                         if( !ref($rc) ) {
136                                 if( $rc < 0 ) {                 
137                                         $remote_blastxml->remove_rid($rid);
138                                         # need a better solution for when 'Server failed to return any data'
139                                 }
140                                 print STDERR "." if ( $v > 0 );
141                                 sleep 5;
142                         } else { 
143                                 ok(1);
144                                 $remote_blastxml->remove_rid($rid);
145                                 my $result = $rc->next_result;
146                                 like($result->database_name, qr/swissprot/i);
147                                 my $count = 0;
148                                 while( my $hit = $result->next_hit ) {          
149                                         $count++;
150                                         next unless ( $v > 0);
151                                         print "sbjct name is ", $hit->name, "\n";
152                                         while( my $hsp = $hit->next_hsp ) {
153                                                 print "score is ", $hsp->score, "\n";
154                                         } 
155                                 }
156                                 is($count, 3);
157                         }
158                 }
159         }