1 # -*-Perl-*- Test Harness script for Bioperl
11 -requires_module => 'Graph'
14 use_ok('Bio::OntologyIO');
15 use_ok('Bio::Ontology::RelationshipType');
18 my $IS_A = Bio::Ontology::RelationshipType->get_instance("IS_A");
19 my $PART_OF = Bio::Ontology::RelationshipType->get_instance("PART_OF");
21 my $parser = Bio::OntologyIO->new(
23 -file => test_input_file('sofa.ontology')
26 my $ont = $parser->next_ontology();
27 isa_ok( $ont, 'Bio::Ontology::Ontology' );
28 is( $ont->name, "Sequence Feature Ontology" );
30 my @roots = $ont->get_root_terms();
31 is( scalar(@roots), 1 );
32 is( $roots[0]->name(), "Sequence_Feature_Ontology" );
33 is( $roots[0]->identifier(), "SO:0000000" );
35 my @terms = $ont->get_child_terms( $roots[0] );
36 is( scalar(@terms), 1 );
37 is( $terms[0]->name(), "sofa" );
38 @terms = $ont->get_child_terms( $terms[0] );
39 is( scalar(@terms), 1 );
40 is( $terms[0]->name(), "feature" );
41 my $featterm = $terms[0];
42 @terms = $ont->get_child_terms($featterm);
43 is( scalar(@terms), 10 );
45 # oligonucleotide has two parents, see whether this is handled
46 @terms = $ont->get_descendant_terms($featterm);
47 my ($term) = grep { $_->name() eq "oligonucleotide"; } @terms;
51 # local $TODO = '$term->identifier()';
52 is( $term->identifier(), "SO:0000696" );
56 @terms = $ont->get_ancestor_terms($term);
57 is( scalar(@terms), 7 );
58 is( scalar( grep { $_->name() eq "remark"; } @terms ), 1 );
59 is( scalar( grep { $_->name() eq "reagent"; } @terms ), 1 );
61 # processed_transcript has part-of and is-a children
62 @terms = $ont->get_descendant_terms($featterm);
63 ($term) = grep { $_->name() eq "processed_transcript"; } @terms;
67 # local $TODO = '$term->identifier()';
68 is( $term->identifier(), "SO:0000233" );
72 @terms = $ont->get_child_terms($term);
73 is( scalar(@terms), 4 );
74 @terms = $ont->get_child_terms( $term, $PART_OF );
75 is( scalar(@terms), 2 );
76 @terms = $ont->get_child_terms( $term, $IS_A );
77 is( scalar(@terms), 2 );
78 @terms = $ont->get_child_terms( $term, $PART_OF, $IS_A );
79 is( scalar(@terms), 4 );
81 # now all descendants:
82 @terms = $ont->get_descendant_terms($term);
83 is( scalar(@terms), 13 );
84 @terms = $ont->get_descendant_terms( $term, $PART_OF );
85 is( scalar(@terms), 2 );
86 @terms = $ont->get_descendant_terms( $term, $IS_A );
87 is( scalar(@terms), 5 );
88 @terms = $ont->get_descendant_terms( $term, $PART_OF, $IS_A );
89 is( scalar(@terms), 13 );
91 # TF_binding_site has 2 parents and different relationships in the two
92 # paths up (although the relationships to its two parents are of the
93 # same type, namely is-a)
94 @terms = $ont->get_descendant_terms($featterm);
95 ($term) = grep { $_->name() eq "TF_binding_site"; } @terms;
99 # local $TODO = '$term->identifier()';
100 is( $term->identifier(), "SO:0000235" );
104 @terms = $ont->get_parent_terms($term);
105 is( scalar(@terms), 2 );
106 my ($pterm) = grep { $_->name eq "regulatory_region"; } @terms;
108 @terms = $ont->get_parent_terms( $term, $PART_OF );
109 is( scalar(@terms), 0 );
110 @terms = $ont->get_parent_terms( $term, $IS_A );
111 is( scalar(@terms), 2 );
112 @terms = $ont->get_parent_terms( $term, $PART_OF, $IS_A );
113 is( scalar(@terms), 2 );
116 @terms = $ont->get_ancestor_terms($term);
117 is( scalar(@terms), 6 );
118 @terms = $ont->get_ancestor_terms( $term, $PART_OF );
119 is( scalar(@terms), 0 );
120 @terms = $ont->get_ancestor_terms( $pterm, $PART_OF );
121 is( scalar(@terms), 1 );
122 @terms = $ont->get_ancestor_terms( $term, $IS_A );
123 is( scalar(@terms), 5 );
124 @terms = $ont->get_ancestor_terms( $pterm, $IS_A );
125 is( scalar(@terms), 0 );
126 @terms = $ont->get_ancestor_terms( $term, $PART_OF, $IS_A );
127 is( scalar(@terms), 6 );
129 # pull out all relationships
130 my @rels = $ont->get_relationships();
131 my @relset = grep { $_->object_term->name eq "sofa"; } @rels;
132 is( scalar(@relset), 1 );
133 @relset = grep { $_->subject_term->name eq "sofa"; } @rels;
134 is( scalar(@relset), 1 );
135 @relset = grep { $_->object_term->name eq "feature"; } @rels;
136 is( scalar(@relset), 10 );
137 @relset = grep { $_->subject_term->name eq "feature"; } @rels;
138 is( scalar(@relset), 1 );
139 @relset = grep { $_->object_term->identifier eq "SO:0000233"; } @rels;
140 is( scalar(@relset), 4 );
141 @relset = grep { $_->predicate_term->name eq "IS_A" } @relset;
142 is( scalar(@relset), 2 );
144 # relationships for a specific term only
145 ($term) = $ont->find_terms( -identifier => "SO:0000233" );
147 is( $term->identifier, "SO:0000233" );
148 is( $term->name, "processed_transcript" );
149 @rels = $ont->get_relationships($term);
150 is( scalar(@rels), 5 );
151 @relset = grep { $_->predicate_term->name eq "IS_A"; } @rels;
152 is( scalar(@relset), 3 );
153 @relset = grep { $_->object_term->identifier eq "SO:0000233"; } @rels;
154 is( scalar(@relset), 4 );
157 test_skip(-tests => 3, -requires_module => 'XML::Parser::PerlSAX');
158 for my $file (qw/interpro.xml interpro_sample.xml interpro_relationship.xml/) {
159 my $parser = Bio::OntologyIO->new(
160 -format => "interpro",
161 -file => test_input_file($file),
163 ok( $parser->next_ontology, "Interpro XML file $file can be parsed" );