2 # testing HIVQueryHelper.pm and lanl-schema.xml indirectly
3 # $Id: HIVQueryHelper.t 231 2008-12-11 14:32:00Z maj $
12 -requires_modules => [qw( Bio::Root::Root XML::Simple)]
14 use_ok('Bio::DB::HIV::HIVQueryHelper');
18 # lanl-schema.xml characteristics as of 1/23/18
19 my ($naliases, $nfields, $ntables) = (166, 100, 14);
22 isa_ok(new HIVSchema(), "HIVSchema");
23 isa_ok($Q = new QRY(), "QRY");
24 isa_ok($r = new R(), "R");
25 isa_ok($q = new Q(), "Q");
29 ok( $tobj = new HIVSchema(Bio::Root::IO->catfile(qw(Bio DB HIV lanl-schema.xml))), "schema load");
54 # lanl-schema.xml tests
55 is( scalar $tobj->fields, $nfields, "fields complete");
56 is( scalar $tobj->tables, $ntables, "tables complete");
57 is( scalar $tobj->aliases, $naliases, "aliases complete");
58 my ($tbl, $fld, $col, $als);
59 ok( ($fld) = grep /sequenceentry.se_sequence/, $tobj->fields, "test field present");
60 ok( $tbl = $tobj->tablepart($fld), "test field syntax ok");
61 ok( $col = $tobj->columnpart($fld), "test field syntax ok");
62 ok( $als = $tobj->aliases($fld), "test alias by field name");
63 is( $tobj->primarykey($tbl), 'sequenceentry.se_id', "correct primary key for SequenceEntry");
64 is( scalar $tobj->foreignkey('author'), 2, "correct number of foreign keys for AUthor");
65 is( $tobj->foreigntable(($tobj->foreignkey('author'))[1]), 'publication', "correct foreign table for au_pub_id");
66 is_deeply( {$tobj->ankh('seq_sample.ssam_second_receptor')},
67 {'seq_sample.ssam_second_receptor' => {'ankey'=>'coreceptor','antype'=>'Virus'}}, "correct annotation key hash");
98 ok($Q->isnull, "null QRY");
99 ok($r->isnull, "null R (request object)");
100 ok($q->isnull, "null Q (atomic query object)");
103 ok($R1 = new R( new Q('X', 'a b c') ), "R obj create and init (1)");
104 ok($R2 = new R( new Q('X', 'a'), new Q('Y', 'u v w') ), "R obj create and init (2)");
105 ok(R::In($R2, $R1), "R::In");
106 ok(!R::In($R1, $R2), "!R::In");
107 ok(R::Eq($R1, $R1->clone), "R::Eq");
109 ok($Q1 = new QRY( $R1 ), "QRY obj create and init (1)");
110 ok($Q2 = new QRY( $R2 ), "QRY obj create and init (2)");
111 ok($Q3 = new QRY( new R( new Q('X', 'a'), new Q('Y', 'w v u'))), "QRY obj create and init (3)");
113 ok(QRY::Eq($Q1 | $Q1, $Q1), "QRY overload |");
114 ok(QRY::Eq($Q1 & $Q1,$Q1), "QRY overload &");
115 ok(QRY::Eq($Q1 & $Q2, $Q3), "QRY nontrivial &");
117 # parse and make query tests
120 ok($pt=QRY::_parse_q("('odds bodkins', a)[X] m[Y] u[Z] OR 'b'[X] {A B [C] [D]}"), "parse: ('odds bodkins', a)[X] m[Y] u[Z] OR 'b'[X] {A B [C] [D]} ");
121 is(scalar QRY::_make_q($pt), 2, "make: 2 queries returned");
122 is_deeply((QRY::_make_q($pt))[0]->{annot}, ['A','B','C','D'], "{annotation fields} parsed correctly");
123 ok($pt=QRY::_parse_q("('odds bodkins', a)[X] m[Y] u[Z] AND b[X] {A B [C] [D]}"), "parse: ('odds bodkins', a)[X] m[Y] u[Z] AND b[X] {A B [C] [D]} ");
124 is_deeply((QRY::_make_q($pt))[0],{}, "above query is null");