1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 69,
11 -requires_modules => [qw(XML::Parser::PerlSAX
14 use_ok('Bio::OntologyIO');
18 my $ipp = Bio::OntologyIO->new( -format => 'interpro',
19 -file => test_input_file('interpro_short.xml'),
20 -ontology_engine => 'simple' );
21 isa_ok ($ipp, 'Bio::OntologyIO::InterProParser');
24 while(my $ont = $ipp->next_ontology) {
25 # there should be only one ontology
29 # we grep for defined values because we don't want a list of undefined values to be pass any test
30 my @leaves = $ip->get_leaf_terms;
31 ok( ( grep { defined } map { $_->get_dbxrefs } @leaves), 'get_dbxrefs on leaf terms is non-empty');
32 ok( ( grep { defined } map { $_->get_dbxrefs('member_list') } @leaves), 'get_dbxrefs(member_list) on leaf terms is non-empty');
33 ok( ( grep { defined } map { $_->get_dbxrefs('sec_list') } @leaves), 'get_dbxrefs(sec_list) on leaf terms is non-empty');
34 ok( ( grep { defined } map { $_->get_dbxrefs('class_list') } @leaves), 'get_dbxrefs(class_list) on leaf terms is non-empty');
35 ok( ( grep { defined } map { $_->get_dbxrefs('pub_list') } @leaves), 'get_dbxrefs(pub_list) on leaf terms is non-empty');
36 ok( ( grep { defined } map { $_->get_dbxrefs('example_list') } @leaves), 'get_dbxrefs(example_list) on leaf terms is non-empty');
37 ok( ( grep { defined } map { $_->get_dbxrefs('external_doc_list') } @leaves), 'get_dbxrefs(external_doc_list) on leaf terms is non-empty');
39 ok( ( grep { defined } map { $_->get_members } @leaves), 'get_members on leaf terms is non-empty');
40 ok( ( grep { defined } map { $_->class_list } @leaves), 'class_list on leaf terms is non-empty');
41 ok( ( grep { defined } map { $_->get_examples } @leaves), 'get_examples on leaf terms is non-empty');
42 ok( ( grep { defined } map { $_->get_external_documents } @leaves), 'get_external_documents on leaf terms is non-empty');
43 ok( ( grep { defined } map { $_->get_references } @leaves), 'get_references on leaf terms is non-empty');
44 ok( ( grep { defined } map { $_->protein_count } @leaves), 'protein_count on leaf terms is non-empty');
46 # this could greatly be improved (note: @leaves elements currently come in random order)
47 like( $leaves[0]->to_string, qr/-- InterPro id:/, 'to_string looks reasonable');
49 # there should be 8 root terms: InterPro Domain, InterPro Family,
50 # InterPro Repeat, and InterPro PTM (Post Translational Modification),
51 # Active_site, Binding_site, Conserved_site and Region
53 my @rt = sort { $a->name cmp $b->name; } $ip->get_root_terms();
54 is (scalar(@rt), 8, 'There are 8 root InterPro terms');
56 # every InterPro term should have an ontology,
57 foreach my $term ($ip->get_leaf_terms, @rt) {
58 isa_ok ($term->ontology, 'Bio::Ontology::Ontology');
59 is ($term->ontology->name, "InterPro", "term ".$term->name." in ontology InterPro");
62 # there are 10 fully instantiated InterPro terms in total, which should be returned as the leafs
63 is (scalar($ip->get_leaf_terms), 10);
64 # roots and leafs together:
65 is (scalar($ip->get_all_terms), 15);
67 # descendants and children (synonymous here because of depth 1)
68 # note that the sort should have placed Domain first and Family second
69 is (scalar($ip->get_descendant_terms($rt[3])), 4); # 4 InterPro Domains
70 is (scalar($ip->get_child_terms($rt[3])), 4); # dto.
71 is (scalar($ip->get_descendant_terms($rt[4])), 3); # 3 Interpro Family
72 is (scalar($ip->get_child_terms($rt[4])), 3); # dto.
74 # test for ancestors and parents (synonymous here because of depth 1)
75 foreach my $t ($ip->get_leaf_terms) {
76 # every InterPro term has exactly one parent - namely either
77 # Domain, Region, Family, Repeat, or PTM(Post Transl. Modification)
79 if (not ( $t->identifier eq "Repeat" or $t->identifier eq "PTM"
80 or $t->identifier eq "Region" or $t->identifier =~ '_site' )
82 is (scalar($ip->get_parent_terms($t)), 1, $t->name . " term has one parent");
83 is (scalar($ip->get_ancestor_terms($t)), 1, $t->name . " term has one ancestor");
87 # test for secondary accession map
88 is(scalar(keys %{$ipp->secondary_accessions_map}), 2, 'secondary accession map has 2 keys');