1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 76);
11 use_ok('Bio::TreeIO');
14 my $verbose = test_debug();
16 ok my $treeio = Bio::TreeIO->new(-verbose => $verbose,
18 -file => test_input_file('cysprot1b.newick'));
20 my $tree = $treeio->next_tree;
21 isa_ok($tree, 'Bio::Tree::TreeI');
23 my @nodes = $tree->get_nodes;
25 my ($rat) = $tree->find_node('CATL_RAT');
27 is($rat->branch_length, '0.12788');
28 # move the id to the bootstap
29 is($rat->ancestor->bootstrap($rat->ancestor->id), '95');
30 $rat->ancestor->id('');
31 # maybe this can be auto-detected, but then can't distinguish
32 # between internal node labels and bootstraps...
33 is($rat->ancestor->bootstrap, '95');
34 is($rat->ancestor->branch_length, '0.18794');
35 is($rat->ancestor->id, '');
38 foreach my $node ( $tree->get_root_node()->each_Descendent() ) {
39 print "node: ", $node->to_string(), "\n";
40 my @ch = $node->each_Descendent();
42 print "\tchildren are: \n";
43 foreach my $node ( $node->each_Descendent() ) {
44 print "\t\t ", $node->to_string(), "\n";
50 my $FILE1 = test_output_file();
51 $treeio = Bio::TreeIO->new(-verbose => $verbose,
54 $treeio->write_tree($tree);
57 $treeio = Bio::TreeIO->new(-verbose => $verbose,
59 -file => test_input_file('LOAD_Ccd1.dnd'));
61 $tree = $treeio->next_tree;
63 isa_ok($tree,'Bio::Tree::TreeI');
65 @nodes = $tree->get_nodes;
69 foreach my $node ( @nodes ) {
70 print "node: ", $node->to_string(), "\n";
71 my @ch = $node->each_Descendent();
73 print "\tchildren are: \n";
74 foreach my $node ( $node->each_Descendent() ) {
75 print "\t\t ", $node->to_string(), "\n";
81 is($tree->total_branch_length, 7.12148);
82 my $FILE2 = test_output_file();
83 $treeio = Bio::TreeIO->new(-verbose => $verbose,
86 $treeio->write_tree($tree);
89 $treeio = Bio::TreeIO->new(-verbose => $verbose,
91 -file => test_input_file('hs_fugu.newick'));
92 $tree = $treeio->next_tree();
93 @nodes = $tree->get_nodes();
95 # no relable order for the bottom nodes because they have no branchlen
96 my @vals = qw(SINFRUP0000006110);
98 foreach my $node ( $tree->get_root_node()->each_Descendent() ) {
99 foreach my $v ( @vals ) {
100 if( defined $node->id &&
101 $node->id eq $v ){ $saw = 1; last; }
105 is($saw, 1, "Saw $vals[0] as expected");
107 foreach my $node ( @nodes ) {
108 print "\t", $node->id, "\n" if $node->id;
112 $treeio = Bio::TreeIO->new(-format => 'newick',
114 my $treeout = Bio::TreeIO->new(-format => 'tabtree');
115 my $treeout2 = Bio::TreeIO->new(-format => 'newick');
117 $tree = $treeio->next_tree;
120 $treeout->write_tree($tree);
121 $treeout2->write_tree($tree);
124 $treeio = Bio::TreeIO->new(-verbose => $verbose,
125 -file => test_input_file('test.nhx'));
129 $tree = $treeio->next_tree;
131 isa_ok($tree, 'Bio::Tree::TreeI');
133 @nodes = $tree->get_nodes;
134 is(@nodes, 12, "Total Nodes");
136 my $adhy = $tree->find_node('ADHY');
137 is($adhy->branch_length, 0.1);
138 is(($adhy->get_tag_values('S'))[0], 'nematode');
139 is(($adhy->get_tag_values('E'))[0], '1.1.1.1');
141 # try lintree parsing
142 $treeio = Bio::TreeIO->new(-format => 'lintree',
143 -file => test_input_file('crab.njb'));
146 while( $tree = $treeio->next_tree ) {
148 isa_ok($tree, 'Bio::Tree::TreeI');
150 @nodes = $tree->get_nodes;
152 @leaves = $tree->get_leaf_nodes;
154 #/maj is(@nodes, 25);
155 is(@nodes, 24); # this is clear from the datafile and counting \maj
156 ($node) = $tree->find_node(-id => '18');
159 is($node->branch_length, '0.030579');
160 is($node->bootstrap, 998);
163 $treeio = Bio::TreeIO->new(-format => 'lintree',
164 -file => test_input_file('crab.nj'));
166 $tree = $treeio->next_tree;
168 isa_ok($tree, 'Bio::Tree::TreeI');
170 @nodes = $tree->get_nodes;
171 @leaves = $tree->get_leaf_nodes;
173 #/maj is(@nodes, 25);
174 is(@nodes, 24); #/maj
175 ($node) = $tree->find_node('18');
177 is($node->branch_length, '0.028117');
179 ($node) = $tree->find_node(-id => 'C-vittat');
180 is($node->id, 'C-vittat');
181 is($node->branch_length, '0.087619');
182 is($node->ancestor->id, '14');
184 $treeio = Bio::TreeIO->new(-format => 'lintree',
185 -file => test_input_file('crab.dat.cn'));
187 $tree = $treeio->next_tree;
189 isa_ok($tree, 'Bio::Tree::TreeI');
191 @nodes = $tree->get_nodes;
192 @leaves = $tree->get_leaf_nodes;
193 is(@leaves, 13, "Leaf nodes");
195 #/maj is(@nodes, 25, "All nodes");
196 is(@nodes, 24, "All nodes");
197 ($node) = $tree->find_node('18');
200 is($node->branch_length, '0.029044');
202 ($node) = $tree->find_node(-id => 'C-vittat');
203 is($node->id, 'C-vittat');
204 is($node->branch_length, '0.097855');
205 is($node->ancestor->id, '14');
208 test_skip(-tests => 8, -requires_module => 'IO::String');
210 # test nexus tree parsing
211 $treeio = Bio::TreeIO->new(-format => 'nexus',
212 -verbose => $verbose,
213 -file => test_input_file('urease.tre.nexus'));
215 $tree = $treeio->next_tree;
217 is($tree->id, 'PAUP_1');
218 is($tree->get_leaf_nodes, 6);
219 ($node) = $tree->find_node(-id => 'Spombe');
220 is($node->branch_length,0.221404);
222 # test nexus MrBayes tree parsing
223 $treeio = Bio::TreeIO->new(-format => 'nexus',
224 -file => test_input_file('adh.mb_tree.nexus'));
226 $tree = $treeio->next_tree;
229 is($tree->id, 'rep.1');
230 is($tree->get_leaf_nodes, 54);
231 ($node) = $tree->find_node(-id => 'd.madeirensis');
232 is($node->branch_length,0.039223);
233 while ($tree = $treeio->next_tree) {
236 is($ct,13,'bug 2356');
240 # process no-newlined tree
241 $treeio = Bio::TreeIO->new(-format => 'nexus',
242 -verbose => $verbose,
243 -file => test_input_file('tree_nonewline.nexus'));
245 $tree = $treeio->next_tree;
247 ok($tree->find_node('TRXHomo'));
250 # parse trees with scores
252 $treeio = Bio::TreeIO->new(-format => 'newick',
253 -file => test_input_file('puzzle.tre'));
254 $tree = $treeio->next_tree;
256 is($tree->score, '-2673.059726');
259 # process trees with node IDs containing spaces
260 $treeio = Bio::TreeIO->new(-format => 'nexus',
261 -verbose => $verbose,
262 -file => test_input_file('spaces.nex'));
264 $tree = $treeio->next_tree;
266 my @nodeids = ("'Allium drummondii'", "'Allium cernuum'",'A.cyaneum');
269 for my $node ($tree->get_leaf_nodes) {
270 is($node->id, shift @nodeids);
274 # process tree with names containing quoted commas
276 $tree = $treeio->next_tree;
278 @nodeids = ("'Allium drummondii, USA'", "'Allium drummondii, Russia'",'A.cyaneum');
281 for my $node ($tree->get_leaf_nodes) {
282 is($node->id, shift @nodeids);
286 # process tree with names containing quoted commas on one line
288 $tree = $treeio->next_tree;
290 @nodeids = ("'Allium drummondii, Russia'", "'Allium drummondii, USA'",'A.cyaneum');
293 for my $node ($tree->get_leaf_nodes) {
294 is($node->id, shift @nodeids);
300 # proper way (Tree isn't GC'd)
301 $tree = Bio::TreeIO->new(-format => 'newick',
302 -verbose => $verbose,
303 -file => test_input_file('bug2869.tree'))->next_tree;
305 my $root = $tree->get_root_node;
307 isa_ok($root, 'Bio::Tree::NodeI');
310 for my $child ($root->get_Descendents) {
318 $root = Bio::TreeIO->new(-format => 'newick',
319 -verbose => $verbose,
320 -file => test_input_file('bug2869.tree'),
321 -no_cleanup => 1)->next_tree->get_root_node;
323 isa_ok($root, 'Bio::Tree::NodeI');
326 local $TODO = 'The nodes are garbage-collected away b/c Tree isn\'t retained in memory';
328 for my $child ($root->get_Descendents) {
332 is($total2, $total1);
336 (((A:1,B:1):1,(C:1,D:1):1):1,((E:1,F:1):1,(G:1,H:1):1):1);