1# -*-Perl-*- Test Harness script for Bioperl
2# $Id: gmap_f9.t 14995 2008-11-16 06:20:00Z cjfields $
3
4use strict;
5use warnings;
6BEGIN {
7    use Bio::Root::Test;
8
9    test_begin(-tests => 54);
10
11    use_ok('Bio::SearchIO');
12}
13
14my $searchio =
15    Bio::SearchIO->new(-format => 'gmap_f9',
16               -file   => test_input_file('gmap_f9.txt'));
17
18my $result = $searchio->next_result;
19isa_ok($result, 'Bio::Search::Result::GenericResult', 'Did we get a Result?');
20is($result->num_hits(), 1, 'Did we get the expected number of hits?');
21is($result->algorithm(), 'gmap', 'Did we get the expected algorithm?');
22is($result->query_name(), 'NM_004448', 'Did we get the expected query_name?');
23
24my $hit = $result->next_hit;
25isa_ok($hit, 'Bio::Search::Hit::GenericHit', 'Did we get a Hit?');
26_check_hit($hit, {name => '17',
27          length => 4624,
28          num_hsps => 27,
29          query_length => 4623
30         } );
31
32my $hsp = $hit->next_hsp;
33_check_hsp($hsp, {algorithm => 'GMAP',
34          query_gaps => 1,
35          hit_gaps => 0,
36          query_length => 310,
37          hit_length => 311,
38          qseq => 'GGAGGAGGTGGAGGAGGAGG', # first 20 bases
39          hseq => 'GGAGGAGGTGGAGGAGGAGG', # ditto
40          query => {start => 1,
41                end => 310,
42                strand => 1},
43          hit => {start => 35109780,
44              end =>  35110090,
45              strand => 1},
46          homology_string => 'GGAGGAGGTGGAGGAGGAGG',
47          seq_inds_query_gap => [(61)]
48         } );
49
50my $searchio_rev =
51    Bio::SearchIO->new(-format => 'gmap_f9',
52               -file   => test_input_file('gmap_f9-reverse-strand.txt'));
53my $result_rev = $searchio_rev->next_result;
54isa_ok($result_rev,
55       'Bio::Search::Result::GenericResult', 'Did we get a Result?');
56is($result_rev->num_hits(), 1, 'Did we get the expected number of hits?');
57is($result_rev->algorithm(), 'gmap', 'Did we get the expected algorithm?');
58is($result_rev->query_name(),
59   'NM_004448', 'Did we get the expected query_name?');
60
61$hit = $result_rev->next_hit;
62_check_hit($hit, {name => '17',
63          length => 4624,
64          num_hsps => 27,
65          query_length => 4623
66         } );
67
68$hsp = $hit->next_hsp;
69_check_hsp($hsp, {algorithm => 'GMAP',
70          query_gaps => 0,
71          hit_gaps => 0,
72          query_length => 974,
73          hit_length => 974,
74          qseq => 'TAGCTGTTTTCCAAAATATA', # first 20 bases
75          hseq => 'TAGCTGTTTTCCAAAATATA', # ditto
76          query => {start => 1,
77                end => 974,
78                strand => 1},
79          hit => {start => 35137468,
80              end =>  35138441,
81              strand => -1},
82          homology_string => 'TAGCTGTTTTCCAAAATATA',
83          seq_inds_query_gap => [()]
84         } );
85
86
87$searchio =  Bio::SearchIO->new(-format => 'gmap_f9',
88                -file   => test_input_file('gmap_f9-multiple_results.txt'));
89
90my $result_count = 0;
91while (my $result = $searchio->next_result) {
92    $result_count++;
93}
94
95is($result_count, 58, "Can we loop over multiple results properly (expecting 58)?");
96
97# bug 3021
98
99$searchio =  Bio::SearchIO->new(-format => 'gmap_f9',
100                -file   => test_input_file('bug3021.gmap'));
101
102$result = $searchio->next_result;
103
104is($result->query_name, 'NM_004448', 'simple query_name now caught, bug 3021');
105
106exit(0);
107
108sub _check_hit {
109    my ($hit, $info) = @_;
110
111    isa_ok($hit, 'Bio::Search::Hit::HitI');
112    is($hit->name, $info->{name}, 'Check the name');
113    is($hit->length, $info->{length}, 'Check the hit length');
114    is($hit->num_hsps, $info->{num_hsps}, 'Check the number of hsps');
115    is($hit->query_length, $info->{query_length}, 'Check the query length');
116
117}
118
119sub _check_hsp {
120    my($hsp, $info) = @_;
121    isa_ok($hsp, 'Bio::Search::HSP::HSPI');
122    is($hsp->algorithm, $info->{algorithm}, 'Check the algorithm');
123    is($hsp->gaps('query'), $info->{query_gaps}, 'Count gaps in the query');
124    is($hsp->gaps('hit'), $info->{hit_gaps}, 'Count gaps in the hit');
125    is($hsp->length('query'), $info->{query_length}, 'Length of the query');
126    is($hsp->length('hit'), $info->{hit_length}, 'Length of the hit');
127    is(substr($hsp->query_string, 0, 20), $info->{qseq}, 'Query sequence');
128    is(substr($hsp->hit_string, 0, 20), $info->{hseq}, 'Hit sequence');
129    is($hsp->query->start, $info->{query}->{start}, "Check query start");
130    is($hsp->query->end, $info->{query}->{end}, "Check query end");
131    is($hsp->query->strand, $info->{query}->{strand}, "Check query end");
132    is(substr($hsp->homology_string, 0, 20), $info->{homology_string}, 'Check the homology string');
133    is_deeply([$hsp->seq_inds('query', 'gap')], $info->{seq_inds_query_gap}, 'Check seq_inds');
134    is($hsp->hit->start, $info->{hit}->{start}, "Check hit start");
135    is($hsp->hit->end, $info->{hit}->{end}, "Check hit end");
136    is($hsp->hit->strand, $info->{hit}->{strand}, "Check hit end");
137}
138