Bio/Tree/NodeNHX.pm

filter: Statementstmt 75.0% 30 / 40 Branchbran 75.0% 15 / 20 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 70.2% 59 / 84 CC 15 SCAR 21.0
CC
15
Cov
71%
nhx_tag
12.0
DESTROY
9.2
to_string
4.0
CRAP 8.2
« Bio/Tools/CodonTable.pm ↑ Summary Bio/SeqIO/largefasta.pm »
1 #
2 # BioPerl module for Bio::Tree::NodeNHX
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Aaron Mackey <amackey@virginia.edu>
7 #
8 # Copyright Aaron Mackey
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Tree::NodeNHX - A Simple Tree Node with support for NHX tags
17  
18 =head1 SYNOPSIS
19  
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();
24  
25 my $node = Bio::Tree::NodeNHX->new();
26 $node->add_Descendents($nodeL);
27 $node->add_Descendents($nodeR);
28  
29 print "node is not a leaf \n" if( $node->is_leaf);
30  
31 =head1 DESCRIPTION
32  
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.
35  
36 =head1 FEEDBACK
37  
38 =head2 Mailing Lists
39  
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.
43  
44 bioperl-l@bioperl.org - General discussion
45 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46  
47 =head2 Support
48  
49 Please direct usage questions or support issues to the mailing list:
50  
51 I<bioperl-l@bioperl.org>
52  
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.
57  
58 =head2 Reporting Bugs
59  
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:
63  
64 https://github.com/bioperl/bioperl-live/issues
65  
66 =head1 AUTHOR - Aaron Mackey
67  
68 Email amackey@virginia.edu
69  
70 =head1 CONTRIBUTORS
71  
72 The NHX (New Hampshire eXtended) format was created by Chris Zmasek,
73 and is described at:
74  
75 http://sourceforge.net/projects/forester-atv/
76  
77 =head1 APPENDIX
78  
79 The rest of the documentation details each of the object methods.
80 Internal methods are usually preceded with a _
81  
82 =cut
83  
84  
85 # Let the code begin...
86  
87 package Bio::Tree::NodeNHX;
88 7 $Bio::Tree::NodeNHX::VERSION = '1.7.8';
89 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91  
92 7 ▶use base qw(Bio::Tree::Node);
Subroutine BEGIN: called CC=1 SCAR=0.0
93  
94 =head2 new
95  
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
107  
108 =cut
109  
110 550 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
111 550 my($class,@args) = @_;
112  
113 550 my $self = $class->SUPER::new(@args);
114 550 my ($nhx) = $self->_rearrange([qw(NHX)], @args);
115 550 $self->nhx_tag($nhx);
116 550 return $self;
117 }
118  
119 549 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=22.2
120 549 my ($self) = @_;
121 # try to insure that everything is cleaned up
122 549 $self->SUPER::DESTROY();
123 549 ▶ if( defined $self->{'_desc'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_desc"} and ref($self->{"_desc"}) =~ /ARRAY/i) 0 549 549
Condition33%1/3
defined $self->{"_desc"} and ref($self->{"_desc"}) =~ /ARRAY/i
!ll&&!rl&&r
05490
MC/DC0%0/2
defined $self->{"_desc"} and ref($self->{"_desc"}) =~ /ARRAY/i
defined $self->{"_desc"} ref($self->{"_desc"}) =~ /ARRAY/i
Truth table33%1/3
A and B
A= defined $self->{"_desc"}B= ref($self->{"_desc"}) =~ /ARRAY/i
ABresult
0X0
100
111
124 ref($self->{'_desc'}) =~ /ARRAY/i ) {
125 0 ▶ while( my ($nodeid,$node) = each %{ $self->{'_desc'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"_desc"};}) 0 0 0
126 0 $node->{'_ancestor'} = undef; # insure no circular references
127 0 $node->DESTROY();
128 0 $node = undef;
129 }
130 0 $self->{'_desc'} = {};
131 }
132 }
133  
134 2492 ▶sub to_string{
Subroutine to_string: called CC=4 SCAR=13.9
Pod documented
135 2492 my ($self) = @_;
136 2492 my @tags = $self->get_all_tags;
137 2492 my $tagstr = '';
138 2492 ▶ if( scalar(@tags) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @tags > 0) 2269 223 2492
139 $tagstr = '[' . join(":", "&&NHX",
140 2269 map { "$_=" .join(',',
141 $self->get_tag_values($_))}
142 @tags ) . ']';
143 }
144 2492 ▶ return sprintf("%s%s%s",
Branch: 2 branches
BranchTrueFalseTotal
defined $self->id ? : 1314 1178 2492
defined $self->branch_length ? : 2408 84 2492
145 defined $self->id ? $self->id : '',
146 defined $self->branch_length ? ':' .
147 $self->branch_length : ' ',
148 $tagstr);
149 }
150  
151 =head2 nhx_tag
152  
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
158 OR
159 with a scalar value update the bootstrap value by default
160  
161  
162 =cut
163  
164 550 ▶sub nhx_tag {
Subroutine nhx_tag: called CC=9 SCAR=24.8
Pod documented
165 550 my ($self, $tags) = @_;
166 550 ▶ if (defined $tags && (ref($tags) =~ /HASH/i)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $tags and ref($tags) =~ /HASH/i) { } 478 72 550
elsif (defined $tags and not ref $tags) { } 0 144 144
Condition66%2/3
defined $tags and ref($tags) =~ /HASH/i
!ll&&!rl&&r
720478
MC/DC50%1/2
defined $tags and ref($tags) =~ /HASH/i
defined $tags ref($tags) =~ /HASH/i
Truth table66%2/3
A and B
A= defined $tagsB= ref($tags) =~ /HASH/i
ABresult
0X0
100
111
167 478 ▶ while( my ($tag,$val) = each %$tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$tags) 778 478 1256
168 778 ▶ if( ref($val) =~ /ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($val) =~ /ARRAY/i) { } 0 778 778
169 0 for my $v ( @$val ) {
170 0 $self->add_tag_value($tag,$v);
171 }
172 } else {
173 778 $self->add_tag_value($tag,$val);
174 }
175 }
176 478 ▶ if (exists $tags->{'B'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tags->{"B"}) 135 343 478
177 135 $self->bootstrap($tags->{'B'});
178 }
179 ▶ } elsif (defined $tags and ! ref ($tags)) {
Condition33%1/3
defined $tags and not ref $tags
!ll&&!rl&&r
7200
MC/DC0%0/2
defined $tags and not ref $tags
defined $tags not ref $tags
Truth table33%1/3
A and not(B)
A= defined $tagsB= not ref $tags
ABresult
0X0
100
111
180 0 $self->debug( "here with $tags\n");
181 # bootstrap by default
182 0 $self->bootstrap($tags);
183 }
184 }
185  
186 7 1;
« Bio/Tools/CodonTable.pm ↑ Summary Bio/SeqIO/largefasta.pm »