maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / lib / Bio / Tree / NodeNHX.pm
blob0da3a332d4a9ffe064d302f2e9cb71fbd82e593b
2 # BioPerl module for Bio::Tree::NodeNHX
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Aaron Mackey <amackey@virginia.edu>
8 # Copyright Aaron Mackey
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
14 =head1 NAME
16 Bio::Tree::NodeNHX - A Simple Tree Node with support for NHX tags
18 =head1 SYNOPSIS
20 use Bio::Tree::NodeNHX;
21 my $nodeA = Bio::Tree::NodeNHX->new();
22 my $nodeL = Bio::Tree::NodeNHX->new();
23 my $nodeR = Bio::Tree::NodeNHX->new();
25 my $node = Bio::Tree::NodeNHX->new();
26 $node->add_Descendents($nodeL);
27 $node->add_Descendents($nodeR);
29 print "node is not a leaf \n" if( $node->is_leaf);
31 =head1 DESCRIPTION
33 Makes a Tree Node with NHX tags, suitable for building a Tree. See
34 L<Bio::Tree::Node> for a full list of functionality.
36 =head1 FEEDBACK
38 =head2 Mailing Lists
40 User feedback is an integral part of the evolution of this and other
41 Bioperl modules. Send your comments and suggestions preferably to
42 the Bioperl mailing list. Your participation is much appreciated.
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
47 =head2 Support
49 Please direct usage questions or support issues to the mailing list:
51 I<bioperl-l@bioperl.org>
53 rather than to the module maintainer directly. Many experienced and
54 reponsive experts will be able look at the problem and quickly
55 address it. Please include a thorough description of the problem
56 with code and data examples if at all possible.
58 =head2 Reporting Bugs
60 Report bugs to the Bioperl bug tracking system to help us keep track
61 of the bugs and their resolution. Bug reports can be submitted via
62 the web:
64 https://github.com/bioperl/bioperl-live/issues
66 =head1 AUTHOR - Aaron Mackey
68 Email amackey@virginia.edu
70 =head1 CONTRIBUTORS
72 The NHX (New Hampshire eXtended) format was created by Chris Zmasek,
73 and is described at:
75 http://sourceforge.net/projects/forester-atv/
77 =head1 APPENDIX
79 The rest of the documentation details each of the object methods.
80 Internal methods are usually preceded with a _
82 =cut
85 # Let the code begin...
87 package Bio::Tree::NodeNHX;
89 use strict;
92 use base qw(Bio::Tree::Node);
94 =head2 new
96 Title : new
97 Usage : my $obj = Bio::Tree::NodeNHX->new();
98 Function: Builds a new Bio::Tree::NodeNHX object
99 Returns : Bio::Tree::NodeNHX
100 Args : -left => pointer to Left descendent (optional)
101 -right => pointer to Right descenent (optional)
102 -branch_length => branch length [integer] (optional)
103 -bootstrap => bootstrap value (string)
104 -description => description of node
105 -id => unique id for node
106 -nhx => hashref of NHX tags and values
108 =cut
110 sub new {
111 my($class,@args) = @_;
113 my $self = $class->SUPER::new(@args);
114 my ($nhx) = $self->_rearrange([qw(NHX)], @args);
115 $self->nhx_tag($nhx);
116 return $self;
119 sub DESTROY {
120 my ($self) = @_;
121 # try to insure that everything is cleaned up
122 $self->SUPER::DESTROY();
123 if( defined $self->{'_desc'} &&
124 ref($self->{'_desc'}) =~ /ARRAY/i ) {
125 while( my ($nodeid,$node) = each %{ $self->{'_desc'} } ) {
126 $node->{'_ancestor'} = undef; # insure no circular references
127 $node->DESTROY();
128 $node = undef;
130 $self->{'_desc'} = {};
134 sub to_string{
135 my ($self) = @_;
136 my @tags = $self->get_all_tags;
137 my $tagstr = '';
138 if( scalar(@tags) > 0 ) {
139 $tagstr = '[' . join(":", "&&NHX",
140 map { "$_=" .join(',',
141 $self->get_tag_values($_))}
142 @tags ) . ']';
144 return sprintf("%s%s%s",
145 defined $self->id ? $self->id : '',
146 defined $self->branch_length ? ':' .
147 $self->branch_length : ' ',
148 $tagstr);
151 =head2 nhx_tag
153 Title : nhx_tag
154 Usage : my $tag = $nodenhx->nhx_tag(%tags);
155 Function: Set tag-value pairs for NHX nodes
156 Returns : none
157 Args : hashref to update the tags/value pairs
159 with a scalar value update the bootstrap value by default
162 =cut
164 sub nhx_tag {
165 my ($self, $tags) = @_;
166 if (defined $tags && (ref($tags) =~ /HASH/i)) {
167 while( my ($tag,$val) = each %$tags ) {
168 if( ref($val) =~ /ARRAY/i ) {
169 for my $v ( @$val ) {
170 $self->add_tag_value($tag,$v);
172 } else {
173 $self->add_tag_value($tag,$val);
176 if (exists $tags->{'B'}) {
177 $self->bootstrap($tags->{'B'});
179 } elsif (defined $tags and ! ref ($tags)) {
180 $self->debug( "here with $tags\n");
181 # bootstrap by default
182 $self->bootstrap($tags);