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