1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# -*-Perl-*- Test Harness script for Bioperl
# $Id: RandomTreeFactory.t 11525 2007-06-27 10:16:38Z sendu $
use strict;
BEGIN {
use lib '.';
use Bio::Root::Test;
test_begin(-tests => 40);
use_ok('Bio::TreeIO');
use_ok('Bio::Tree::Statistics');
}
use Data::Dumper;
my $in = Bio::TreeIO->new(-format => 'nexus',
-file => test_input_file('traittree.nexus'));
my $tree = $in->next_tree;
my $node = $tree->find_node(-id => 'N14');
my $stats = Bio::Tree::Statistics->new();
is $stats->cherries($tree), 8, 'cherries';
is $stats->cherries($tree, $node), 4, 'cherries';
# traits
my $key = $tree->add_trait(test_input_file('traits.tab'), 3);
is ($key, 'intermediate', 'read traits');
is $stats->ps($tree, $key), 4, 'parsimony score';
is $stats->ps($tree, $key, $node), 1, 'subtree parsimony score';
my $node_i = $tree->find_node(-id => 'N10');
my @values = sort $node_i->get_tag_values('ps_trait');
ok eq_set (\@values, ['red', 'blue']), 'ps value';
is $stats->fitch_down($tree), 1, 'fitch_down';
is $node_i->get_tag_values('ps_trait'), 'red', 'ps value after fitch_down';
$node_i = $tree->find_node(-id => '2'); # leaf
is $stats->persistence($tree, $node_i), 1, 'persistence of a leaf';
$node_i = $tree->find_node(-id => 'N1');
is $stats->persistence($tree, $node_i), 1, 'persistence of an internal node value ';
$node_i = $tree->find_node(-id => 'N13');
is $stats->persistence($tree, $node_i), 3, 'persistence of an internal node value';
$node_i = $tree->find_node(-id => 'N6');
is $stats->persistence($tree, $node_i), 2, 'persistence of an internal node value';
my $value;
$node_i = $tree->find_node(-id => '1');
is $stats->count_subclusters($tree, $node_i), 0, 'leaf node: number of clusters = 0 ';
$node_i = $tree->find_node(-id => 'N3');
is $stats->count_subclusters($tree, $node_i), 1, 'number of clusters ';
$node_i = $tree->find_node(-id => 'N14');
is $stats->count_subclusters($tree, $node_i), 1, 'number of clusters ';
$node_i = $tree->find_node(-id => 'N7');
is $stats->count_subclusters($tree, $node_i), 2, 'number of clusters ';
$node_i = $tree->find_node(-id => 'N12');
is $stats->count_leaves($tree, $node_i), 2, 'number of leaves in phylotype ';
$node_i = $tree->find_node(-id => 'N13');
is $stats->count_leaves($tree, $node_i), 4, 'number of leaves in phylotype ';
$node_i = $tree->find_node(-id => 'N14');
is $stats->count_leaves($tree, $node_i), 6, 'number of leaves in phylotype ';
$node_i = $tree->find_node(-id => 'N7');
is $stats->count_leaves($tree, $node_i), 6, 'number of leaves in phylotype ';
$node_i = $tree->find_node(-id => 'N4');
is $stats->phylotype_length($tree, $node_i), 1, 'phylotype length';
$node_i = $tree->find_node(-id => 'N6');
is $stats->phylotype_length($tree, $node_i), 5, 'phylotype length';
$node_i = $tree->find_node(-id => 'N7');
is $stats->phylotype_length($tree, $node_i), 12, 'phylotype length';
$node_i = $tree->find_node(-id => 'N13');
is $stats->phylotype_length($tree, $node_i), 6, 'phylotype length';
$node_i = $tree->find_node(-id => 'N14');
is $stats->phylotype_length($tree, $node_i), 11, 'phylotype length';
$node_i = $tree->find_node(-id => 'N4');
is $stats->sum_of_leaf_distances($tree, $node_i), 1, 'sum of leaf distances';
$node_i = $tree->find_node(-id => 'N6');
is $stats->sum_of_leaf_distances($tree, $node_i), 6, 'sum of leaf distances';
$node_i = $tree->find_node(-id => 'N7');
is $stats->sum_of_leaf_distances($tree, $node_i), 18, 'sum of leaf distances';
$node_i = $tree->find_node(-id => 'N13');
is $stats->sum_of_leaf_distances($tree, $node_i), 8, 'sum of leaf distances';
$node_i = $tree->find_node(-id => 'N14');
is $stats->sum_of_leaf_distances($tree, $node_i), 18, 'sum of leaf distances';
is sprintf ("%.3f", $stats->genetic_diversity($tree, $node_i)), '3.000', 'genetic diversity';
is sprintf ("%.3f", $stats->statratio($tree, $node_i)), '0.333', 'separation';
is $stats->ai($tree, $key), 0.628906, 'association index';
is $stats->ai($tree, $key, $node), 0.062500, 'subtree association index';
my $mc = $stats->mc($tree, $key);
is ($mc->{blue}, 2, 'monophyletic clade size');
is ($mc->{red}, 4, 'monophyletic clade size');
$node = $tree->find_node(-id => 'N10');
$mc = $stats->mc($tree, $key, $node);
is ($mc->{blue}, 2, 'monophyletic clade size');
is ($mc->{red}, 2, 'monophyletic clade size');
|