1 # testing Bio::DB::Query::HIVQuery
2 # $Id: HIVQuery.t 232 2008-12-11 14:51:51Z maj $
10 -requires_modules => [qw(LWP::UserAgent
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');
22 my $tobj= new Bio::DB::Query::HIVQuery(-RUN_OPTION=>0);
25 isa_ok($tobj, 'Bio::DB::Query::HIVQuery');
28 isa_ok($tobj, 'Bio::Root::Root');
29 can_ok($tobj, qw( count ids query ));
33 get_annotations_by_ids
35 add_annotations_for_id
36 remove_annotations_for_ids
37 remove_annotations_for_id
71 ok($tobj->_map_db_uri, "_map_db_uri set in default object");
72 ok($tobj->_make_search_if_uri, "_make_search_if_uri set in default object");
73 ok($tobj->_search_uri, "_search_uri set in default object");
74 ok($tobj->_schema_file, "_schema_file set in default object");
75 ok(defined $tobj->_run_option, "_run_option set in default object");
76 ok($tobj->{_annotations}, "annotations container available");
78 # query syntax (no run)
80 $tobj->query(['coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any']);
81 is($tobj->_do_query(0), 0, 'query syntax check 1');
83 $tobj->query({'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F'], country=>'Any'});
84 is($tobj->_do_query(0), 0, 'query syntax check 2');
86 $tobj->query({'query'=>{'coreceptor'=>['CCR5 CXCR4','CXCR4'], subtype=>['D', 'F']}, 'annot'=> ['country']});
87 is($tobj->_do_query(0),0, 'query syntax check 3');
89 $tobj->query("('CCR5 CXCR4', 'CXCR4')[coreceptor] (D F)[subtype] {[country]}");
90 is($tobj->_do_query(0),0, 'query parser check');
94 $tobj->query( "(SI[phenotype] ('CCR5 CXCR4')[coreceptor] C[subtype] OR NSI[phenotype] D[subtype]) AND ZA[country]");
95 is($tobj->_do_query(0),0, 'multiquery parse check');
98 test_skip(-requires_module => 'HTML::Parser', -tests => 3);
99 no warnings; # HTML::Parser has an uninited value issue
100 use_ok('HTML::Parser');
102 # help test; just tests that file can be written and that tags are in matching
103 # pairs, with reasonable placement of <html> and </html>
104 my $hlpf = test_output_file();
107 my $h = HTML::Parser->new(empty_element_tags => 1,
108 start_h => [sub {$a++; (shift eq 'html') && ($a==1) && $html++;}, "tagname"],
109 end_h => [sub {$a--; (shift eq 'html') && ($a==0) && $html++;}, "tagname"] );
110 ok($tobj->help($hlpf), "help html to file");
114 open my $HP, '<', $hlpf or die "Could not read file '$hlpf': $!\n";
116 is_deeply([$a, $html], [0, 2], "help html parsed");
117 close $HP; # Always explicitly close filehandles
124 #pre-run query exceptions
127 $tobj->query( "narb[scroob]" );
128 throws_ok {$tobj->_do_query} qr/BadParameter/, "bad field exception check";
130 $tobj->query( "narb[phenotype]" );
131 throws_ok {$tobj->_do_query} qr/BadParameter/, "bad match data exception check";
133 $tobj->query( [ 'cd4_count' => "" ] );
134 throws_ok {$tobj->_do_query} qr/BadParameter/, "empty field not ok exception check";
136 $tobj->{_schema} = undef;
137 throws_ok {$tobj->_do_query} qr/SchemaNotInit/, "uninitialized schema exception check";
138 throws_ok {$tobj->count} qr/Query not yet run/, "query not run (level 1) warning check";
139 throws_ok {$tobj->get_annotations_by_id($tobj->ids)} qr/Requires query run/, "query not run (level 2) warning check";
145 test_skip(-tests => 10,
146 -requires_networking => 1);
147 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)};
150 skip("Network problems, skipping all", 10);
152 ok($tobj,"live query");
153 cmp_ok( $tobj->count, ">=", 12, "enough sequences returned");
154 # test query object handling of Bio::DB::HIV
155 my ($tdb, $seqio, $seq);
156 ok( $tdb = new Bio::DB::HIV, "create Bio::DB::HIV object");
157 eval {$seqio = $tdb->get_Stream_by_query($tobj)};
160 skip("Network problems, skipping all", 7);
162 ok($seqio, "get SeqIO stream from query");
163 # test HIVAnnotProcessor indirectly
164 ok($seq = $seqio->next_seq, "access sequence stream");
165 ok($seq->annotation->get_value('Virus'), "'Virus' annotation present");
166 like ($seq->annotation->get_value('Virus','phenotype'), qr/SI/, "'Virus' phenotype annotation present");
167 like ($seq->annotation->get_value('Virus', 'subtype'), qr/[CD]/, "'Virus' subtype annotation present");
168 ok($seq->accession_number, "GenBank accession available");
173 $tobj->query( "2BR02B[accession]" );
174 throws_ok {$tobj->_do_query(2)} qr/no sequences/i, "no sequences warning check";