~ubuntu-branches/ubuntu/saucy/bioperl/saucy-proposed

« back to all changes in this revision

Viewing changes to t/Ontology/Ontology.t

  • Committer: Bazaar Package Importer
  • Author(s): Charles Plessy
  • Date: 2009-03-10 07:19:11 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090310071911-fukqzw54pyb1f0bd
Tags: 1.6.0-2
* Removed patch system (not used):
  - removed instuctions in debian/rules;
  - removed quilt from Build-Depends in debian/control.
* Re-enabled tests:
  - uncommented test command in debian/rules;
  - uncommented previously missing build-dependencies in debian/control.
  - Re-enabled tests and uncommented build-dependencies accordingly.
* Removed libmodule-build-perl and libtest-harness-perl from
  Build-Depends-Indep (provided by perl-modules).
* Better cleaning of empty directories using find -type d -empty -delete
  instead of rmdir in debian/rules (LP: #324001).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-Perl-*- Test Harness script for Bioperl
 
2
# $Id: Ontology.t 15112 2008-12-08 18:12:38Z sendu $
 
3
 
 
4
use strict;
 
5
 
 
6
BEGIN {
 
7
    use lib '.';
 
8
    use Bio::Root::Test;
 
9
    
 
10
    test_begin(-tests => 52,
 
11
                           -requires_module => 'Graph');
 
12
        
 
13
        use_ok('Bio::OntologyIO');
 
14
        use_ok('Bio::Ontology::RelationshipType');
 
15
}
 
16
 
 
17
my $IS_A    = Bio::Ontology::RelationshipType->get_instance( "IS_A" );
 
18
my $PART_OF = Bio::Ontology::RelationshipType->get_instance( "PART_OF" );
 
19
 
 
20
my $parser = Bio::OntologyIO->new(
 
21
                      -format    => "soflat",
 
22
                      -file      => test_input_file('sofa.ontology'));
 
23
 
 
24
my $ont = $parser->next_ontology();
 
25
ok ($ont);
 
26
is ($ont->name, "Sequence Feature Ontology");
 
27
 
 
28
my @roots = $ont->get_root_terms();
 
29
is (scalar(@roots), 1);
 
30
is ($roots[0]->name(), "Sequence_Feature_Ontology");
 
31
is ($roots[0]->identifier(), "SO:0000000");
 
32
 
 
33
my @terms = $ont->get_child_terms($roots[0]);
 
34
is (scalar(@terms), 1);
 
35
is ($terms[0]->name(), "sofa");
 
36
@terms = $ont->get_child_terms($terms[0]);
 
37
is (scalar(@terms), 1);
 
38
is ($terms[0]->name(), "feature");
 
39
my $featterm = $terms[0];
 
40
@terms = $ont->get_child_terms($featterm);
 
41
is (scalar(@terms), 10);
 
42
 
 
43
# oligonucleotide has two parents, see whether this is handled
 
44
@terms = $ont->get_descendant_terms($featterm);
 
45
my ($term) = grep { $_->name() eq "oligonucleotide"; } @terms;
 
46
ok $term;
 
47
#TODO: {
 
48
#       local $TODO = '$term->identifier()';
 
49
        is($term->identifier(), "SO:0000696");
 
50
#}
 
51
 
 
52
@terms = $ont->get_ancestor_terms($term);
 
53
is (scalar(@terms), 7);
 
54
is (scalar(grep { $_->name() eq "remark"; } @terms), 1);
 
55
is (scalar(grep { $_->name() eq "reagent"; } @terms), 1);
 
56
 
 
57
# processed_transcript has part-of and is-a children
 
58
@terms = $ont->get_descendant_terms($featterm);
 
59
($term) = grep { $_->name() eq "processed_transcript"; } @terms;
 
60
ok $term;
 
61
 
 
62
#TODO: {
 
63
#       local $TODO = '$term->identifier()';
 
64
        is($term->identifier(), "SO:0000233");
 
65
#}
 
66
 
 
67
@terms = $ont->get_child_terms($term);
 
68
is (scalar(@terms), 4);
 
69
@terms = $ont->get_child_terms($term, $PART_OF);
 
70
is (scalar(@terms), 2);
 
71
@terms = $ont->get_child_terms($term, $IS_A);
 
72
is (scalar(@terms), 2);
 
73
@terms = $ont->get_child_terms($term, $PART_OF, $IS_A);
 
74
is (scalar(@terms), 4);
 
75
 
 
76
# now all descendants:
 
77
@terms = $ont->get_descendant_terms($term);
 
78
is (scalar(@terms), 13);
 
79
@terms = $ont->get_descendant_terms($term, $PART_OF);
 
80
is (scalar(@terms), 2);
 
81
@terms = $ont->get_descendant_terms($term, $IS_A);
 
82
is (scalar(@terms), 5);
 
83
@terms = $ont->get_descendant_terms($term, $PART_OF, $IS_A);
 
84
is (scalar(@terms), 13);
 
85
 
 
86
# TF_binding_site has 2 parents and different relationships in the two
 
87
# paths up (although the relationships to its two parents are of the
 
88
# same type, namely is-a)
 
89
@terms = $ont->get_descendant_terms($featterm);
 
90
($term) = grep { $_->name() eq "TF_binding_site"; } @terms;
 
91
ok $term;
 
92
 
 
93
#TODO: {
 
94
#       local $TODO = '$term->identifier()';
 
95
        is($term->identifier(), "SO:0000235");
 
96
#}
 
97
 
 
98
@terms = $ont->get_parent_terms($term);
 
99
is (scalar(@terms), 2);
 
100
my ($pterm) = grep { $_->name eq "regulatory_region"; } @terms;
 
101
ok $pterm;
 
102
@terms = $ont->get_parent_terms($term, $PART_OF);
 
103
is (scalar(@terms), 0);
 
104
@terms = $ont->get_parent_terms($term, $IS_A);
 
105
is (scalar(@terms), 2);
 
106
@terms = $ont->get_parent_terms($term, $PART_OF, $IS_A);
 
107
is (scalar(@terms), 2);
 
108
 
 
109
# now all ancestors:
 
110
@terms = $ont->get_ancestor_terms($term);
 
111
is (scalar(@terms), 6);
 
112
@terms = $ont->get_ancestor_terms($term, $PART_OF);
 
113
is (scalar(@terms), 0);
 
114
@terms = $ont->get_ancestor_terms($pterm, $PART_OF);
 
115
is (scalar(@terms), 1);
 
116
@terms = $ont->get_ancestor_terms($term, $IS_A);
 
117
is (scalar(@terms), 5);
 
118
@terms = $ont->get_ancestor_terms($pterm, $IS_A);
 
119
is (scalar(@terms), 0);
 
120
@terms = $ont->get_ancestor_terms($term, $PART_OF, $IS_A);
 
121
is (scalar(@terms), 6);
 
122
 
 
123
# pull out all relationships
 
124
my @rels = $ont->get_relationships();
 
125
my @relset = grep { $_->object_term->name eq "sofa"; } @rels;
 
126
is (scalar(@relset), 1);
 
127
@relset = grep { $_->subject_term->name eq "sofa"; } @rels;
 
128
is (scalar(@relset), 1);
 
129
@relset = grep { $_->object_term->name eq "feature"; } @rels;
 
130
is (scalar(@relset), 10);
 
131
@relset = grep { $_->subject_term->name eq "feature"; } @rels;
 
132
is (scalar(@relset), 1);
 
133
@relset = grep { $_->object_term->identifier eq "SO:0000233"; } @rels;
 
134
is (scalar(@relset), 4);
 
135
@relset = grep { $_->predicate_term->name eq "IS_A" } @relset;
 
136
is (scalar(@relset), 2);
 
137
 
 
138
# relationships for a specific term only
 
139
($term) = $ont->find_terms(-identifier => "SO:0000233");
 
140
ok ($term);
 
141
is ($term->identifier, "SO:0000233");
 
142
is ($term->name, "processed_transcript");
 
143
@rels = $ont->get_relationships($term);
 
144
is (scalar(@rels), 5);
 
145
@relset = grep { $_->predicate_term->name eq "IS_A"; } @rels;
 
146
is (scalar(@relset), 3);
 
147
@relset = grep { $_->object_term->identifier eq "SO:0000233"; } @rels;
 
148
is (scalar(@relset), 4);