tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / t / Tools / Run / RemoteBlast.t
blob61eb6600cdfa404a87bd80820a5da989501e22eb
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib '.';
8     use Bio::Root::Test;
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 $count = 0;
99                         while (my $result = $rc->next_result) {
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                         }
109                         is($count, 3);
110                 }
111         }
114 SKIP: {
115     test_skip(-tests => 5, -requires_module => 'Bio::SearchIO::blastxml');
116         
117         my $remote_blastxml = Bio::Tools::Run::RemoteBlast->new('-prog' => $prog,
118                 '-data'       => $db,
119                 '-readmethod' => 'xml',
120                 '-expect'     => $e_val,
121         );
122         $remote_blastxml->submit_parameter('ENTREZ_QUERY', 
123                                                                         'Escherichia coli[ORGN]');
124         
125         $remote_blastxml->retrieve_parameter('FORMAT_TYPE', 'XML');
126         $inputfilename = test_input_file('ecolitst.fa');
127         
128         ok(1, 'XML BLAST');
129         
130         $r = $remote_blastxml->submit_blast($inputfilename);
131         ok($r);
132         print STDERR "waiting..." if( $v > 0 );
133         while ( my @rids = $remote_blastxml->each_rid ) {
134                 foreach my $rid ( @rids ) {
135                         my $rc = $remote_blastxml->retrieve_blast($rid);
136                         if( !ref($rc) ) {
137                                 if( $rc < 0 ) {                 
138                                         $remote_blastxml->remove_rid($rid);
139                                         # need a better solution for when 'Server failed to return any data'
140                                 }
141                                 print STDERR "." if ( $v > 0 );
142                                 sleep 5;
143                         } else { 
144                                 ok(1);
145                                 $remote_blastxml->remove_rid($rid);
146                                 my $result = $rc->next_result;
147                                 like($result->database_name, qr/swissprot/i);
148                                 my $count = 0;
149                                 while( my $hit = $result->next_hit ) {          
150                                         $count++;
151                                         next unless ( $v > 0);
152                                         print "sbjct name is ", $hit->name, "\n";
153                                         while( my $hsp = $hit->next_hsp ) {
154                                                 print "score is ", $hsp->score, "\n";
155                                         } 
156                                 }
157                                 is($count, 3);
158                         }
159                 }
160         }