1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 45,
11 -requires_module => 'Graph');
13 use_ok('Bio::OntologyIO');
14 use_ok('Bio::Ontology::RelationshipType');
17 my $IS_A = Bio::Ontology::RelationshipType->get_instance( "IS_A" );
18 my $PART_OF = Bio::Ontology::RelationshipType->get_instance( "PART_OF" );
20 my $parser = Bio::OntologyIO->new(
22 -file => test_input_file('so.obo'));
24 my $ont = $parser->next_ontology();
26 is ($ont->name(), "sequence");
28 my @roots = $ont->get_root_terms();
29 is (scalar(@roots), 1);
30 is ($roots[0]->name(), "Sequence_Ontology");
31 is ($roots[0]->identifier(), "SO:0000000");
33 my @terms = $ont->get_child_terms($roots[0]);
34 is (scalar(@terms), 5);
35 my ($term) = grep { $_->name() eq "variation_operation"; } @terms;
37 ($term) = grep { $_->name() eq "sequence_attribute"; } @terms;
39 ($term) = grep { $_->name() eq "consequences_of_mutation"; } @terms;
41 ($term) = grep { $_->name() eq "chromosome_variation"; } @terms;
43 ($term) = grep { $_->name() eq "located_sequence_feature"; } @terms;
46 @terms = $ont->get_child_terms($terms[0]);
47 is (scalar(@terms), 5);
48 ($term) = grep { $_->name() eq "translocate"; } @terms;
50 ($term) = grep { $_->name() eq "delete"; } @terms;
52 ($term) = grep { $_->name() eq "insert"; } @terms;
54 ($term) = grep { $_->name() eq "substitute"; } @terms;
56 ($term) = grep { $_->name() eq "invert"; } @terms;
59 my $featterm = $terms[0];
60 @terms = $ont->get_child_terms($featterm);
61 is (scalar(@terms), 2);
63 # substitution has two parents, see whether this is handled
64 @terms = $ont->find_terms(-name => "substitution");
66 is ($term->name(), "substitution");
68 # search using obo terms;
69 @terms = $ont->find_identically_named_terms($term);
71 @terms = $ont->find_identical_terms($term);
73 @terms = $ont->find_similar_terms($term);
76 @terms = $ont->get_ancestor_terms($term);
77 is (scalar(@terms), 6);
78 is (scalar(grep { $_->name() eq "region"; } @terms), 1);
79 is (scalar(grep { $_->name() eq "sequence_variant"; } @terms), 1);
81 # processed_transcript has part-of and is-a children
83 @terms = $ont->find_terms(-name => "processed_transcript");;
86 @terms = $ont->get_child_terms($term);
87 is (scalar(@terms), 5);
88 @terms = $ont->get_child_terms($term, $PART_OF);
89 is (scalar(@terms), 2);
90 @terms = $ont->get_child_terms($term, $IS_A);
91 is (scalar(@terms), 3);
92 @terms = $ont->get_child_terms($term, $PART_OF, $IS_A);
93 is (scalar(@terms), 5);
95 # TF_binding_site has 2 parents and different relationships in the two
96 # paths up (although the relationships to its two parents are of the
97 # same type, namely is-a)
98 @terms = $ont->find_terms(-name => "TF_binding_site");;
101 @terms = $ont->get_parent_terms($term);
102 is (scalar(@terms), 2);
103 my ($pterm) = grep { $_->name eq "regulatory_region"; } @terms;
105 @terms = $ont->get_parent_terms($term, $PART_OF);
106 is (scalar(@terms), 0);
107 @terms = $ont->get_parent_terms($term, $IS_A);
108 is (scalar(@terms), 2);
109 @terms = $ont->get_parent_terms($term, $PART_OF, $IS_A);
110 is (scalar(@terms), 2);
113 # pull out all relationships
114 my @rels = $ont->get_relationships();
115 my @relset = grep { $_->object_term->name eq "Sequence_Ontology"; } @rels;
116 is (scalar(@relset), 5);
117 @relset = grep { $_->subject_term->name eq "Sequence_Ontology"; } @rels;
118 is (scalar(@relset), 0);
120 # relationships for a specific term only
121 ($term) = $ont->find_terms(-identifier => "SO:0000082");
123 is ($term->identifier, "SO:0000082");
124 is ($term->name, "processed_transcript_attribute");
125 @rels = $ont->get_relationships($term);
126 is (scalar(@rels), 5);
127 @relset = grep { $_->predicate_term->name eq "IS_A"; } @rels;
128 is (scalar(@relset), 5);
129 @relset = grep { $_->object_term->identifier eq "SO:0000082"; } @rels;
130 is (scalar(@relset), 4);
131 @relset = grep { $_->subject_term->identifier eq "SO:0000082"; } @rels;
132 is (scalar(@relset), 1);