File: RemoteBlast.t

package info (click to toggle)
bioperl 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 40,768 kB
  • ctags: 12,005
  • sloc: perl: 174,299; xml: 13,923; sh: 1,941; lisp: 1,803; asm: 109; makefile: 53
file content (161 lines) | stat: -rw-r--r-- 4,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# -*-Perl-*- Test Harness script for Bioperl
# $Id: RemoteBlast.t 15112 2008-12-08 18:12:38Z sendu $

use strict;

BEGIN {
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 16,
               -requires_modules => [qw(IO::String LWP LWP::UserAgent)],
               -requires_networking => 1);
    
    use_ok('Bio::Tools::Run::RemoteBlast');
}

my $prog = 'blastp';
my $db   = 'swissprot';
my $e_val= '1e-10';
my $v = test_debug();
my $remote_blast = Bio::Tools::Run::RemoteBlast->new('-verbose' => $v,
													'-prog' => $prog,
													'-data' => $db,
													'-expect' => $e_val,
							  );
$remote_blast->submit_parameter('ENTREZ_QUERY', 
										  'Escherichia coli[ORGN]');
my $inputfilename = test_input_file('ecolitst.fa');
ok( -e $inputfilename);	

ok(1, 'Text BLAST');

my $r = $remote_blast->submit_blast($inputfilename);
ok($r);
print STDERR "waiting..." if( $v > 0 );
while ( my @rids = $remote_blast->each_rid ) {
	foreach my $rid ( @rids ) {
		my $rc = $remote_blast->retrieve_blast($rid);
		if( !ref($rc) ) {
			if( $rc < 0 ) { 		
				$remote_blast->remove_rid($rid);
				# need a better solution for when 'Server failed to return any data'
			}
			print STDERR "." if ( $v > 0 );
			sleep 5;
		} else { 
			ok(1);
			$remote_blast->remove_rid($rid);
			my $result = $rc->next_result;
			like($result->database_name, qr/swissprot/i);
			my $count = 0;
			while( my $hit = $result->next_hit ) {		
				$count++;
				next unless ( $v > 0);
				print "sbjct name is ", $hit->name, "\n";
				while( my $hsp = $hit->next_hsp ) {
					print "score is ", $hsp->score, "\n";
				} 
			}
			is($count, 3);
		}
	}
}

# test blasttable

ok(1, 'Tabular BLAST');

my $remote_blast2 = Bio::Tools::Run::RemoteBlast->new
  ('-verbose'    => $v,
	'-prog'       => $prog,
	'-data'       => $db,
	'-readmethod' => 'blasttable',
	'-expect'     => $e_val,
  );
$remote_blast2->submit_parameter('ENTREZ_QUERY', 'Escherichia coli[ORGN]');

$remote_blast2->retrieve_parameter('ALIGNMENT_VIEW', 'Tabular');

$inputfilename = test_input_file('ecolitst.fa');

$r = $remote_blast2->submit_blast($inputfilename);
ok($r);
print STDERR "waiting..." if( $v > 0 );
while ( my @rids = $remote_blast2->each_rid ) {
	foreach my $rid ( @rids ) {
		my $rc = $remote_blast2->retrieve_blast($rid);
		if( !ref($rc) ) {
			if( $rc < 0 ) { 		
				$remote_blast2->remove_rid($rid);
				# need a better solution for when 'Server failed to return any data'
			}
			print STDERR "." if ( $v > 0 );
			sleep 5;
		} else { 
			ok(1);
			$remote_blast2->remove_rid($rid);
			my $count = 0;
			while (my $result = $rc->next_result) {
				while( my $hit = $result->next_hit ) {		
					$count++;
					next unless ( $v > 0);
					print "sbjct name is ", $hit->name, "\n";
					while( my $hsp = $hit->next_hsp ) {
						print "score is ", $hsp->score, "\n";
					} 
				}
			}
			is($count, 3);
		}
	}
}

SKIP: {
    test_skip(-tests => 5, -requires_module => 'Bio::SearchIO::blastxml');
	
	my $remote_blastxml = Bio::Tools::Run::RemoteBlast->new('-prog' => $prog,
		'-data'       => $db,
		'-readmethod' => 'xml',
		'-expect'     => $e_val,
	);
	$remote_blastxml->submit_parameter('ENTREZ_QUERY', 
									'Escherichia coli[ORGN]');
	
	$remote_blastxml->retrieve_parameter('FORMAT_TYPE', 'XML');
	$inputfilename = test_input_file('ecolitst.fa');
	
	ok(1, 'XML BLAST');
	
	$r = $remote_blastxml->submit_blast($inputfilename);
	ok($r);
	print STDERR "waiting..." if( $v > 0 );
	while ( my @rids = $remote_blastxml->each_rid ) {
		foreach my $rid ( @rids ) {
			my $rc = $remote_blastxml->retrieve_blast($rid);
			if( !ref($rc) ) {
				if( $rc < 0 ) { 		
					$remote_blastxml->remove_rid($rid);
					# need a better solution for when 'Server failed to return any data'
				}
				print STDERR "." if ( $v > 0 );
				sleep 5;
			} else { 
				ok(1);
				$remote_blastxml->remove_rid($rid);
				my $result = $rc->next_result;
				like($result->database_name, qr/swissprot/i);
				my $count = 0;
				while( my $hit = $result->next_hit ) {		
					$count++;
					next unless ( $v > 0);
					print "sbjct name is ", $hit->name, "\n";
					while( my $hsp = $hit->next_hsp ) {
						print "score is ", $hsp->score, "\n";
					} 
				}
				is($count, 3);
			}
		}
	}
}