Bio-Phylo

 view release on metacpan or  search on metacpan

t/57-nhx.t  view on Meta::CPAN

#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
use Bio::Phylo::IO qw'parse_tree unparse';

my $expected = {
	'155657|estExt_Genewise1.C_15140004' => { 
		'length' => 5.3435, 
		'nhx' => { 'D' => 'N', 'G' => '155657|estExt_Genewise1.C_15140004', 'T' => 283909 }
	},
	'jgi|Helro1|186101' => {
		'length' => 100000, 
		'nhx' => { 'D' => 'N', 'G' => 'jgi|Helro1|186101', 'T' => 6412 }
	},
	'Annelida' => {
		'length' => 0.0000, 
		'nhx' => { 'D' => 'N', 'B' => 27, 'T' => 6340 }
	},
	'222316' => {
		'length' => 2.9506, 
		'nhx' => { 'D' => 'N', 'G' => 222316, 'T' => 225164 }
	},
	'Lophotrochozoa' => {
		'length' => 0, 
		'nhx' => { 'D' => 'N', 'B' => 0, 'T' => 1206795 }
	},
	'31120' => {
		'length' => 1.0547, 
		'nhx' => { 'D' => 'N', 'G' => 31120, 'T' => 81824 }
	}, 
	'PTSG_04766T0' => {
		'length' => 1.0994, 
		'nhx' => { 'D' => 'N', 'G' => 'PTSG_04766T0', 'T' => 218847 }
	}
};

my $tree = parse_tree(
	'-format' => 'nhx',
	'-handle' => \*DATA,
);
isa_ok($tree, 'Bio::Phylo::Forest::Tree');
for my $name ( keys %$expected ) {
	my $node = $tree->get_by_name($name);
	isa_ok($node, 'Bio::Phylo::Forest::Node');
	ok($node->get_branch_length == $expected->{$name}->{'length'}, "branch length of $name");
	for my $key ( keys %{ $expected->{$name}->{'nhx'} } ) {
		my $exp = $expected->{$name}->{'nhx'}->{$key};
		my $obs = $node->get_meta_object( 'nhx:' . $key );
		ok( $obs eq $exp, "$key: $obs eq $exp" );
	}
}
ok( unparse(
	'-format' => 'nhx',
	'-phylo'  => $tree,
), 'unparse to NHX' );

__DATA__
(((((155657|estExt_Genewise1.C_15140004:5.3435[&&NHX:D=N:G=155657|estExt_Genewise1.C_15140004:T=283909],jgi|Helro1|186101:100000[&&NHX:D=N:G=jgi|Helro1|186101:T=6412])Annelida:0.0000[&&NHX:D=N:B=27:T=6340],222316:2.9506[&&NHX:D=N:G=222316:T=225164])L...



( run in 1.589 second using v1.01-cache-2.11-cpan-364913b4093 )