File: Term.t

package info (click to toggle)
bioperl 1.4-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 20,336 kB
  • ctags: 8,476
  • sloc: perl: 119,890; xml: 6,001; lisp: 121; makefile: 57
file content (128 lines) | stat: -rw-r--r-- 3,774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*-Perl-*-
## Bioperl Test Harness Script for Modules
## $Id: Term.t,v 1.9 2003/12/22 08:50:35 juguang Exp $

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.t'

use strict;
BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    if( $@ ) {
        use lib 't';
    }
    use Test;
    plan tests => 51;
}

use Bio::Ontology::Term;
use Bio::Ontology::TermFactory;
use Bio::Annotation::DBLink;
use Bio::Annotation::Reference;

my $obj = Bio::Ontology::Term->new();

ok( $obj->isa( "Bio::Ontology::TermI" ) );

ok( $obj->identifier( "0003947" ), "0003947" );
ok( $obj->identifier(), "0003947" );

ok( $obj->name( "N-acetylgalactosaminyltransferase" ), "N-acetylgalactosaminyltransferase" );
ok( $obj->name(), "N-acetylgalactosaminyltransferase" );

ok( $obj->definition( "Catalysis of ..." ), "Catalysis of ..." );
ok( $obj->definition(), "Catalysis of ..." );

ok( $obj->version( "666" ), "666" );
ok( $obj->version(), "666" );

ok( $obj->ontology( "category 1 name" ) );
ok( $obj->ontology()->name(), "category 1 name" );

my $ont = Bio::Ontology::Ontology->new();
ok( $ont->name( "category 2 name" ) );

ok( $obj->ontology( $ont ) );
ok( $obj->ontology()->name(), "category 2 name" );

ok( $obj->is_obsolete( 1 ), 1 );
ok( $obj->is_obsolete(), 1 );

ok( $obj->comment( "Consider the term ..." ), "Consider the term ..." );
ok( $obj->comment(), "Consider the term ..." );

ok( $obj->get_synonyms(), 0 );

$obj->add_synonym( ( "AA", "AB" ) );
my @al1 = $obj->get_synonyms();
ok( scalar(@al1), 2 );
ok( $al1[ 0 ], "AA" );
ok( $al1[ 1 ], "AB" );

my @al2 = $obj->remove_synonyms();
ok( $al2[ 0 ], "AA" );
ok( $al2[ 1 ], "AB" );

ok( $obj->get_synonyms(), 0 );
ok( $obj->remove_synonyms(), 0 );

$obj->add_synonyms( ( "AA", "AB" ) );

ok( $obj->identifier(undef), undef );
ok( $obj->name(undef), undef );
ok( $obj->definition(undef), undef );
ok( $obj->is_obsolete(0), 0 );
ok( $obj->comment(undef), undef );


$obj = Bio::Ontology::Term->new( 
    -identifier  => "0016847",
    -name        => "1-aminocyclopropane-1-carboxylate synthase",
    -definition  => "Catalysis of ...",
    -is_obsolete => 0,
    -version     => "6.6.6",
    -ontology    => "cat",
    -comment     => "X",
    -dblinks    => [
        Bio::Annotation::DBLink->new(-database => 'db1'),
        Bio::Annotation::DBLink->new(-database => 'db2')
    ],
    -references => []
);  

ok( $obj->identifier(), "0016847" );
ok( $obj->name(), "1-aminocyclopropane-1-carboxylate synthase" );
ok( $obj->definition(), "Catalysis of ..." );
ok( $obj->is_obsolete(), 0);
ok( $obj->comment(), "X" );
ok( $obj->version(), "6.6.6" );
ok( $obj->ontology()->name(), "cat" );
ok( scalar($obj->get_dblinks), 2);
ok( scalar($obj->get_references), 0);

# test object factory for terms
my $fact = Bio::Ontology::TermFactory->new();
$obj = $fact->create_object(-name => "some ontology term");
ok $obj->isa("Bio::Ontology::TermI");
ok ($obj->name, "some ontology term");

$fact->type("Bio::Ontology::GOterm");
$obj = $fact->create_object(-name => "some ontology term",
			    -identifier => "GO:987654");
ok $obj->isa("Bio::Ontology::TermI");
ok (ref($obj), "Bio::Ontology::GOterm");
ok ($obj->name, "some ontology term");
ok ($obj->identifier, "GO:987654");

$fact->type("Bio::Annotation::OntologyTerm");
$obj = $fact->create_object(-name => "some ontology term",
			    -identifier => "GO:987654",
			    -ontology => "nonsense");
ok $obj->isa("Bio::Ontology::TermI");
ok $obj->isa("Bio::AnnotationI");
ok ($obj->name, "some ontology term");
ok ($obj->identifier, "GO:987654");
ok ($obj->tagname, "nonsense");