1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id: SearchIO.t 14995 2008-11-16 06:20:00Z cjfields $
9 test_begin(-tests => 166);
11 use_ok('Bio::SearchIO');
12 use_ok('Bio::Search::SearchUtils');
15 my ($searchio, $result,$iter,$hit,$hsp);
17 # test blasttable output
18 my @eqset = qw( c200-vs-yeast.BLASTN.m9);
19 $searchio = Bio::SearchIO->new(-file => test_input_file('c200-vs-yeast.BLASTN'),
21 $result = $searchio->next_result;
22 isa_ok($result,'Bio::Search::Result::ResultI');
23 my %ref = &Bio::Search::SearchUtils::result2hash($result);
24 is( scalar keys %ref, 67);
25 $searchio = Bio::SearchIO->new(-file => test_input_file('c200-vs-yeast.BLASTN.m8'),
26 -program_name => 'BLASTN',
27 -format => 'blasttable');
28 $result = $searchio->next_result;
29 my %tester = &Bio::Search::SearchUtils::result2hash($result);
30 is( scalar keys %tester, 67);
31 foreach my $key ( sort keys %ref ) {
32 is($tester{$key}, $ref{$key},$key);
35 # test WU-BLAST blasttable output
36 $searchio = Bio::SearchIO->new(-file => test_input_file('test1.wublastp'),
38 $result = $searchio->next_result;
39 isa_ok($result,'Bio::Search::Result::ResultI');
40 my %wuref = &Bio::Search::SearchUtils::result2hash($result);
41 is( scalar keys %wuref, 31);
42 $searchio = Bio::SearchIO->new(-file => test_input_file('test1.blasttab3'),
43 -program_name => 'BLASTP',
44 -format => 'blasttable');
45 $result = $searchio->next_result;
46 my %wutester = &Bio::Search::SearchUtils::result2hash($result);
47 is( scalar keys %wutester, 31);
48 foreach my $key ( sort keys %ref ) {
49 is($wutester{$key}, $wuref{$key},$key);
52 # BLAST 2.2.18+ tabular output (has 13 columns instead of 12)
53 $searchio = Bio::SearchIO->new(-format => 'blasttable',
54 -file => test_input_file('2008.blasttable'));
56 while(my $res = $searchio->next_result) {
57 is($res->query_name, 'gi|1786183|gb|AAC73113.1|');
58 is($res->algorithm, 'BLASTP');
59 is($res->algorithm_version, '2.2.18+');
60 my $hit = $res->next_hit;
61 is($hit->name, 'gi|34395933|sp|P00561.2|AK1H_ECOLI');
62 $hit = $res->next_hit;
63 is($hit->score, 331, 'hit score');
64 is($hit->raw_score, 331, 'hit raw_score');
65 my $hsp = $hit->next_hsp;
66 isa_ok($hsp, 'Bio::SeqFeatureI');
68 float_is($hsp->evalue, 2e-91);
69 is($hsp->start('hit'), 16);
70 is($hsp->end('hit'), 805);
71 is($hsp->start('query'), 5);
72 is($hsp->end('query'), 812);
73 is($hsp->length, 821);
74 float_is($hsp->percent_identity, 30.0852618757613, 'fixed bug 3343 (percent identity)');
75 is($hsp->gaps, 44, 'side effect of fixing bug 3343 (number of gaps)');
76 my $hit_sf = $hsp->hit;
77 my $query_sf = $hsp->query;
78 isa_ok($hit_sf, 'Bio::SeqFeatureI');
79 is($hit_sf->start(), 16);
80 is($hit_sf->end(), 805);
81 is($hit_sf->strand(), 0);
82 isa_ok($query_sf, 'Bio::SeqFeatureI');
83 is($query_sf->start(), 5);
84 is($query_sf->end(), 812);
85 is($query_sf->strand(), 0);