fix skip test count (off by 1)
[bioperl-run.git] / t / Tools / Run / RemoteBlast_rpsblast.t
blob3676abec9c4928147156bd5601d61f20ef7a12b8
1 # -*-Perl-*- Test Harness script for Bioperl
2 #       $Id$    
4 # malcolm_cook@stowers.org: this test is in a separate file from
5 # RemoteBlast.t (on which it is modelled) since there is some sort of
6 # side-effecting between the multiple remote blasts that is causing
7 # this test to fail, if it comes last, or the other test to fail, if
8 # this one comes first.  THIS IS A BUG EITHER IN REMOTE BLAST OR MY
9 # UNDERSTANDING, i.e. of how to initialize it.
11 use strict;
13 BEGIN {
14     use lib '.';
15     use Bio::Root::Test;
17     test_begin(-tests => 7,
18                -requires_modules => [qw(IO::String LWP LWP::UserAgent)],
19                -requires_networking => 1);
21     use_ok('Bio::Tools::Run::RemoteBlast');
24 my $v = test_debug();
25 my $inputfilename = test_input_file('ecolitst.fa');
26 ok( -e $inputfilename); 
28 my $remote_rpsblast = Bio::Tools::Run::RemoteBlast->new
29   ('-verbose'    => test_debug(),
30    '-prog'       => 'blastp',
31    '-data'       => 'cdsearch/cdd',
32    '-readmethod' => 'blasttable',
33    '-expect'     => '1e-10',
34   );
36 $remote_rpsblast->retrieve_parameter('ALIGNMENT_VIEW', 'Tabular');
38 # This is the key to getting job run using rpsblast:
39 $Bio::Tools::Run::RemoteBlast::HEADER{'SERVICE'} = 'rpsblast'; 
41 my $attempt = 1;
43 SKIP: {
44     my $status;
45     eval{
46         $status = $remote_rpsblast->submit_blast($inputfilename);
47     };
48     
49     ok($status,'rpsblast blasttable submitted');
50     
51     skip("Error accessing remote BLAST interface: $@", 3) if $@;
52     
53     my @rids = $remote_rpsblast->each_rid;
54     is(@rids, 1, 'should only be one RID');
55     skip("Wrong number of RIDs: ".scalar(@rids), 2) if @rids != 1;
56     
57     print STDERR "waiting [$rids[0]]..." if( $v > 0 );
58     my $rc;
59     while (defined($rc = $remote_rpsblast->retrieve_blast($rids[0]))) {
60         if ( !ref($rc) ) {
61             if ( $rc < 0 ) {
62                 skip("need a better solution for when 'Server failed to return any data'",2);
63             }
64             sleep 5;
65             print STDERR "Retrieval attempt: $attempt\n" if ( $v > 0 );
66             $attempt++ < 10 ? next : last;
67         } else {
68             last
69         }
70     }
71     $remote_rpsblast->remove_rid($rids[0]);
72     
73     if ($rc) {
74         ok(1,'retrieve_blast succeeded');
75         $remote_rpsblast->remove_rid($rids[0]);
76         my $count = 0;
77         isa_ok($rc, 'Bio::SearchIO');
78         while (my $result = $rc->next_result) {
79             while ( my $hit = $result->next_hit ) {
80                 $count++;
81                 next unless ( $v > 0);
82                 print "sbjct name is ", $hit->name, "\n";
83                 while ( my $hsp = $hit->next_hsp ) {
84                     print "score is ", $hsp->bits, "\n";
85                 } 
86             }
87         }
88         cmp_ok($count, '>=', 45, 'HSPs returned');
89     } elsif ($attempt > 10) {
90         # have a test fail here (there should not be repeated failed attempts to
91         # get reports)
92         
93         ok(0,'Exceeded maximum attempts on server to retrieve report');
94         skip("Timeout, did not return report after ".($attempt - 1)." attempts", 2);
95     } else {
96         # have a test fail here (whatever is returned should be eval as true and
97         # be a SearchIO)
98         
99         ok(0,"Other problem on remote server, no report returned: $rc");
100         skip('Possible remote server problems', 1);
101     }
104 # To be a good citizen, we should restore the default NCBI service
105 # ('plain') for future tests
106 $Bio::Tools::Run::RemoteBlast::HEADER{'SERVICE'} = 'plain';