1# -*-Perl-*- Test Harness script for Bioperl
2# $Id: SearchIO.t 14995 2008-11-16 06:20:00Z cjfields $
3
4use strict;
5
6BEGIN {
7    use Bio::Root::Test;
8
9    test_begin(-tests => 166);
10
11	use_ok('Bio::SearchIO');
12    use_ok('Bio::Search::SearchUtils');
13}
14
15my ($searchio, $result,$iter,$hit,$hsp);
16
17# test blasttable output
18my @eqset = qw( c200-vs-yeast.BLASTN.m9);
19$searchio = Bio::SearchIO->new(-file => test_input_file('c200-vs-yeast.BLASTN'),
20			      -format => 'blast');
21$result = $searchio->next_result;
22isa_ok($result,'Bio::Search::Result::ResultI');
23my %ref = &Bio::Search::SearchUtils::result2hash($result);
24is( 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;
29my %tester = &Bio::Search::SearchUtils::result2hash($result);
30is( scalar keys %tester, 67);
31foreach my $key ( sort keys %ref ) {
32    is($tester{$key}, $ref{$key},$key);
33}
34
35# test WU-BLAST blasttable output
36$searchio = Bio::SearchIO->new(-file => test_input_file('test1.wublastp'),
37			      			   -format => 'blast');
38$result = $searchio->next_result;
39isa_ok($result,'Bio::Search::Result::ResultI');
40my %wuref = &Bio::Search::SearchUtils::result2hash($result);
41is( 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;
46my %wutester = &Bio::Search::SearchUtils::result2hash($result);
47is( scalar keys %wutester, 31);
48foreach my $key ( sort keys %ref ) {
49    is($wutester{$key}, $wuref{$key},$key);
50}
51
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'));
55
56while(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');
67    is($hsp->bits, 331);
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);
86}
87