1# -*-Perl-*- Test Harness script for Bioperl
2# $Id: WABA.t 11525 2007-06-27 10:16:38Z sendu $
3
4use strict;
5
6BEGIN {
7    use Bio::Root::Test;
8
9    test_begin(-tests => 64);
10
11    use_ok('Bio::SearchIO');
12}
13
14my $wabain = Bio::SearchIO->new(
15    -format => 'waba',
16    -file   => test_input_file('test.waba')
17);
18
19isa_ok($wabain, 'Bio::SearchIO') ;
20
21# These won't look the same as the WABA file because Jim's code is 0 based
22# while we (bioperl) are 1 based.
23my @results = (
24    [
25        'U57623',
26        'pair1_hs.fa',
27        'pair1_mm.fa',
28        [
29            'U02884',
30            3,
31            [qw(3833 34 2972 1 243 3688 1 40.9)],
32            [qw(4211 3022 6914 1 3705 6848 1 43.7)],
33            [qw(2218 7004 9171 1 6892 8712 1 50.3)],
34        ],
35    ],
36    [
37        'X57152', 'pair9_hs.fa',
38        'pair9_mm.fa', [ 'X80685', 1, [qw(7572 4 5845 1 632 7368 1 46.8)], ],
39    ]
40);
41
42while ( my $wabar = $wabain->next_result ) {
43    my @r = @{ shift @results };
44    is( $wabar->query_name,     shift @r, 'query_name'     );
45    is( $wabar->query_database, shift @r, 'query database' );
46    is( $wabar->database_name,  shift @r, 'database name'  );
47
48    while ( my $wabah = $wabar->next_hit ) {
49        my (@h) = @{ shift @r };
50        is( $wabah->name, shift @h, 'name' );
51        is( $wabah->hsps(), shift @h, 'hsps' );
52
53        while ( my $wabahsp = $wabah->next_hsp ) {
54            my (@hsp) = @{ shift @h };
55            is( $wabahsp->length('total'),        shift @hsp , 'total length');
56            is( $wabahsp->query->start,           shift @hsp , 'start'       );
57            is( $wabahsp->query->end,             shift @hsp , 'end'         );
58            is( $wabahsp->strand('query'),        shift @hsp , 'strand'      );
59            is( $wabahsp->start('hit'),           shift @hsp , 'start'       );
60            is( $wabahsp->end('subject'),         shift @hsp , 'end'         );
61            is( $wabahsp->subject->strand,        shift @hsp, 'strand'       );
62            is( length( $wabahsp->query_string ), $wabahsp->length('total') , 'query string');
63            is( length( $wabahsp->hit_string ),   $wabahsp->length('total') , 'hit_string'  );
64            is( length( $wabahsp->hmmstate_string ),
65                $wabahsp->length('total') , 'hmmstate string');
66            my $hs = $wabahsp->hit_string;
67            is( $wabahsp->gaps('hit'), $hs =~ tr/\-// );
68            my $qs = $wabahsp->query_string;
69            is( $wabahsp->gaps('query'), $qs =~ tr/\-// );
70            is( sprintf( "%.1f", $wabahsp->percent_identity ), shift @hsp );
71        }
72    }
73}
74