A test to ensure Bio::PrimarySeqI->trunc() doesn't use clone() for a Bio::Seq::RichSe...
[bioperl-live.git] / t / Ontology / GOterm.t
blobd80b5bc66469463f3afc22a8264a5897c9f2adc4
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
5 use warnings;
7 BEGIN {
8     use lib '.';
9     use Bio::Root::Test;
10     
11     test_begin(-tests => 62,
12                -requires_module => 'Graph::Directed');
13         
14     use_ok('Bio::Ontology::GOterm');
15     use_ok('Bio::Ontology::Ontology');
16         use_ok('Bio::Annotation::DBLink');
19 my $obj = Bio::Ontology::GOterm->new();
21 # note that all *dblink* methods are now deprecated...
23 isa_ok( $obj,"Bio::Ontology::GOterm");
25 $obj->init();
27 like( $obj->to_string(), qr'-- GO id:' );
29 is( $obj->GO_id( "GO:0003947" ), "GO:0003947" );
30 is( $obj->GO_id(), "GO:0003947" );
33 is( $obj->get_dbxrefs(), 0 );
35 my @dblinks = (Bio::Annotation::DBLink->new(-primary_id => 'dAA'),
36                                  Bio::Annotation::DBLink->new(-primary_id => 'dAB'));
38 $obj->add_dbxref( -dbxrefs => \@dblinks );
39 is( scalar($obj->get_dbxrefs()), 2 );
40 my @df1 = $obj->get_dbxrefs();
41 is( $df1[ 0 ]->display_text, "dAA" );
42 is( $df1[ 1 ]->display_text, "dAB" );
43 is( $obj->get_dbxrefs(), 2 );
45 my @df2 = $obj->remove_dbxrefs();
46 is( $df2[ 0 ]->display_text, "dAA" );
47 is( $df2[ 1 ]->display_text, "dAB" );
49 is( $obj->get_dbxrefs(), 0 );
50 is( $obj->remove_dbxrefs(), 0 );
53 is( $obj->get_secondary_GO_ids(), 0 );
55 $obj->add_secondary_GO_id( ( "GO:0000000", "GO:1234567" ) );
56 is( scalar($obj->get_secondary_GO_ids()), 2 );
57 my @si1 = $obj->get_secondary_GO_ids();
58 is( $si1[ 0 ], "GO:0000000" );
59 is( $si1[ 1 ], "GO:1234567" );
60 is( $obj->get_secondary_GO_ids(), 2 );
62 my @si2 = $obj->remove_secondary_GO_ids();
63 is( $si2[ 0 ], "GO:0000000" );
64 is( $si2[ 1 ], "GO:1234567" );
66 is( $obj->get_secondary_GO_ids(), 0 );
67 is( $obj->remove_secondary_GO_ids(), 0 );
71 is( $obj->identifier( "0003947" ), "0003947" );
72 is( $obj->identifier(), "0003947" );
74 is( $obj->name( "N-acetylgalactosaminyltransferase" ), "N-acetylgalactosaminyltransferase" );
75 is( $obj->name(), "N-acetylgalactosaminyltransferase" );
77 is( $obj->definition( "Catalysis of ..." ), "Catalysis of ..." );
78 is( $obj->definition(), "Catalysis of ..." );
80 is( $obj->version( "666" ), "666" );
81 is( $obj->version(), "666" );
83 ok( $obj->ontology( "category 1 name" ) );
84 is( $obj->ontology()->name(), "category 1 name" );
86 my $ont = Bio::Ontology::Ontology->new();
87 ok( $ont->name( "category 2 name" ) );
89 ok( $obj->ontology( $ont ) );
90 is( $obj->ontology()->name(), "category 2 name" );
92 is( $obj->is_obsolete( 1 ), 1 );
93 is( $obj->is_obsolete(), 1 );
95 is( $obj->comment( "Consider the term ..." ), "Consider the term ..." );
96 is( $obj->comment(), "Consider the term ..." );
98 is( $obj->get_synonyms(), 0 );
100 $obj->add_synonym( ( "AA", "AB" ) );
101 my @al1 = $obj->get_synonyms();
102 is( scalar(@al1), 2 );
103 is( $al1[ 0 ], "AA" );
104 is( $al1[ 1 ], "AB" );
106 my @al2 = $obj->remove_synonyms();
107 is( $al2[ 0 ], "AA" );
108 is( $al2[ 1 ], "AB" );
110 is( $obj->get_synonyms(), 0 );
111 is( $obj->remove_synonyms(), 0 );
113 $obj->add_synonym( ( "AA", "AB" ) );
114 $obj->add_dbxref( -dbxrefs => \@dblinks );
115 $obj->add_secondary_GO_id( ( "GO:1234567", "GO:1234567" ) );
117 $obj->init();
118 is( $obj->identifier(), undef ); # don't make up identifiers
119 is( $obj->name(), undef );
120 is( $obj->definition(), undef );
121 is( $obj->is_obsolete(), 0 );
122 is( $obj->comment(), undef );
125 $obj = Bio::Ontology::GOterm->new( -go_id       => "0016847",
126                                    -name        => "1-aminocyclopropane-1-carboxylate synthase",
127                                    -definition  => "Catalysis of ...",
128                                    -is_obsolete => 0,
129                                    -version     => "6.6.6",
130                                    -ontology    => "cat",
131                                    -comment     => "X" );  
133 is( $obj->identifier(), "GO:0016847" );
134 is( $obj->name(), "1-aminocyclopropane-1-carboxylate synthase" );
135 is( $obj->definition(), "Catalysis of ..." );
136 is( $obj->is_obsolete(), 0 );
137 is( $obj->comment(), "X" );
138 is( $obj->version(), "6.6.6" );
139 is( $obj->ontology()->name(), "cat" );