3 # BioPerl module for Bio::Tree::NodeNHX
5 # Cared for by Aaron Mackey <amackey@virginia.edu>
7 # Copyright Aaron Mackey
9 # You may distribute this module under the same terms as perl itself
11 # POD documentation - main docs before the code
15 Bio::Tree::NodeNHX - A Simple Tree Node with support for NHX tags
19 use Bio::Tree::NodeNHX;
20 my $nodeA = Bio::Tree::NodeNHX->new();
21 my $nodeL = Bio::Tree::NodeNHX->new();
22 my $nodeR = Bio::Tree::NodeNHX->new();
24 my $node = Bio::Tree::NodeNHX->new();
25 $node->add_Descendents($nodeL);
26 $node->add_Descendents($nodeR);
28 print "node is not a leaf \n" if( $node->is_leaf);
32 Makes a Tree Node with NHX tags, suitable for building a Tree. See
33 L<Bio::Tree::Node> for a full list of functionality.
39 User feedback is an integral part of the evolution of this and other
40 Bioperl modules. Send your comments and suggestions preferably to
41 the Bioperl mailing list. Your participation is much appreciated.
43 bioperl-l@bioperl.org - General discussion
44 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
48 Report bugs to the Bioperl bug tracking system to help us keep track
49 of the bugs and their resolution. Bug reports can be submitted via
52 http://bugzilla.open-bio.org/
54 =head1 AUTHOR - Aaron Mackey
56 Email amackey@virginia.edu
60 The NHX (New Hampshire eXtended) format was created by Chris Zmasek,
63 http://www.genetics.wustl.edu/eddy/forester/NHX.html
67 The rest of the documentation details each of the object methods.
68 Internal methods are usually preceded with a _
73 # Let the code begin...
75 package Bio
::Tree
::NodeNHX
;
79 use base
qw(Bio::Tree::Node);
84 Usage : my $obj = Bio::Tree::NodeNHX->new();
85 Function: Builds a new Bio::Tree::NodeNHX object
86 Returns : Bio::Tree::NodeNHX
87 Args : -left => pointer to Left descendent (optional)
88 -right => pointer to Right descenent (optional)
89 -branch_length => branch length [integer] (optional)
90 -bootstrap => bootstrap value (string)
91 -description => description of node
92 -id => unique id for node
93 -nhx => hashref of NHX tags and values
98 my($class,@args) = @_;
100 my $self = $class->SUPER::new
(@args);
101 my ($nhx) = $self->_rearrange([qw(NHX)], @args);
102 $self->nhx_tag($nhx);
108 # try to insure that everything is cleaned up
109 $self->SUPER::DESTROY
();
110 if( defined $self->{'_desc'} &&
111 ref($self->{'_desc'}) =~ /ARRAY/i ) {
112 while( my ($nodeid,$node) = each %{ $self->{'_desc'} } ) {
113 $node->{'_ancestor'} = undef; # insure no circular references
117 $self->{'_desc'} = {};
123 my @tags = $self->get_all_tags;
126 $tagstr = '[' . join(":", "&&NHX",
127 map { "$_=" .join(',',
128 $self->get_tag_values($_))}
131 return sprintf("%s%s%s",
132 defined $self->id ?
$self->id : '',
133 defined $self->branch_length ?
':' .
134 $self->branch_length : ' ',
141 Usage : my $tag = $nodenhx->nhx_tag(%tags);
142 Function: Set tag-value pairs for NHX nodes
144 Args : hashref to update the tags/value pairs
146 with a scalar value update the bootstrap value by default
152 my ($self, $tags) = @_;
153 if (defined $tags && (ref($tags) =~ /HASH/i)) {
154 while( my ($tag,$val) = each %$tags ) {
155 if( ref($val) =~ /ARRAY/i ) {
156 for my $v ( @
$val ) {
157 $self->add_tag_value($tag,$v);
160 $self->add_tag_value($tag,$val);
163 if (exists $tags->{'B'}) {
164 $self->bootstrap($tags->{'B'});
166 } elsif (defined $tags and ! ref ($tags)) {
167 $self->debug( "here with $tags\n");
168 # bootstrap by default
169 $self->bootstrap($tags);