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