1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id: TreeIO.t 14580 2008-03-01 17:01:30Z cjfields $
8 use File::Temp qw(tempfile);
10 test_begin(-tests => 19);
11 use_ok('Bio::TreeIO');
14 my $verbose = 0; #test_debug();
18 my $treeio = Bio::TreeIO->new(
21 -file => test_input_file('test.nhx'),
25 $tree = $treeio->next_tree;
26 isa_ok($tree, 'Bio::Tree::TreeI');
28 my @nodes = $tree->get_nodes;
29 is(@nodes, 12, "Total Nodes");
30 #print STDERR "TREE: ".$tree->as_text('nhx')."\n";
32 my $adhy = $tree->find_node('ADHY');
33 is($adhy->branch_length, 0.1);
34 is(($adhy->get_tag_values('S'))[0], 'nematode');
35 is(($adhy->get_tag_values('E'))[0], '1.1.1.1');
37 test_roundtrip('((a,b),c);','simple newick');
38 test_roundtrip('((x:0.05,y:0.06),a:0.1[&&NHX:G=dummy]);','bug 1471 test');
39 test_roundtrip('((x:0.05[&&NHX:label=x],y:0.06)[&&NHX:label=int_node],a:0.1[&&NHX:label=a]);','different combinations of label, NHX, and branch length');
41 test_roundtrip('(a:1,b:2,c:3,d:4)TEST:1.2345;','doot node branch length');
42 test_roundtrip('(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5)F;','Example from Wikipedia');
44 test_roundtrip('(((ADH2:0.1[&&NHX:E=1.1.1.1:S=human],ADH1:0.11[&&NHX:E=1.1.1.1:S=human]):0.05[&&NHX:B=100:D=Y:E=1.1.1.1:S=Primates],ADHY:0.1[&&NHX:E=1.1.1.1:S=nematode],ADHX:0.12[&&NHX:E=1.1.1.1:S=insect]):0.1[&&NHX:D=N:E=1.1.1.1:S=Metazoa],(ADH4:0.09[&&NHX:E=1.1.1.1:S=yeast],ADH3:0.13[&&NHX:E=1.1.1.1:S=yeast],ADH2:0.12[&&NHX:E=1.1.1.1:S=yeast],ADH1:0.11[&&NHX:E=1.1.1.1:S=yeast]):0.1[&&NHX:S=Fungi])[&&NHX:D=N:E=1.1.1.1];','ADH NHX tree');
45 test_roundtrip('(gene1_Hu[&&NHX:S=Hu_Homo_sapiens],(gene2_Hu[&&NHX:S=Hu_Homo_sapiens],gene2_Mu[&&NHX:S=Mu_Mus_musculus]));','notung nhx example http://www.cs.cmu.edu/~aiton/split/Manual-2.6.master014.html');
46 test_roundtrip('(cow_gene1,(mouse_gene2,cow_gene2)[&&NHX:B=100]);','notung nhx bootstrap http://www.cs.cmu.edu/~aiton/split/Manual-2.6.master014.html');
48 # Read in some larger trees from data files...
49 test_roundtrip(read_file(test_input_file('nhx-bacteria.nhx')),'r-sig-phylo mailing list http://www.mail-archive.com/r-sig-phylo@r-project.org/msg00516.html');
50 test_roundtrip(read_file(test_input_file('ex1.nucl.nhx')),'treebest example nhx');
51 # Note: these files aren't reproduced exactly in their online form. We need to round-trip them once
52 # before including them in the test, because the ordering of annotation keys is not a well-defined
53 # part of the NHX format. Since nhx.pm sorts the keys before output, once they've been through
54 # one time, the ordering becomes stable.
55 test_roundtrip(read_file(test_input_file('wellcome_tol.nhx')),'Wellcome Trust ToL (from http://iphylo.blogspot.com/2009/02/thoughts-on-wellcome-interactive-tree.html)');
57 # Uncomment to run (takes a long time!!)
58 #test_roundtrip(read_file(test_input_file('tol-2010-02-18.nhx')),'Tolweb.org converted to NHX');
60 test_roundtrip(read_file(test_input_file('biorecipe.nhx')),'Biorecipes NHX file (http://www.biorecipes.com/Orthologues/StatusPage/pics/TreeEukaryota.nt)');
66 my $in = Bio::TreeIO->new(-format => 'nhx',
71 my $t = $in->next_tree;
74 $out = $t->as_text('nhx');
77 $desc = "Roundtrip: $desc";
78 return is($out,$string,$desc);
85 open my $IN, '<', $file or die "Could not read file '$file': $!\n";
90 $string =~ s/$cr//g; # For files with Windows line-endings
91 #print STDERR "STR: $string\n";