| Summary | Included libraries | Package variables | Synopsis | Description | General documentation | Methods |
| WebCvs |
use Bio::Tree::Compatible;
use Bio::TreeIO;
my $input = Bio::TreeIO->new('-format' => 'newick',
'-file' => 'input.tre');
my $t1 = $input->next_tree;
my $t2 = $input->next_tree;
my ($incompat, $ilabels, $inodes) = Bio::Tree::Compatible::is_compatible($t1,$t2); if ($incompat) { my %cluster1 = %{ Bio::Tree::Compatible::cluster_representation($t1) }; my %cluster2 = %{ Bio::Tree::Compatible::cluster_representation($t2) }; print "incompatible trees\n"; if (scalar(@$ilabels)) { foreach my $label (@$ilabels) { my $node1 = $t1->find_node(-id => $label); my $node2 = $t2->find_node(-id => $label); my @c1 = sort @{ $cluster1{$node1} }; my @c2 = sort @{ $cluster2{$node2} }; print "label $label"; print " cluster"; map { print " ",$_ } @c1; print " cluster"; map { print " ",$_ } @c2; print "\n"; } } if (scalar(@$inodes)) { while (@$inodes) { my $node1 = shift @$inodes; my $node2 = shift @$inodes; my @c1 = sort @{ $cluster1{$node1} }; my @c2 = sort @{ $cluster2{$node2} }; print "cluster"; map { print " ",$_ } @c1; print " properly intersects cluster"; map { print " ",$_ } @c2; print "\n"; } } } else { print "compatible trees\n"; }
| postorder_traversal | Description | Code |
| cluster_representation | Description | Code |
| common_labels | Description | Code |
| topological_restriction | Description | Code |
| is_compatible | Description | Code |
| postorder_traversal | code | next | Top |
Title : postorder_traversalFor example, the postorder traversal of the tree (((A,B)C,D),(E,F,G)); is a reference to an array of nodes with internal_id 0 through 9, because the Newick standard representation for phylogenetic trees is based on a postorder traversal. +---A +---0 |
| cluster_representation | code | prev | next | Top |
Title : cluster_representationFor example, the cluster representation of the tree (((A,B)C,D),(E,F,G)); is a reference to a hash associating an array of string (descendent labels) to each node, as follows: 0 --> [A] |
| common_labels | code | prev | next | Top |
Title : common_labelsFor example, the common labels of the tree (((A,B)C,D),(E,F,G)); and the tree ((A,B)H,E,(J,(K)G)I); are: [A,B,E,G]. +---A +---A |
| topological_restriction | code | prev | next | Top |
Title : topological_restrictionFor example, the topological restrictions of each of the trees (((A,B)C,D),(E,F,G)); and ((A,B)H,E,(J,(K)G)I); to the labels [A,B,E,G] are as follows: +---A +---A |
| is_compatible | code | prev | next | Top |
Title : is_compatibleFor example, the topological restrictions of the trees (((A,B)C,D),(E,F,G)); and ((A,B)H,E,(J,(K)G)I); to their common labels, [A,B,E,G], are compatible. The respective cluster representations are as follows: [A] [A]As a second example, the trees (A,B); and ((B)A); are incompatible. Their respective cluster representations are as follows: [A] [B]The reason is, the smallest cluster containing label A is [A] in the first tree but [A,B] in the second tree. +---A A---BAs a second example, the trees (((B,A),C),D); and ((A,(D,B)),C); are also incompatible. Their respective cluster representations are as follows: [A] [A]The reason is, cluster [A,B] properly intersects cluster [B,D]. There are further incompatibilities between these trees: [A,B,C] properly intersects both [B,D] and [A,B,D]. +---B +-------A |
| postorder_traversal | description | prev | next | Top |
my($self) = @_; my @stack; my @queue; push @stack, $self->get_root_node; while (@stack) { my $node = pop @stack; push @queue, $node; foreach my $child ($node->each_Descendent(-sortby => 'internal_id')) { push @stack, $child; } } my @postorder = reverse @queue; return\@ postorder;}
| cluster_representation | description | prev | next | Top |
my ($tree) = @_; my %cluster; my @postorder = @{ postorder_traversal($tree) }; foreach my $node ( @postorder ) { my @labeled = map { $_->id } grep { $_->id } $node->get_Descendents; push @labeled, $node->id if $node->id; $cluster{$node} =\@ labeled; } return\% cluster;}
| common_labels | description | prev | next | Top |
my($self,$arg) = @_; my @labels1 = map { $_->id } grep { $_->id } $self->get_nodes; my $common = Set::Scalar->new( @labels1 ); my @labels2 = map { $_->id } grep { $_->id } $arg->get_nodes; my $temp = Set::Scalar->new( @labels2 ); return $common->intersection($temp);}
| topological_restriction | description | prev | next | Top |
my ($tree, $labels) = @_; for my $node ( @{ postorder_traversal($tree) } ) { unless (ref($node)) { # skip $node if already removed}
my @cluster = map { $_->id } grep { $_->id } $node->get_Descendents; push @cluster, $node->id if $node->id; my $cluster = Set::Scalar->new(@cluster); if ($cluster->is_disjoint($labels)) { $tree->remove_Node($node); } else { if ($node->id and not $labels->has($node->id)) { $node->{'_id'} = undef; } } } }
| is_compatible | description | prev | next | Top |
my ($tree1, $tree2) = @_; my $common = $tree1->Bio::Tree::Compatible::common_labels($tree2); $tree1->Bio::Tree::Compatible::topological_restriction($common); $tree2->Bio::Tree::Compatible::topological_restriction($common); my @postorder1 = @{ postorder_traversal($tree1) }; my @postorder2 = @{ postorder_traversal($tree2) }; my %cluster1 = %{ cluster_representation($tree1) }; my %cluster2 = %{ cluster_representation($tree2) }; my $incompat = 0; # false}
my @labels; foreach my $label ( $common->elements ) { my $node1 = $tree1->find_node(-id => $label); my @labels1 = @{ $cluster1{$node1} }; my $cluster1 = Set::Scalar->new(@labels1); my $node2 = $tree2->find_node(-id => $label); my @labels2 = @{ $cluster2{$node2} }; my $cluster2 = Set::Scalar->new(@labels2); unless ( $cluster1->is_equal($cluster2) ) { $incompat = 1; # true
push @labels, $label; } } my @nodes; foreach my $node1 ( @postorder1 ) { my @labels1 = @{ $cluster1{$node1} }; my $cluster1 = Set::Scalar->new(@labels1); foreach my $node2 ( @postorder2 ) { my @labels2 = @{$cluster2{$node2} }; my $cluster2 = Set::Scalar->new(@labels2); if ($cluster1->is_properly_intersecting($cluster2)) { $incompat = 1; # true
push @nodes, $node1, $node2; } } } return ($incompat,\@ labels,\@ nodes); } 1;
| FEEDBACK | Top |
| Mailing Lists | Top |
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
| Support | Top |
| Reporting Bugs | Top |
https://redmine.open-bio.org/projects/bioperl/
| SEE ALSO | Top |
| AUTHOR - Gabriel Valiente | Top |
| APPENDIX | Top |