Bio/TreeIO/tabtree.pm

filter: Statementstmt 34.4% 10 / 29 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 3 / 6 Podpod 100% 3 / 3 totaltotal 27.5% 16 / 58 CC 10 SCAR 37.2
CC
10
Cov
22%
_write_tree_Helper
72.0
write_tree
12.0
next_tree
2.0
CRAP 41.1
« Bio/SeqFeature/Tools/FeatureNamer.pm ↑ Summary Bio/Seq/PrimedSeq.pm »
1 #
2 # BioPerl module for Bio::TreeIO::tabtree
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
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::TreeIO::tabtree - A simple output format which displays a tree as an ASCII drawing
17  
18 =head1 SYNOPSIS
19  
20 use Bio::TreeIO;
21 my $in = Bio::TreeIO->new(-file => 'input', -format => 'newick');
22 my $out = Bio::TreeIO->new(-file => '>output', -format => 'tabtree');
23  
24 while( my $tree = $in->next_tree ) {
25 $out->write_tree($tree);
26 }
27  
28 =head1 DESCRIPTION
29  
30 This is a made up format just for outputting trees as an ASCII drawing.
31  
32 =head1 FEEDBACK
33  
34 =head2 Mailing Lists
35  
36 User feedback is an integral part of the evolution of this and other
37 Bioperl modules. Send your comments and suggestions preferably to
38 the Bioperl mailing list. Your participation is much appreciated.
39  
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
42  
43 =head2 Support
44  
45 Please direct usage questions or support issues to the mailing list:
46  
47 I<bioperl-l@bioperl.org>
48  
49 rather than to the module maintainer directly. Many experienced and
50 reponsive experts will be able look at the problem and quickly
51 address it. Please include a thorough description of the problem
52 with code and data examples if at all possible.
53  
54 =head2 Reporting Bugs
55  
56 Report bugs to the Bioperl bug tracking system to help us keep track
57 of the bugs and their resolution. Bug reports can be submitted via the
58 web:
59  
60 https://github.com/bioperl/bioperl-live/issues
61  
62 =head1 AUTHOR - Jason Stajich
63  
64 Email jason@bioperl.org
65  
66 =head1 APPENDIX
67  
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
70  
71 =cut
72  
73  
74 # Let the code begin...
75  
76  
77 package Bio::TreeIO::tabtree;
78 2 $Bio::TreeIO::tabtree::VERSION = '1.7.8';
79 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 # Object preamble - inherits from Bio::Root::Root
82  
83  
84  
85 2 ▶use base qw(Bio::TreeIO);
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 =head2 new
88  
89 Title : new
90 Usage : my $obj = Bio::TreeIO::tabtree->new();
91 Function: Builds a new Bio::TreeIO::tabtree object
92 Returns : Bio::TreeIO::tabtree
93 Args :
94  
95  
96 =cut
97  
98 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
99 1 my($class,@args) = @_;
100  
101 1 my $self = $class->SUPER::new(@args);
102  
103 }
104  
105 =head2 write_tree
106  
107 Title : write_tree
108 Usage : $treeio->write_tree($tree);
109 Function: Write a tree out to data stream in newick/phylip format
110 Returns : none
111 Args : Bio::Tree::TreeI object
112  
113 =cut
114  
115 0 ▶sub write_tree{
Subroutine write_tree: not called CC=3 SCAR=24.8
Pod documented
116 0 my ($self,$tree) = @_;
117 0 my $line = _write_tree_Helper($tree->get_root_node,"");
118 0 $self->_print($line. "\n");
119 0 ▶ $self->flush if $self->_flush_on_write && defined $self->_fh;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_flush_on_write and defined $self->_fh 0 0 0
Condition0%0/3
$self->_flush_on_write and defined $self->_fh
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write defined $self->_fh
Truth table0%0/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
ABresult
0X0
100
111
120 0 return;
121 }
122  
123 0 ▶sub _write_tree_Helper {
Subroutine _write_tree_Helper: not called CC=8 SCAR=42.8
124 0 my ($node,$indent) = @_;
125 0 ▶ return unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 0 0
126  
127 0 my @d = $node->each_Descendent();
128 0 my $line = "";
129 0 my ($i,$lastchild) = (0,scalar @d - 1);
130 0 for my $n ( @d ) {
131 0 ▶ if( $n->is_Leaf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->is_Leaf) { } 0 0 0
132 0 ▶ $line .= sprintf("%s| \n%s\\-%s\n",
Condition0%0/2
$n->id || ''
l!l
00
MC/DC0%0/1
$n->id || ''
$n->id
Truth table0%0/2
A
A= $n->id
Aresult
11
00
133 $indent,$indent,$n->id || '');
134 } else {
135 0 ▶ $line .= sprintf("$indent| %s\n",( $n->id ?
Branch: 1 branch
BranchTrueFalseTotal
$n->id ? : 0 0 0
136 sprintf("(%s)",$n->id) : ''));
137 }
138 0 ▶ my $new_indent = $indent . (($i == $lastchild) ? "| " : " ");
Branch: 1 branch
BranchTrueFalseTotal
$i == $lastchild ? : 0 0 0
139 0 ▶ if( $n != $node ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n != $node) 0 0 0
140 # avoid the unlikely case of cycles
141 0 $line .= _write_tree_Helper($n,$new_indent);
142 }
143 }
144 0 return $line;
145 }
146  
147 =head2 next_tree
148  
149 Title : next_tree
150 Usage :
151 Function: Sorry not possible with this format
152 Returns : none
153 Args : none
154  
155  
156 =cut
157  
158 0 ▶sub next_tree{
Subroutine next_tree: not called CC=1 SCAR=6.9
Pod documented
159 0 $_[0]->throw("Sorry the format 'tabtree' can only be used as an output format at this time");
160 }
161  
162 2 1;
« Bio/SeqFeature/Tools/FeatureNamer.pm ↑ Summary Bio/Seq/PrimedSeq.pm »