2 ## Bioperl Test Harness Script for Modules
5 # Before `make install' is performed this script should be runnable with
6 # `make test'. After `make install' it should work as `perl test.t'
9 use vars qw($HAVEGRAPHDIRECTED $DEBUG $NUMTESTS);
10 $DEBUG = $ENV{'BIOPERLDEBUG'} || 0;
13 eval { require Test::More; };
18 plan tests => ($NUMTESTS = 108);
19 use_ok('Bio::Annotation::Collection');
20 use_ok('Bio::Annotation::DBLink');
21 use_ok('Bio::Annotation::Comment');
22 use_ok('Bio::Annotation::Reference');
23 use_ok('Bio::Annotation::SimpleValue');
24 use_ok('Bio::Annotation::Target');
25 use_ok('Bio::Annotation::AnnotationFactory');
26 use_ok('Bio::Annotation::StructuredValue');
27 use_ok('Bio::Annotation::Tree');
29 use_ok('Bio::SeqFeature::Generic');
30 use_ok('Bio::SimpleAlign');
31 use_ok('Bio::Cluster::UniGene');
36 my $simple = Bio::Annotation::SimpleValue->new(
41 isa_ok($simple, 'Bio::AnnotationI');
44 is $simple->tagname, 'colour';
46 is $simple->value(0), 0;
52 my $link1 = new Bio::Annotation::DBLink(-database => 'TSC',
53 -primary_id => 'TSC0000030'
55 isa_ok($link1,'Bio::AnnotationI');
56 is $link1->database(), 'TSC';
57 is $link1->primary_id(), 'TSC0000030';
58 is $link1->as_text, 'Direct database link to TSC0000030 in database TSC';
59 my $ac = Bio::Annotation::Collection->new();
60 isa_ok($ac,'Bio::AnnotationCollectionI');
62 $ac->add_Annotation('dblink',$link1);
63 $ac->add_Annotation('dblink',
64 Bio::Annotation::DBLink->new(-database => 'TSC',
65 -primary_id => 'HUM_FABV'));
67 my $comment = Bio::Annotation::Comment->new( '-text' => 'sometext');
68 is $comment->text, 'sometext';
69 is $comment->as_text, 'Comment: sometext';
70 $ac->add_Annotation('comment', $comment);
74 my $target = new Bio::Annotation::Target(-target_id => 'F321966.1',
79 isa_ok($target,'Bio::AnnotationI');
80 ok $ac->add_Annotation('target', $target);
83 my $ref = Bio::Annotation::Reference->new( '-authors' => 'author line',
84 '-title' => 'title line',
85 '-location'=> 'location line',
87 isa_ok($ref,'Bio::AnnotationI');
88 is $ref->authors, 'author line';
89 is $ref->title, 'title line';
90 is $ref->location, 'location line';
92 is $ref->database, 'MEDLINE';
93 is $ref->as_text, 'Reference: title line';
94 $ac->add_Annotation('reference', $ref);
98 foreach my $link ( $ac->get_Annotations('dblink') ) {
99 is $link->database, 'TSC';
100 is $link->tagname(), 'dblink';
106 my @keys = $ac->get_all_annotation_keys();
107 is (scalar(@keys), 4);
108 foreach my $ann ( $ac->get_Annotations() ) {
109 shift(@keys) if ($n > 0) && ($ann->tagname ne $keys[0]);
110 is $ann->tagname(), $keys[0];
115 $ac->add_Annotation($link1);
118 foreach my $link ( $ac->get_Annotations('dblink') ) {
119 is $link->tagname(), 'dblink';
124 # annotation of structured simple values (like swissprot''is GN line)
125 my $ann = Bio::Annotation::StructuredValue->new();
126 isa_ok($ann, "Bio::AnnotationI");
128 $ann->add_value([-1], "val1");
129 is ($ann->value(), "val1");
130 $ann->value("compat test");
131 is ($ann->value(), "compat test");
132 $ann->add_value([-1], "val2");
133 is ($ann->value(-joins => [" AND "]), "compat test AND val2");
134 $ann->add_value([0], "val1");
135 is ($ann->value(-joins => [" AND "]), "val1 AND val2");
136 $ann->add_value([-1,-1], "val3", "val4");
137 $ann->add_value([-1,-1], "val5", "val6");
138 $ann->add_value([-1,-1], "val7");
139 is ($ann->value(-joins => [" AND "]), "val1 AND val2 AND (val3 AND val4) AND (val5 AND val6) AND val7");
140 is ($ann->value(-joins => [" AND ", " OR "]), "val1 AND val2 AND (val3 OR val4) AND (val5 OR val6) AND val7");
143 foreach ($ann->get_all_values()) {
148 my $nested_ac = Bio::Annotation::Collection->new();
149 $nested_ac->add_Annotation('nested', $ac);
151 is (scalar($nested_ac->get_Annotations()), 1);
152 ($ac) = $nested_ac->get_Annotations();
153 isa_ok($ac, "Bio::AnnotationCollectionI");
154 is (scalar($nested_ac->get_all_Annotations()), 6);
155 $nested_ac->add_Annotation('gene names', $ann);
156 is (scalar($nested_ac->get_Annotations()), 2);
157 is (scalar($nested_ac->get_all_Annotations()), 7);
158 is (scalar($nested_ac->get_Annotations('dblink')), 0);
159 my @anns = $nested_ac->get_Annotations('gene names');
160 isa_ok($anns[0], "Bio::Annotation::StructuredValue");
161 @anns = map { $_->get_Annotations('dblink');
162 } $nested_ac->get_Annotations('nested');
163 is (scalar(@anns), 3);
164 is (scalar($nested_ac->flatten_Annotations()), 2);
165 is (scalar($nested_ac->get_Annotations()), 7);
166 is (scalar($nested_ac->get_all_Annotations()), 7);
169 eval {require Graph::Directed;
170 require Bio::Annotation::OntologyTerm; };
171 skip('Graph::Directed not installed cannot test'.
172 ' Bio::Annotation::OntologyTerm module',6) if $@;
173 # OntologyTerm annotation
174 my $termann = Bio::Annotation::OntologyTerm->new(-label => 'test case',
175 -identifier => 'Ann:00001',
176 -ontology => 'dumpster');
177 isa_ok($termann->term,'Bio::Ontology::Term');
178 is ($termann->term->name, 'test case');
179 is ($termann->term->identifier, 'Ann:00001');
180 is ($termann->tagname, 'dumpster');
181 is ($termann->ontology->name, 'dumpster');
182 is ($termann->as_text, "dumpster|test case|");
186 my $seq = Bio::Seq->new();
187 isa_ok($seq,"Bio::AnnotatableI");
188 my $fea = Bio::SeqFeature::Generic->new();
189 isa_ok($fea, "Bio::AnnotatableI");
190 my $clu = Bio::Cluster::UniGene->new();
191 isa_ok($clu, "Bio::AnnotatableI");
192 my $aln = Bio::SimpleAlign->new();
193 isa_ok($clu,"Bio::AnnotatableI");
195 # tests for Bio::Annotation::AnnotationFactory
197 my $factory = Bio::Annotation::AnnotationFactory->new;
198 isa_ok($factory, 'Bio::Factory::ObjectFactoryI');
200 # defaults to SimpleValue
201 $ann = $factory->create_object(-value => 'peroxisome',
202 -tagname => 'cellular component');
203 like(ref $ann, qr(Bio::Annotation::SimpleValue));
205 $factory->type('Bio::Annotation::OntologyTerm');
207 $ann = $factory->create_object(-name => 'peroxisome',
208 -tagname => 'cellular component');
210 like(ref($ann), qr(Bio::Annotation::OntologyTerm));
213 skip("TODO: Create Annotation::Comment based on parameter only",2);
214 ok $ann = $factory->create_object(-text => 'this is a comment');
215 like(ref $ann, qr(Bio::Annotation::Comment));
218 ok $factory->type('Bio::Annotation::Comment');
219 ok $ann = $factory->create_object(-text => 'this is a comment');
220 like(ref $ann, qr(Bio::Annotation::Comment));
223 # factory guessing the type: Comment
224 $factory = new Bio::Annotation::AnnotationFactory();
225 ok $ann = $factory->create_object(-text => 'this is a comment');
226 like(ref $ann, qr(Bio::Annotation::Comment));
228 # factory guessing the type: Target
229 $factory = new Bio::Annotation::AnnotationFactory();
230 ok $ann = $factory->create_object(-target_id => 'F1234', -start => 1, -end => 10);
231 like(ref $ann, qr(Bio::Annotation::Target));
233 # factory guessing the type: OntologyTerm
234 $factory = new Bio::Annotation::AnnotationFactory();
235 ok(defined ($ann = $factory->create_object(-name => 'peroxisome',
236 -tagname => 'cellular component')));
237 like(ref $ann, qr(Bio::Annotation::OntologyTerm));
240 my $tree_filename = Bio::Root::IO->catfile("t","data","longnames.dnd");
241 my $tree=Bio::TreeIO->new(-file=>$tree_filename)->next_tree();
242 my $ann_tree = Bio::Annotation::Tree->new(
247 isa_ok($ann_tree, 'Bio::AnnotationI');
248 $ann_tree->tree_id('test');
249 is $ann_tree->tree_id(), 'test', "tree_id()";
250 $ann_tree->tagname('tree');
251 is $ann_tree->tagname(), 'tree', "tagname()";
252 my $aln_filename = Bio::Root::IO->catfile("t","data","longnames.aln");
254 $aln = Bio::AlignIO->new(-file=>$aln_filename, -format=>'clustalw')->next_aln();
255 isa_ok($aln, 'Bio::AnnotatableI');
256 $ac = Bio::Annotation::Collection->new();
257 $ac->add_Annotation('tree',$ann_tree);
258 $aln->annotation($ac);
259 foreach my $treeblock ( $aln->annotation->get_Annotations('tree') ) {
260 my $treeref=$treeblock->tree();
261 my @nodes = sort { defined $a->id &&
263 $a->id cmp $b->id } $treeref->get_nodes();
264 is $nodes[12]->id, '183.m01790', "add tree to AlignI";
266 foreach my $seq ($aln->each_seq_with_id($nodes[12]->id)) { $str=$seq->subseq(1,20)}
267 is $str, "MDDKELEIPVEHSTAFGQLV", "get seq from node id";