/usr/share/perl5/Bio/TreeIO/newick.pm is in libbio-perl-perl 1.6.924-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | #
# BioPerl module for Bio::TreeIO::newick
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Jason Stajich <jason@bioperl.org>
#
# Copyright Jason Stajich
#
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
=head1 NAME
Bio::TreeIO::newick
=head1 SYNOPSIS
# do not use this module directly
use Bio::TreeIO;
my $treeio = Bio::TreeIO->new(-format => 'newick',
-file => 't/data/LOAD_Ccd1.dnd');
my $tree = $treeio->next_tree;
=head1 DESCRIPTION
This module handles parsing and writing of Newick/PHYLIP/New Hampshire format.
=head1 FEEDBACK
=head2 Mailing Lists
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to the
Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
=head2 Support
Please direct usage questions or support issues to the mailing list:
I<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
=head2 Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
https://github.com/bioperl/bioperl-live/issues
=head1 AUTHOR - Jason Stajich
Email jason-at-bioperl-dot-org
=head1 APPENDIX
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
=cut
# Let the code begin...
package Bio::TreeIO::newick;
use strict;
use Bio::Event::EventGeneratorI;
use base qw(Bio::TreeIO Bio::TreeIO::NewickParser);
=head2 new
Title : new
Args : -print_count => boolean default is false
-bootstrap_style => set the bootstrap style (one of nobranchlength,
molphy, traditional)
-order_by => set the order by sort method
See L<Bio::Node::Node::each_Descendent()>
=cut
sub _initialize {
my $self = shift;
$self->SUPER::_initialize(@_);
my ( $print_count ) = $self->_rearrange(
[
qw(PRINT_COUNT)
],
@_
);
$self->print_tree_count( $print_count || 0 );
return;
}
=head2 next_tree
Title : next_tree
Usage : my $tree = $treeio->next_tree
Function: Gets the next tree in the stream
Returns : L<Bio::Tree::TreeI>
Args : none
=cut
sub next_tree {
my ($self) = @_;
local $/ = ";\n";
return unless $_ = $self->_readline;
s/[\r\n]//gs;
my $score;
my $despace = sub { my $dirty = shift; $dirty =~ s/\s+//gs; return $dirty };
my $dequote = sub {
my $dirty = shift;
$dirty =~ s/^"?\s*(.+?)\s*"?$/$1/;
return $dirty;
};
s/([^"]*)(".+?")([^"]*)/$despace->($1) . $dequote->($2) . $despace->($3)/egsx;
if (s/^\s*\[([^\]]+)\]//) {
my $match = $1;
$match =~ s/\s//g;
$match =~ s/lh\=//;
if ( $match =~ /([-\d\.+]+)/ ) {
$score = $1;
}
}
$self->_eventHandler->start_document;
# Call the parse_newick method as defined in NewickParser.pm
$self->parse_newick($_);
my $tree = $self->_eventHandler->end_document;
# Add the tree score afterwards if it exists.
if (defined $tree) {
$tree->score($score);
return $tree;
}
}
# Returns the default set of parsing & writing parameters for the Newick format.
sub get_default_params {
my $self = shift;
return {
newline_each_node => 0,
order_by => '', # ???
bootstrap_style => 'traditional', # Can be 'traditional', 'molphy', 'nobranchlength'
internal_node_id => 'id', # Can be 'id' or 'bootstrap'
no_branch_lengths => 0,
no_bootstrap_values => 0,
no_internal_node_labels => 0
};
}
=head2 write_tree
Title : write_tree
Usage : $treeio->write_tree($tree);
Function: Write a tree out to data stream in newick/phylip format
Returns : none
Args : L<Bio::Tree::TreeI> object
=cut
sub write_tree {
my ( $self, @trees ) = @_;
if ( $self->print_tree_count ) {
$self->_print( sprintf( " %d\n", scalar @trees ) );
}
my $params = $self->get_params;
foreach my $tree (@trees) {
if ( !defined $tree
|| ref($tree) =~ /ARRAY/i
|| !$tree->isa('Bio::Tree::TreeI') )
{
$self->throw(
"Calling write_tree with non Bio::Tree::TreeI object\n");
}
my @data = $self->_write_tree_Helper( $tree->get_root_node, $params);
$self->_print( join( ',', @data ).";" );
}
$self->flush if $self->_flush_on_write && defined $self->_fh;
return;
}
sub _write_tree_Helper {
my $self = shift;
my ( $node, $params ) = @_;
my @data;
foreach my $n ( $node->each_Descendent($params->{order_by}) ) {
push @data, $self->_write_tree_Helper( $n, $params );
}
my $label = $self->_node_as_string($node,$params);
if ( scalar(@data) >= 1) {
$data[0] = "(" . $data[0];
$data[-1] .= ")";
$data[-1] .= $label;
} else {
push @data, $label;
}
return @data;
}
sub _node_as_string {
my $self = shift;
my $node = shift;
my $params = shift;
my $label_stringbuffer = '';
if ($params->{no_bootstrap_values} != 1 &&
!$node->is_Leaf &&
defined $node->bootstrap &&
$params->{bootstrap_style} eq 'traditional' &&
$params->{internal_node_id} eq 'bootstrap') {
# If we're an internal node and we're using 'traditional' bootstrap style,
# we output the bootstrap instead of any label.
my $bootstrap = $node->bootstrap;
$label_stringbuffer .= $bootstrap if (defined $bootstrap);
} elsif ($params->{no_internal_node_labels} != 1) {
my $id = $node->id;
$label_stringbuffer .= $id if( defined $id );
}
if ($params->{no_branch_lengths} != 1) {
my $blen = $node->branch_length;
$label_stringbuffer .= ":". $blen if (defined $blen);
}
if ($params->{bootstrap_style} eq 'molphy') {
my $bootstrap = $node->bootstrap;
$label_stringbuffer .= "[$bootstrap]" if (defined $bootstrap);
}
if ($params->{newline_each_node} == 1) {
$label_stringbuffer .= "\n";
}
return $label_stringbuffer;
}
=head2 print_tree_count
Title : print_tree_count
Usage : $obj->print_tree_count($newval)
Function: Get/Set flag for printing out the tree count (paml,protml way)
Returns : value of print_tree_count (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub print_tree_count {
my $self = shift;
return $self->{'_print_tree_count'} = shift if @_;
return $self->{'_print_tree_count'} || 0;
}
=head2 bootstrap_style
Title : bootstrap_style
Usage : $obj->bootstrap_style($newval)
Function: A description of how bootstraps and branch lengths are
written, as the ID part of the internal node or else in []
in the branch length (Molphy-like; I am sure there is a
better name for this but am not sure where to go for some
sort of format documentation)
If no branch lengths are requested then no bootstraps are usually
written (unless someone REALLY wants this functionality...)
Can take on strings which contain the possible values of
'nobranchlength' --> don't draw any branch lengths - this
is helpful if you don't want to have to
go through and delete branch len on all nodes
'molphy' --> draw bootstraps (100) like
(A:0.11,B:0.22):0.33[100];
'traditional' --> draw bootstraps (100) like
(A:0.11,B:0.22)100:0.33;
Returns : value of bootstrap_style (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub bootstrap_style {
my $self = shift;
my $val = shift;
if ( defined $val ) {
if ( $val !~ /^nobranchlength|molphy|traditional/i ) {
$self->warn(
"requested an unknown bootstrap style $val, expect one of nobranchlength,molphy,traditional, not updating value.\n"
);
}
else {
$self->{'_bootstrap_style'} = $val;
}
}
return $self->{'_bootstrap_style'} || 'traditional';
}
=head2 order_by
Title : order_by
Usage : $obj->order_by($newval)
Function: Allow node order to be specified (typically "alpha")
See L<Bio::Node::Node::each_Descendent()>
Returns : value of order_by (a scalar)
Args : on set, new value (a scalar or undef, optional)
=cut
sub order_by {
my $self = shift;
return $self->{'order_by'} = shift if @_;
return $self->{'order_by'};
}
1;
|