1
# testing Bio::DB::Query::HIVQuery
2
# $Id: HIVQuery.t 232 2008-12-11 14:51:51Z maj $
11
-requires_modules => [qw( XML::Simple )]
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
23
my $tobj= new Bio::DB::Query::HIVQuery(-RUN_OPTION=>0);
26
isa_ok($tobj, 'Bio::DB::Query::HIVQuery');
29
isa_ok($tobj, 'Bio::Root::Root');
30
can_ok($tobj, qw( count ids query ));
34
get_annotations_by_ids
36
add_annotations_for_id
37
remove_annotations_for_ids
38
remove_annotations_for_id
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");
79
# query syntax (no run)
81
$tobj->query(['coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any']);
82
is($tobj->_do_query(0), 0, 'query syntax check 1');
84
$tobj->query({'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any'});
85
is($tobj->_do_query(0), 0, 'query syntax check 2');
87
$tobj->query({'query'=>{'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F']}, 'annot'=> ['country']});
88
is($tobj->_do_query(0),0, 'query syntax check 3');
90
$tobj->query("('CCR5 CXCR4', 'CXCR4')[coreceptor] (D F)[subtype] {[country]}");
91
is($tobj->_do_query(0),0, 'query parser check');
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');
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();
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");
113
is_deeply([$a, $html], [0, 2], "help html parsed");
120
#pre-run query exceptions
123
$tobj->query( "narb[scroob]" );
124
throws_ok {$tobj->_do_query} qr/BadParameter/, "bad field exception check";
126
$tobj->query( "narb[phenotype]" );
127
throws_ok {$tobj->_do_query} qr/BadParameter/, "bad match data exception check";
129
$tobj->query( [ 'cd4_count' => "" ] );
130
throws_ok {$tobj->_do_query} qr/BadParameter/, "empty field not ok exception check";
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";
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)};
146
skip("Network problems, skipping all", 10);
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)};
156
skip("Network problems, skipping all", 7);
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");
169
$tobj->query( "2BR02B[accession]" );
170
throws_ok {$tobj->_do_query(2)} qr/no sequences/i, "no sequences warning check";