3 # BioPerl module for Bio::TreeIO::tabtree
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Jason Stajich <jason@bioperl.org>
9 # Copyright Jason Stajich
11 # You may distribute this module under the same terms as perl itself
13 # POD documentation - main docs before the code
17 Bio::TreeIO::tabtree - A simple output format which displays a tree as an ASCII drawing
22 my $in = Bio::TreeIO->new(-file => 'input', -format => 'newick');
23 my $out = Bio::TreeIO->new(-file => '>output', -format => 'tabtree');
25 while( my $tree = $in->next_tree ) {
26 $out->write_tree($tree);
31 This is a made up format just for outputting trees as an ASCII drawing.
37 User feedback is an integral part of the evolution of this and other
38 Bioperl modules. Send your comments and suggestions preferably to
39 the Bioperl mailing list. Your participation is much appreciated.
41 bioperl-l@bioperl.org - General discussion
42 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
46 Please direct usage questions or support issues to the mailing list:
48 I<bioperl-l@bioperl.org>
50 rather than to the module maintainer directly. Many experienced and
51 reponsive experts will be able look at the problem and quickly
52 address it. Please include a thorough description of the problem
53 with code and data examples if at all possible.
57 Report bugs to the Bioperl bug tracking system to help us keep track
58 of the bugs and their resolution. Bug reports can be submitted via the
61 http://bugzilla.open-bio.org/
63 =head1 AUTHOR - Jason Stajich
65 Email jason@bioperl.org
69 The rest of the documentation details each of the object methods.
70 Internal methods are usually preceded with a _
75 # Let the code begin...
78 package Bio
::TreeIO
::tabtree
;
81 # Object preamble - inherits from Bio::Root::Root
85 use base
qw(Bio::TreeIO);
90 Usage : my $obj = Bio::TreeIO::tabtree->new();
91 Function: Builds a new Bio::TreeIO::tabtree object
92 Returns : Bio::TreeIO::tabtree
99 my($class,@args) = @_;
101 my $self = $class->SUPER::new
(@args);
108 Usage : $treeio->write_tree($tree);
109 Function: Write a tree out to data stream in newick/phylip format
111 Args : Bio::Tree::TreeI object
116 my ($self,$tree) = @_;
117 my $line = _write_tree_Helper
($tree->get_root_node,"");
118 $self->_print($line. "\n");
119 $self->flush if $self->_flush_on_write && defined $self->_fh;
123 sub _write_tree_Helper
{
124 my ($node,$indent) = @_;
125 return unless defined $node;
127 my @d = $node->each_Descendent();
129 my ($i,$lastchild) = (0,scalar @d - 1);
132 $line .= sprintf("%s| \n%s\\-%s\n",
133 $indent,$indent,$n->id || '');
135 $line .= sprintf("$indent| %s\n",( $n->id ?
136 sprintf("(%s)",$n->id) : ''));
138 my $new_indent = $indent . (($i == $lastchild) ?
"| " : " ");
140 # avoid the unlikely case of cycles
141 $line .= _write_tree_Helper
($n,$new_indent);
151 Function: Sorry not possible with this format
159 $_[0]->throw("Sorry the format 'tabtree' can only be used as an output format at this time");