tag fourth (and hopefully last) alpha
[bioperl-live.git] / branch-1-6 / t / Tree / TreeIO / phyloxml.t
blob8dfa52cfcc1031bf693f98afbbee33be5c733df5
1 # -*-Perl-*- Test Harness script for Bioperl
3 use strict;
4 use warnings;
6 BEGIN {
7         use lib '.';
8         use Bio::Root::Test;
9   
10         test_begin(-tests => 97,
11                            -requires_modules => [qw(XML::LibXML XML::LibXML::Reader)]);
12         
13         use_ok('Bio::TreeIO');
16 my $verbose = test_debug();
18 SKIP: {
19   if (1000*$] < 5008) {
20     skip("Reader interface only supported in Perl >= 5.8",96);
21   } elsif (XML::LibXML::LIBXML_VERSION() <= 20620) {
22     skip("Reader not supported for libxml2 <= 2.6.20",96);
23   }
24   use_ok('Bio::TreeIO::phyloxml');
25   
26   if ($verbose) {
27         diag("libxml version: ", XML::LibXML::LIBXML_VERSION()); 
28   }
29   
30   ok my $treeio = Bio::TreeIO->new(
31                          -verbose => $verbose,
32                                    -format => 'phyloxml',
33                                    -file   => test_input_file('phyloxml_examples.xml'));
34   
35   # tree1: clade and attribute
36   # <phylogeny> <clade> <name>
37   {
38         if ($verbose > 0) {
39           diag("\ntree1: clade and attribute");
40         }
41         my $tree = $treeio->next_tree;
42         isa_ok($tree, 'Bio::Tree::TreeI');
43         is($tree->id, 'example from Prof. Joe Felsenstein\'s book "Inferring Phylogenies"');
44         is($tree->get_tag_values('description'), 'phyloXML allows to use either a "branch_length" attribute or element to indicate branch lengths.');
45         if ($verbose > 0) {
46           diag("tree id: ",$tree->id);
47           diag("tree description: ", $tree->get_tag_values('description'));
48         }
49         is($tree->get_tag_values('rooted'), 'true');
50         my @nodes = $tree->get_nodes;
51         is(@nodes, 5);
52         my ($A) = $tree->find_node('A');
53         ok($A);
54         is($A->branch_length, '0.102');
55         if ($verbose > 0) {
56           diag("node A: branch_length ", $A->branch_length);
57         }
58         is($A->ancestor->id, '');
59         is($A->ancestor->branch_length, '0.06');
60         my $leaves_string = $tree->simplify_to_leaves_string();
61         if ($verbose > 0) {
62           diag($leaves_string);
63         }
64         is($leaves_string, '((A,B),C)');
65   
66   # write_tree
67         if ($verbose > 0) {
68           diag("\ntest write_tree");
69         }
70         my $FILE1 = test_output_file();
71         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
72                 -format => 'phyloxml',
73                 -file   => ">$FILE1");
74         $treeio->write_tree($tree);
75         ok -s $FILE1;
76         if ($verbose > 0) {
77           diag(`cat $FILE1`);
78         }
79   }
80   
81   # tree2: branch_length
82   # <branch_length>
83   {
84         if ($verbose > 0) {
85           diag("\ntree2: branch_length");
86         }
87         my $tree = $treeio->next_tree;
88         isa_ok($tree, 'Bio::Tree::TreeI');
89         if ($verbose > 0) {
90           diag("tree id: ",$tree->id);
91         }
92         my @nodes = $tree->get_nodes;
93         is(@nodes, 5);
94         my $A = $tree->find_node('A');
95         ok($A);
96         is($A->branch_length, '0.102');
97         if ($verbose > 0) {
98           diag("node A: branch_length ", $A->branch_length);
99         }
100         is($A->ancestor->id, '');
101         is($A->ancestor->branch_length, '0.06');
102         my $leaves_string = $tree->simplify_to_leaves_string();
103         if ($verbose > 0) {
104           diag($leaves_string);
105         }
106         is($leaves_string, '((A,B),C)');
107   
108   # write_tree
109         if ($verbose > 0) {
110           diag("\ntest write_tree");
111         }
112         my $FILE1 = test_output_file();
113         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
114                 -format => 'phyloxml',
115                 -file   => ">$FILE1");
116         $treeio->write_tree($tree);
117         ok -s $FILE1;
118         if ($verbose > 0) {
119           diag(`cat $FILE1`);
120         }
121   }
122   
123   # tree3: confidence (bootstrap)
124   # <confidence>
125   {
126         if ($verbose > 0) {
127           diag("\ntree3: confidence (bootstrap)");
128         }
129         my $tree = $treeio->next_tree;
130         isa_ok($tree, 'Bio::Tree::TreeI');
131         if ($verbose > 0) {
132           diag("tree id: ",$tree->id);
133         }
134         my $AB = $tree->find_node('AB');
135         ok($AB);
136         is($AB->bootstrap, '89');
137         if ($verbose > 0) {
138           diag("node AB: bootstrap ", $AB->bootstrap);
139         }
140         my $leaves_string = $tree->simplify_to_leaves_string();
141         if ($verbose > 0) {
142           diag($leaves_string);
143         }
144         is($leaves_string, '((A,B),C)');
145   
146   # write_tree
147         if ($verbose > 0) {
148           diag("\ntest write_tree");
149         }
150         my $FILE1 = test_output_file();
151         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
152                 -format => 'phyloxml',
153                 -file   => ">$FILE1");
154         $treeio->write_tree($tree);
155         ok -s $FILE1;
156         if ($verbose > 0) {
157           diag(`cat $FILE1`);
158         }
159   }
160   
161   # tree4: species and sequence
162   # <taxonomy> <scientific_name> <sequence> <annotation>
163   {
164         if ($verbose > 0) {
165           diag("\ntree4: taxonomy and sequence");
166         }
167         my $tree = $treeio->next_tree;
168         isa_ok($tree, 'Bio::Tree::TreeI');
169         if ($verbose > 0) {
170           diag("tree id: ",$tree->id);
171         }
172         my $C = $tree->find_node('C');
173         my ($ac) = $C->annotation->get_Annotations('taxonomy');
174         isa_ok( $ac, 'Bio::Annotation::Collection');
175         my ($ac2) = $ac->get_Annotations('scientific_name');
176         isa_ok( $ac2, 'Bio::Annotation::Collection');
177         my ($scientificname) = $ac2->get_Annotations('_text');
178         is($scientificname->value, 'C. elegans');
179         if ($verbose > 0) {
180           diag( "Node C Scientific Name: ",$scientificname->value);
181         }
182         my ($ac3) = $C->annotation->get_nested_Annotations(-keys=>['scientific_name'], -recursive=>1);
183         isa_ok( $ac3, 'Bio::Annotation::Collection');
184         ($scientificname) = $ac2->get_Annotations('_text');
185         is($scientificname->value, 'C. elegans');
186         if ($verbose > 0) {
187           diag( "Node C Scientific Name: ",$scientificname->value);
188         }
189         my ($seq) = @{$C->sequence};
190         isa_ok( $seq, 'Bio::SeqI');
191         my ($seqac) = $seq->annotation;
192         isa_ok( $seqac, 'Bio::Annotation::Collection');
193         my ($descac) = $seqac->get_nested_Annotations(-keys=>['desc'], -recursive=>1);
194         my ($desc) = $descac->get_Annotations('_text');
195         is($desc->value, 'alcohol dehydrogenase');
196         if ($verbose > 0) {
197           diag( "Node C Sequence description: ",$desc->value);
198         }
199         ($descac) = $seqac->get_nested_Annotations(-keys=>['desc'], -recursive=>1);
200         
201   # write_tree
202         if ($verbose > 0) {
203           diag("\ntest write_tree");
204         }
205         my $FILE1 = test_output_file();
206         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
207                 -format => 'phyloxml',
208                 -file   => ">$FILE1");
209         $treeio->write_tree($tree);
210         ok -s $FILE1;
211         if ($verbose > 0) {
212           diag(`cat $FILE1`);
213         }
214   }
215   
216   # tree5: homolog relationship and sequence relationship
217   # <events> <speciations> <duplications> <symbol> <accession> 
218   # <sequence_relation> 
219   {
220         if ($verbose > 0) {
221           diag("\ntree5: events and relations");
222         }
223         my $tree = $treeio->next_tree;
224         isa_ok($tree, 'Bio::Tree::TreeI');
225         if ($verbose > 0) {
226           diag("tree id: ",$tree->id);
227         }
228         my $node = $tree->get_root_node;
229         my ($speciationsac) = $node->annotation->get_nested_Annotations(-keys=>['speciations'], -recursive=>1);
230         my ($speciationval) = $speciationsac->get_Annotations('_text');
231         is($speciationval->value, '1');
232         if ($verbose > 0) {
233           diag("root node speciation event: ", $speciationval->value);
234         }
235         my @children = ($node);
236         for (@children) {
237           push @children, $_->each_Descendent();
238         }
239         my @leaves = ();
240         for (@children) {
241           push @leaves, $_ if $_->is_Leaf;
242         }
243         my ($z) = $leaves[0];
244         my $z_seq = $z->sequence->[0];
245         isa_ok ($z_seq, 'Bio::SeqI');
246         my ($z_id) = $z_seq->annotation->get_nested_Annotations('-keys'=>['id_source'], '-recursive'=>1);
247         my ($z_id_text) = $z_id->value;
248         my @seq_rels = $z_seq->annotation->get_nested_Annotations('-keys'=>['sequence_relation'], '-recursive'=>1);
249         foreach my $rel (@seq_rels) {
250           isa_ok($rel, 'Bio::Annotation::Relation');
251           is ($rel->tagname, 'sequence_relation');
252           my $seqto = $rel->to;
253           isa_ok ($seqto, 'Bio::SeqI');
254           my ($seqto_id) = $seqto->annotation->get_nested_Annotations('-keys'=>['id_source'], '-recursive'=>1);
255           my $seqto_text = $seqto_id->value;
256           if ($verbose > 0) {
257                 diag( "node ", $z_id_text, " has ", $rel->type, " relation to ", $seqto_text);
258           }
259         }
260         my ($x) = $leaves[1];
261         
262   
263   # write_tree
264         if ($verbose > 0) {
265           diag("\ntest write_tree");
266         }
267         my $FILE1 = test_output_file();
268         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
269                 -format => 'phyloxml',
270                 -file   => ">$FILE1");
271         $treeio->write_tree($tree);
272         ok -s $FILE1;
273         if ($verbose > 0) {
274           diag(`cat $FILE1`);
275         }
276   }
277   
278   # tree6: detailed sequence data
279   # <mol_seq> <annotation> <code>
280   {
281         if ($verbose > 0) {
282           diag("\ntree6: detailed sequence annotation");
283         }
284         my $tree = $treeio->next_tree;
285         isa_ok($tree, 'Bio::Tree::TreeI');
286         if ($verbose > 0) {
287           diag("tree id: ",$tree->id);
288         }
289         my @children = ($tree->get_root_node);
290         for (@children) {
291           push @children, $_->each_Descendent();
292         }
293         my @leaves = ();
294         for (@children) {
295           push @leaves, $_ if $_->is_Leaf;
296         }
297         my ($z) = $leaves[0];
298         my $z_seq = $z->sequence->[0];
299         isa_ok ($z_seq, 'Bio::SeqI');
300         my ($z_seqname) = $z_seq->annotation->get_nested_Annotations('-keys'=>['name'], '-recursive'=>1); 
301         my ($z_seqname_text) = $z_seqname->get_Annotations('_text');
302         is ($z_seqname_text->value, 'NADH-dependent butanol dehydrogenase B');
303         my ($z_molseq) = $z_seq->seq;
304         is ($z_molseq, 'MVDFEYSIPTRIFFGKDKINVLGRELKKYGSKVLIVYGGGSIKRNGIYDK');
305         if ($verbose > 0) {
306           diag("Sequence ", $z_seqname_text->value, " is ", $z_molseq);
307         }
308         my ($z_seqname_text2) = $treeio->read_annotation('-obj'=>$z_seq, '-path'=>'name');
309         is ($z_seqname_text->value, $z_seqname_text2);
310   
311   # write_tree
312         if ($verbose > 0) {
313           diag("\ntest write_tree");
314         }
315         my $FILE1 = test_output_file();
316         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
317                 -format => 'phyloxml',
318                 -file   => ">$FILE1");
319         $treeio->write_tree($tree);
320         ok -s $FILE1;
321         if ($verbose > 0) {
322           diag(`cat $FILE1`);
323         }
324   }
325   
326   # tree7: network
327   # <clade_relation> @id_source & @id_ref
328   {
329         if ($verbose > 0) {
330           diag("\ntree7: network using id_source/id_ref");
331         }
332         my $tree = $treeio->next_tree;
333         isa_ok($tree, 'Bio::Tree::TreeI');
334         if ($verbose > 0) {
335           diag("tree id: ",$tree->id);
336         }
337         my @children = ($tree->get_root_node);
338         for (@children) {
339           push @children, $_->each_Descendent();
340         }
341         my @leaves = ();
342         for (@children) {
343           push @leaves, $_ if $_->is_Leaf;
344         }
345         my ($c) = $leaves[0];
346         my ($c_id) = $c->annotation->get_nested_Annotations('-keys'=>['id_source'], '-recursive'=>1);
347         my @clade_rels = $c->annotation->get_nested_Annotations('-keys'=>['clade_relation'], '-recursive'=>1);
348         foreach my $rel (@clade_rels) {
349           isa_ok($rel, 'Bio::Annotation::Relation');
350           is ($rel->tagname, 'clade_relation');
351           my $nodeto = $rel->to;
352           isa_ok ($nodeto, 'Bio::Tree::AnnotatableNode');
353           my ($nodeto_id) = $nodeto->annotation->get_nested_Annotations('-keys'=>['id_source'], '-recursive'=>1);
354           is ($nodeto_id->value, 'b');
355           my ($nodeto_id2) = $treeio->read_annotation('-obj'=>$nodeto, '-path'=>'id_source', '-attr'=>1);
356           is ($nodeto_id->value, $nodeto_id2);
357           if ($verbose > 0) {
358                 diag( "node ", $c_id->value, " has ", $rel->type, " relation to ", $nodeto_id->value);
359           }
360         }
361   
362   # write_tree
363         if ($verbose > 0) {
364           diag("\ntest write_tree");
365         }
366         my $FILE1 = test_output_file();
367         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
368                 -format => 'phyloxml',
369                 -file   => ">$FILE1");
370         $treeio->write_tree($tree);
371         ok -s $FILE1;
372         if ($verbose > 0) {
373           diag(`cat $FILE1`);
374         }
375   }
376   
377   # tree8: property elements
378   # <property>
379   {
380         if ($verbose > 0) {
381           diag("\ntree8: property");
382         }
383         my $tree = $treeio->next_tree;
384         isa_ok($tree, 'Bio::Tree::TreeI');
385         if ($verbose > 0) {
386           diag("tree id: ",$tree->id);
387         }
388         my ($A) = $tree->find_node('A');
389         isa_ok($A, 'Bio::Tree::AnnotatableNode');
390         my ($ac) = $A->annotation();
391         isa_ok($ac, 'Bio::AnnotationCollectionI');
392         my (@annotations) = $ac->get_Annotations('property');
393         isa_ok( $annotations[0], 'Bio::Annotation::Collection');
394         diag("property:",$annotations[0]) if $verbose;
395         my (@keys) = $annotations[0]->get_all_annotation_keys();
396         diag("keys:",@keys) if $verbose;
397         my (@value) = $annotations[0]->get_Annotations('_text');
398         is($value[0]->value, ' 1200 ');
399         if ($verbose > 0) {
400           diag( "Annotation NOAA:depth ",$value[0]->value);
401         }
402         my $leaves_string = $tree->simplify_to_leaves_string();
403         if ($verbose > 0) {
404           diag($leaves_string);
405         }
406         is($leaves_string, '((A,B),C)');
407   
408   # write_tree
409         if ($verbose > 0) {
410           diag("\ntest write_tree");
411         }
412         my $FILE1 = test_output_file();
413         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
414                 -format => 'phyloxml',
415                 -file   => ">$FILE1");
416         $treeio->write_tree($tree);
417         ok -s $FILE1;
418         if ($verbose > 0) {
419           diag(`cat $FILE1`);
420         }
421   }
422   
423   # tree9: property outside tree topology using id refs
424   # <property> @id_source @id_ref
425   {
426         if ($verbose > 0) {
427           diag("\ntree9: property using id_source/id_ref");
428         }
429         my $tree = $treeio->next_tree;
430         isa_ok($tree, 'Bio::Tree::TreeI');
431         if ($verbose > 0) {
432           diag("tree id: ",$tree->id);
433         }
434         my $A = $tree->find_node('A');
435         isa_ok($A, 'Bio::Tree::AnnotatableNode');
436         my $ac = $A->annotation();
437         isa_ok($ac, 'Bio::AnnotationCollectionI');
438         my @annotations = $ac->get_Annotations('property');
439         isa_ok( $annotations[0], 'Bio::Annotation::Collection');
440         my @value = $annotations[0]->get_Annotations('_text');
441         is($value[0]->value, ' 1200 ');
442         if ($verbose > 0) {
443           diag( "Annotation NOAA:depth ",$value[0]->value);
444         }
445         my $leaves_string = $tree->simplify_to_leaves_string();
446         if ($verbose > 0) {
447           diag($leaves_string);
448         }
449         is($leaves_string, '((A,B),C)');
450   
451   # write_tree
452         if ($verbose > 0) {
453           diag("\ntest write_tree");
454         }
455         my $FILE1 = test_output_file();
456         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
457                 -format => 'phyloxml',
458                 -file   => ">$FILE1");
459         $treeio->write_tree($tree);
460         ok -s $FILE1;
461         if ($verbose > 0) {
462           diag(`cat $FILE1`);
463         }
464   }
465   
466   # tree10: detailed taxonomy and distribution
467   # <id> <rank> <uri> <common_name> <distribution>
468   {
469         if ($verbose > 0) {
470           diag("\ntree10: taxonomy and distribution");
471         }
472         my $tree = $treeio->next_tree;
473         isa_ok($tree, 'Bio::Tree::TreeI');
474         if ($verbose > 0) {
475           diag("tree id: ",$tree->id);
476         }
477         my $node = $tree->get_root_node;
478         my @leaves;
479         my @children = ($node);
480         for (@children) {
481           push @children, $_->each_Descendent();
482         }
483         for (@children) {
484           push @leaves, $_ if $_->is_Leaf;
485         }
486         my ($A) = $leaves[0];
487         my ($scientificname) = $A->annotation->get_nested_Annotations('-keys'=>['scientific_name'], '-recursive'=>1);
488         my ($scientificname_text) = $scientificname->get_Annotations('_text');
489         my ($commonname) = $A->annotation->get_nested_Annotations('-keys'=>['common_name'], '-recursive'=>1); 
490         my ($commonname_text) = $commonname->get_Annotations('_text');
491         my ($rank) = $A->annotation->get_nested_Annotations('-keys'=>['rank'], '-recursive'=>1); 
492         my ($rank_text) = $rank->get_Annotations('_text');
493         if ($verbose > 0) {
494           diag("node rank is ", $rank_text->value);
495           diag("node scientific name is ", $scientificname_text->value);
496           diag("node common name is ", $commonname_text->value);
497         }
498         my ($distribution) = $A->annotation->get_nested_Annotations('-keys'=>['distribution'], '-recursive'=>1);
499         my ($desc) = $distribution->get_Annotations('desc');
500         my ($desc_text) = $desc->get_Annotations('_text');
501         if ($verbose > 0) {
502           diag("node distribution is ", $desc_text->value);
503         } 
504         
505   # write_tree
506         if ($verbose > 0) {
507           diag("\ntest write_tree");
508         }
509         my $FILE1 = test_output_file();
510         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
511                 -format => 'phyloxml',
512                 -file   => ">$FILE1");
513         $treeio->write_tree($tree);
514         ok -s $FILE1;
515         if ($verbose > 0) {
516           diag(`cat $FILE1`);
517         }
518   }
519   
520   # tree11: phylogeographic information
521   # <distribution> <point> <lat> <long> <alt>
522   {
523         if ($verbose > 0) {
524           diag("\ntree11: phylogenographic information");
525         }
526         my $tree = $treeio->next_tree;
527         isa_ok($tree, 'Bio::Tree::TreeI');
528         if ($verbose > 0) {
529           diag("tree id: ",$tree->id);
530         }
531         my $node = $tree->get_root_node;
532         my @leaves;
533         my @children = ($node);
534         for (@children) {
535           push @children, $_->each_Descendent();
536         }
537         for (@children) {
538           push @leaves, $_ if $_->is_Leaf;
539         }
540         my ($D) = $leaves[0];
541         my ($point) = $treeio->read_annotation('-obj'=>$D, '-path'=>'distribution/point/geodetic_datum', '-attr'=>1);
542         is ($point, 'WGS84');
543         my ($lat) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'distribution/point/lat');
544         my ($long) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'distribution/point/long');
545         my ($alt) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'distribution/point/alt');
546         is ($lat, '32.880933');
547         is ($long, '-117.217543');
548         is ($alt, '104');
549         if ($verbose > 0) {
550           diag("node distribution lat: $lat long $long alt $alt");
551         }
552         
553         
554   # write_tree
555         if ($verbose > 0) {
556           diag("\ntest write_tree");
557         }
558         my $FILE1 = test_output_file();
559         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
560                 -format => 'phyloxml',
561                 -file   => ">$FILE1");
562         $treeio->write_tree($tree);
563         ok -s $FILE1;
564         if ($verbose > 0) {
565           diag(`cat $FILE1`);
566         }
567   }
568   
569   # tree12: date information
570   # <date> <desc> <value>
571   {
572         if ($verbose > 0) {
573           diag("\ntree12: date");
574         }
575         my $tree = $treeio->next_tree;
576         isa_ok($tree, 'Bio::Tree::TreeI');
577         if ($verbose > 0) {
578           diag("tree id: ",$tree->id);
579         }
580         my $node = $tree->get_root_node;
581         my @leaves;
582         my @children = ($node);
583         for (@children) {
584           push @children, $_->each_Descendent();
585         }
586         for (@children) {
587           push @leaves, $_ if $_->is_Leaf;
588         }
589         my ($D) = $leaves[0];
590         my ($dateunit) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/unit', '-attr'=>1);
591         my ($daterange) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/range', '-attr'=>1);
592         my ($datevalue) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/value');
593         is ($dateunit, 'mya');
594         is ($daterange, '30');
595         is ($datevalue, '600');
596         if ($verbose > 0) {
597           diag("node date unit: $dateunit range $daterange value $datevalue");
598         }
599   
600   # write_tree
601         if ($verbose > 0) {
602           diag("\ntest write_tree");
603         }
604         my $FILE1 = test_output_file();
605         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
606                 -format => 'phyloxml',
607                 -file   => ">$FILE1");
608         $treeio->write_tree($tree);
609         ok -s $FILE1;
610         if ($verbose > 0) {
611           diag(`cat $FILE1`);
612         }
613   }
614   
615   # tree13: alignment outside <phylogeny>
616   # <align:alignment> <seq> 
617   {
618         if ($verbose > 0) {
619           diag("\ntree13: alignment outside  <phylogeny>");
620         }
621         my $tree = $treeio->next_tree;
622         isa_ok($tree, 'Bio::Tree::TreeI');
623         if ($verbose > 0) {
624           diag("tree id: ",$tree->id);
625         }
626         my $leaves_string = $tree->simplify_to_leaves_string();
627         if ($verbose > 0) {
628           diag($leaves_string);
629         }
630         is($leaves_string, '((A,B),C)');
631   
632   # add annotation in phyloxml
633         if ($verbose > 0) {
634           diag("test add annotation in phyloXML format");
635         }
636         my $node = $tree->get_root_node;
637         my @leaves;
638         my @children = ($node);
639         for (@children) {
640           push @children, $_->each_Descendent();
641         }
642         for (@children) {
643           push @leaves, $_ if $_->is_Leaf;
644         }
645         my ($D) = $leaves[0];
646         isa_ok($D, 'Bio::Tree::AnnotatableNode');
647         $treeio->add_phyloXML_annotation(
648                           -obj => $D, 
649                           -xml => "            <name>D</name>
650                           <date unit=\"mya\" range=\"30\">
651                                  <desc>my date</desc>
652                                  <value>veryveryold</value>
653                           </date>
654   "
655                           );
656         my ($dateunit) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/unit', '-attr'=>1);
657         my ($daterange) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/range', '-attr'=>1);
658         my ($datevalue) =  $treeio->read_annotation('-obj'=>$D, '-path'=>'date/value');
659         is ($dateunit, 'mya');
660         is ($daterange, '30');
661         is ($datevalue, 'veryveryold');
662   
663   # write_tree
664         if ($verbose > 0) {
665           diag("\ntest write_tree");
666         }
667         my $FILE1 = test_output_file();
668         my $treeio = Bio::TreeIO->new(-verbose => $verbose,
669                 -format => 'phyloxml',
670                 -file   => ">$FILE1");
671         $treeio->write_tree($tree);
672         ok -s $FILE1;
673         if ($verbose > 0) {
674           diag(`cat $FILE1`);
675         }
676   }
677   
678   
679   # convert between nhx-phyloxml
680   {
681         if ($verbose > 0) {
682           diag("\n test translation between nhx and phyloxml");
683         }
684         ok my $nhxio = Bio::TreeIO->new(
685                 -verbose => $verbose,
686                 -format => 'nhx',
687                 -file   => test_input_file('test.nhx'));
688         my $tree = $nhxio->next_tree;
689         isa_ok($tree, 'Bio::Tree::TreeI');
690         my $FILE1 = test_output_file();
691         my $phyloxmlio = Bio::TreeIO->new(-verbose => $verbose,
692                 -format => 'phyloxml',
693                 -file   => ">$FILE1");
694         $phyloxmlio->write_tree($tree);
695         ok -s $FILE1;
696         if ($verbose > 0) {
697           diag(`cat $FILE1`);
698         }
699   }
700