~ubuntu-branches/ubuntu/trusty/bioperl/trusty-proposed

« back to all changes in this revision

Viewing changes to t/RemoteDB/HIV/HIVQuery.t

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# testing Bio::DB::Query::HIVQuery
 
2
# $Id: HIVQuery.t 232 2008-12-11 14:51:51Z maj $
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
BEGIN {
 
7
    use Bio::Root::Test;
 
8
 
 
9
    test_begin(
 
10
        -tests => 41,
 
11
        -requires_modules => [qw( XML::Simple )]
 
12
        );
 
13
    use_ok('Bio::DB::Query::HIVQuery');
 
14
    use_ok('Bio::DB::HIV');
 
15
    use_ok( 'Bio::Annotation::Collection' );
 
16
    use_ok( 'Bio::Annotation::Comment' );
 
17
    use_ok( 'Bio::Annotation::Reference' );
 
18
    use_ok( 'Bio::DB::HIV::HIVQueryHelper' );
 
19
    #use_ok( 'HTML::Parser' ); # this is for the test of the help function below
 
20
                              # not necessary for module
 
21
}
 
22
 
 
23
my $tobj= new Bio::DB::Query::HIVQuery(-RUN_OPTION=>0);
 
24
 
 
25
#object tests
 
26
isa_ok($tobj, 'Bio::DB::Query::HIVQuery');
 
27
 
 
28
#compliance tests
 
29
isa_ok($tobj, 'Bio::Root::Root');
 
30
can_ok($tobj, qw( count ids query ));
 
31
 
 
32
#methods
 
33
can_ok($tobj, qw( 
 
34
                  get_annotations_by_ids 
 
35
                  get_annotations_by_id 
 
36
                  add_annotations_for_id 
 
37
                  remove_annotations_for_ids
 
38
                  remove_annotations_for_id
 
39
                  remove_annotations
 
40
                  get_accessions
 
41
                  get_accessions_by_ids
 
42
                  get_accessions_by_id
 
43
                  )
 
44
    );
 
45
#internals
 
46
can_ok($tobj, qw(
 
47
                  _do_query
 
48
                  _reset
 
49
                  _session_id
 
50
                  _run_option
 
51
                  add_id
 
52
                  lanl_base
 
53
                  map_db
 
54
                  make_search_if
 
55
                  search_
 
56
                  _map_db_uri
 
57
                  _make_search_if_uri
 
58
                  _search_uri
 
59
                  _schema_file
 
60
                  _schema
 
61
                  _lanl_query
 
62
                  _lanl_response
 
63
                  _create_lanl_query
 
64
                  _do_lanl_request
 
65
                  _parse_lanl_response
 
66
                  _parse_query_string
 
67
                  _sorry 
 
68
                 )
 
69
    );
 
70
 
 
71
#defaults tests
 
72
ok($tobj->_map_db_uri, "_map_db_uri set in default object");
 
73
ok($tobj->_make_search_if_uri, "_make_search_if_uri set in default object");
 
74
ok($tobj->_search_uri, "_search_uri set in default object");
 
75
ok($tobj->_schema_file, "_schema_file set in default object");
 
76
ok(defined $tobj->_run_option, "_run_option set in default object");
 
77
ok($tobj->{_annotations}, "annotations container available");
 
78
 
 
79
# query syntax (no run)
 
80
$tobj->_reset;
 
81
$tobj->query(['coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any']);
 
82
is($tobj->_do_query(0), 0, 'query syntax check 1');
 
83
$tobj->_reset;
 
84
$tobj->query({'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any'});
 
85
is($tobj->_do_query(0), 0, 'query syntax check 2');
 
86
$tobj->_reset;
 
87
$tobj->query({'query'=>{'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F']}, 'annot'=> ['country']});
 
88
is($tobj->_do_query(0),0, 'query syntax check 3');
 
89
$tobj->_reset;
 
90
$tobj->query("('CCR5 CXCR4', 'CXCR4')[coreceptor] (D F)[subtype] {[country]}");
 
91
is($tobj->_do_query(0),0, 'query parser check');
 
92
 
 
93
#multiquery parse
 
94
$tobj->_reset;
 
95
$tobj->query( "(SI[phenotype] ('CCR5 CXCR4')[coreceptor] C[subtype] OR NSI[phenotype] D[subtype]) AND ZA[country]");
 
96
is($tobj->_do_query(0),0, 'multiquery parse check');
 
97
 
 
98
SKIP: {
 
99
        test_skip(-requires_module => 'HTML::Parser', -tests => 3);
 
100
        use_ok('HTML::Parser');
 
101
        # help test; just tests that file can be written and that tags are in matching 
 
102
        # pairs, with reasonable placement of <html> and </html>
 
103
        my $hlpf = test_output_file();
 
104
        my $a = 0;
 
105
        my $html = 0;
 
106
        my $h = HTML::Parser->new( empty_element_tags=>1, start_h => [sub {$a++; (shift eq 'html') && ($a==1) && $html++}, "tagname"], end_h => [sub {$a--; (shift eq 'html') && ($a==0) && $html++;}, "tagname"] );
 
107
        ok($tobj->help($hlpf), "help html to file");
 
108
        {
 
109
                local $/;
 
110
                undef $/;
 
111
                open HP, $hlpf;
 
112
                $h->parse(<HP>);
 
113
                is_deeply([$a, $html], [0, 2], "help html parsed");
 
114
                1;
 
115
        }
 
116
 
 
117
}
 
118
 
 
119
#exceptions tests
 
120
#pre-run query exceptions
 
121
$tobj->verbose(2);
 
122
$tobj->_reset;
 
123
$tobj->query( "narb[scroob]" );
 
124
throws_ok {$tobj->_do_query} qr/BadParameter/, "bad field exception check";
 
125
$tobj->_reset;
 
126
$tobj->query( "narb[phenotype]" );
 
127
throws_ok {$tobj->_do_query} qr/BadParameter/, "bad match data exception check";
 
128
$tobj->_reset;
 
129
$tobj->query( [ 'cd4_count'  => "" ] );
 
130
throws_ok {$tobj->_do_query} qr/BadParameter/, "empty field not ok exception check";
 
131
$tobj->_reset;
 
132
$tobj->{_schema} = undef;
 
133
throws_ok {$tobj->_do_query} qr/SchemaNotInit/, "uninitialized schema exception check";
 
134
throws_ok {$tobj->count} qr/Query not yet run/, "query not run (level 1) warning check";
 
135
throws_ok {$tobj->get_annotations_by_id($tobj->ids)} qr/Requires query run/, "query not run (level 2) warning check";
 
136
 
 
137
 
 
138
 
 
139
# network tests
 
140
SKIP : {
 
141
    test_skip(-tests => 10,
 
142
          -requires_networking => 1);
 
143
    eval {$tobj  = Bio::DB::Query::HIVQuery->new(-QUERY=>"(SI[phenotype] ('CCR5 CXCR4')[coreceptor] C[subtype] OR NSI[phenotype] D[subtype]) AND ZA[country]",-RUN_OPTION=>2)};
 
144
    if ($@) {
 
145
        diag($@);
 
146
        skip("Network problems, skipping all", 10);
 
147
    }
 
148
    ok($tobj,"live query");
 
149
    cmp_ok( $tobj->count, ">=", 12, "enough sequences returned");
 
150
# test query object handling of Bio::DB::HIV   
 
151
    my ($tdb, $seqio, $seq);
 
152
    ok( $tdb = new Bio::DB::HIV, "create Bio::DB::HIV object");
 
153
        eval {$seqio = $tdb->get_Stream_by_query($tobj)};
 
154
    if ($@) {
 
155
        diag($@);
 
156
        skip("Network problems, skipping all", 7);
 
157
    }   
 
158
    ok($seqio, "get SeqIO stream from query");
 
159
# test HIVAnnotProcessor indirectly
 
160
    ok($seq = $seqio->next_seq, "access sequence stream");
 
161
    ok($seq->annotation->get_value('Virus'), "'Virus' annotation present");
 
162
    like ($seq->annotation->get_value('Virus','phenotype'), qr/SI/, "'Virus' phenotype annotation present");
 
163
    like ($seq->annotation->get_value('Virus', 'subtype'), qr/[CD]/, "'Virus' subtype annotation present");
 
164
    ok($seq->accession_number, "GenBank accession available");
 
165
 
 
166
# exception checks
 
167
    $tobj->_reset;
 
168
    $tobj->verbose(2);
 
169
    $tobj->query( "2BR02B[accession]" );
 
170
    throws_ok {$tobj->_do_query(2)} qr/no sequences/i, "no sequences warning check";
 
171
}