2 # BioPerl module for Bio::TreeIO::tabtree
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Jason Stajich <jason@bioperl.org>
8 # Copyright Jason Stajich
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::TreeIO::tabtree - A simple output format which displays a tree as an ASCII drawing
21 my $in = Bio::TreeIO->new(-file => 'input', -format => 'newick');
22 my $out = Bio::TreeIO->new(-file => '>output', -format => 'tabtree');
24 while( my $tree = $in->next_tree ) {
25 $out->write_tree($tree);
30 This is a made up format just for outputting trees as an ASCII drawing.
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.
40 bioperl-l@bioperl.org - General discussion
41 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
45 Please direct usage questions or support issues to the mailing list:
47 I<bioperl-l@bioperl.org>
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.
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
60 https://github.com/bioperl/bioperl-live/issues
62 =head1 AUTHOR - Jason Stajich
64 Email jason@bioperl.org
68 The rest of the documentation details each of the object methods.
69 Internal methods are usually preceded with a _
74 # Let the code begin...
77 package Bio
::TreeIO
::tabtree
;
80 # Object preamble - inherits from Bio::Root::Root
84 use base
qw(Bio::TreeIO);
89 Usage : my $obj = Bio::TreeIO::tabtree->new();
90 Function: Builds a new Bio::TreeIO::tabtree object
91 Returns : Bio::TreeIO::tabtree
98 my($class,@args) = @_;
100 my $self = $class->SUPER::new
(@args);
107 Usage : $treeio->write_tree($tree);
108 Function: Write a tree out to data stream in newick/phylip format
110 Args : Bio::Tree::TreeI object
115 my ($self,$tree) = @_;
116 my $line = _write_tree_Helper
($tree->get_root_node,"");
117 $self->_print($line. "\n");
118 $self->flush if $self->_flush_on_write && defined $self->_fh;
122 sub _write_tree_Helper
{
123 my ($node,$indent) = @_;
124 return unless defined $node;
126 my @d = $node->each_Descendent();
128 my ($i,$lastchild) = (0,scalar @d - 1);
131 $line .= sprintf("%s| \n%s\\-%s\n",
132 $indent,$indent,$n->id || '');
134 $line .= sprintf("$indent| %s\n",( $n->id ?
135 sprintf("(%s)",$n->id) : ''));
137 my $new_indent = $indent . (($i == $lastchild) ?
"| " : " ");
139 # avoid the unlikely case of cycles
140 $line .= _write_tree_Helper
($n,$new_indent);
150 Function: Sorry not possible with this format
158 $_[0]->throw("Sorry the format 'tabtree' can only be used as an output format at this time");