Added more missing 'Data::Stag' and 'LWP::UserAgent' requirements
[bioperl-live.git] / t / Tools / Run / RemoteBlast_rpsblast.t
blob9ae95c9494e2e49c3441ab97309ca02c7f3f9dde
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
19                                            LWP::UserAgent)],
20                -requires_networking => 1);
22     use_ok('Bio::Tools::Run::RemoteBlast');
25 my $v = test_debug();
26 my $inputfilename = test_input_file('ecolitst.fa');
27 ok( -e $inputfilename);
29 my $remote_rpsblast
30     = Bio::Tools::Run::RemoteBlast->new(-verbose    => test_debug(),
31                                         -prog       => 'blastp',
32                                         -data       => 'cdd',
33                                         -readmethod => 'blasttable',
34                                         -expect     => '1e-10',
35                                         );
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     };
49     ok($status,'rpsblast blasttable submitted');
50     skip("Error accessing remote BLAST interface: $@", 4) if $@;
52     my @rids = $remote_rpsblast->each_rid;
53     is(@rids, 1, 'should only be one RID');
54     skip("Wrong number of RIDs: ".scalar(@rids), 3) if @rids != 1;
56     diag("Retrieving $rids[0]...\n") if $v;
57     my $rc;
58     while (defined($rc = $remote_rpsblast->retrieve_blast($rids[0]))) {
59         if ( !ref($rc) ) {
60             if ( $rc < 0 ) {
61                 skip("need a better solution for when 'Server failed to return any data'",2);
62             }
63             sleep 5;
64             diag("Retrieval attempt: $attempt\n") if $v;
65             $attempt++ < 10 ? next : last;
66         }
67         else {
68             last;
69         }
70     }
71     $remote_rpsblast->remove_rid($rids[0]);
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         
79         while (my $result = $rc->next_result) {
80             while ( my $hit = $result->next_hit ) {
81                 $count++;
82                 next unless ( $v > 0);
83                 print "sbjct name is ", $hit->name, "\n";
84                 while ( my $hsp = $hit->next_hsp ) {
85                     print "score is ", $hsp->bits, "\n";
86                 }
87             }
88         }
89         cmp_ok($count, '>=', 45, 'HSPs returned');
90     }
91     elsif ($attempt > 10) {
92         # have a test fail here (there should not be repeated failed attempts to
93         # get reports)
94         ok(0,'Exceeded maximum attempts on server to retrieve report');
95         diag("Timeout, did not return report after ".($attempt - 1)." attempts");
96         skip('Remote server timeout problems', 2);
97     }
98     else {
99         # have a test fail here (whatever is returned should be eval as true and
100         # be a SearchIO)
101         ok(0,"Other problem on remote server, no report returned: $rc");
102         skip('Possible remote server problems', 2);
103     }
106 # To be a good citizen, we should restore the default NCBI service
107 # ('plain') for future tests
108 $Bio::Tools::Run::RemoteBlast::HEADER{'SERVICE'} = 'plain';