| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bio::MUST::Core::Tree; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Thin wrapper around Bio::Phylo trees |
|
3
|
|
|
|
|
|
|
# CONTRIBUTOR: Valerian LUPO <valerian.lupo@doct.uliege.be> |
|
4
|
|
|
|
|
|
|
$Bio::MUST::Core::Tree::VERSION = '0.212650'; |
|
5
|
17
|
|
|
17
|
|
125
|
use Moose; |
|
|
17
|
|
|
|
|
45
|
|
|
|
17
|
|
|
|
|
124
|
|
|
6
|
|
|
|
|
|
|
# use MooseX::SemiAffordanceAccessor; |
|
7
|
17
|
|
|
17
|
|
120222
|
use namespace::autoclean; |
|
|
17
|
|
|
|
|
47
|
|
|
|
17
|
|
|
|
|
183
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
17
|
|
|
17
|
|
1980
|
use autodie; |
|
|
17
|
|
|
|
|
49
|
|
|
|
17
|
|
|
|
|
156
|
|
|
10
|
17
|
|
|
17
|
|
92438
|
use feature qw(say); |
|
|
17
|
|
|
|
|
45
|
|
|
|
17
|
|
|
|
|
1652
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
17
|
|
|
17
|
|
133
|
use Smart::Comments '####'; |
|
|
17
|
|
|
|
|
54
|
|
|
|
17
|
|
|
|
|
205
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
17
|
|
|
17
|
|
126075
|
use Carp; |
|
|
17
|
|
|
|
|
61
|
|
|
|
17
|
|
|
|
|
1819
|
|
|
15
|
17
|
|
|
17
|
|
126
|
use Const::Fast; |
|
|
17
|
|
|
|
|
59
|
|
|
|
17
|
|
|
|
|
233
|
|
|
16
|
17
|
|
|
17
|
|
1272
|
use File::Basename; |
|
|
17
|
|
|
|
|
45
|
|
|
|
17
|
|
|
|
|
1153
|
|
|
17
|
17
|
|
|
17
|
|
116
|
use List::AllUtils qw(uniq); |
|
|
17
|
|
|
|
|
46
|
|
|
|
17
|
|
|
|
|
784
|
|
|
18
|
17
|
|
|
17
|
|
131
|
use Statistics::Descriptive; |
|
|
17
|
|
|
|
|
46
|
|
|
|
17
|
|
|
|
|
412
|
|
|
19
|
17
|
|
|
17
|
|
89
|
use Tie::IxHash; |
|
|
17
|
|
|
|
|
42
|
|
|
|
17
|
|
|
|
|
506
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
17
|
|
|
17
|
|
9114
|
use Bio::Phylo::IO qw(parse); |
|
|
17
|
|
|
|
|
844313
|
|
|
|
17
|
|
|
|
|
1241
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
17
|
|
|
17
|
|
203
|
use Bio::MUST::Core::Types; |
|
|
17
|
|
|
|
|
39
|
|
|
|
17
|
|
|
|
|
538
|
|
|
24
|
17
|
|
|
17
|
|
111
|
use Bio::MUST::Core::Constants qw(:files); |
|
|
17
|
|
|
|
|
44
|
|
|
|
17
|
|
|
|
|
2923
|
|
|
25
|
17
|
|
|
17
|
|
175
|
use Bio::MUST::Core::Utils qw(:filenames); |
|
|
17
|
|
|
|
|
57
|
|
|
|
17
|
|
|
|
|
1909
|
|
|
26
|
17
|
|
|
17
|
|
147
|
use aliased 'Bio::MUST::Core::SeqId'; |
|
|
17
|
|
|
|
|
47
|
|
|
|
17
|
|
|
|
|
168
|
|
|
27
|
17
|
|
|
17
|
|
4434
|
use aliased 'Bio::MUST::Core::IdList'; |
|
|
17
|
|
|
|
|
43
|
|
|
|
17
|
|
|
|
|
72
|
|
|
28
|
|
|
|
|
|
|
with 'Bio::MUST::Core::Roles::Commentable', |
|
29
|
|
|
|
|
|
|
'Bio::MUST::Core::Roles::Listable'; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'tree' => ( |
|
33
|
|
|
|
|
|
|
is => 'ro', |
|
34
|
|
|
|
|
|
|
isa => 'Maybe[Bio::Phylo::Forest::Tree]', |
|
35
|
|
|
|
|
|
|
default => undef, |
|
36
|
|
|
|
|
|
|
writer => '_set_tree', |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# color for uncolored taxon (see Taxonomy::ColorScheme) |
|
41
|
|
|
|
|
|
|
const my $BLACK => '#000000'; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Note: we don't store SeqId objects in the tree but dynamically build them |
|
44
|
|
|
|
|
|
|
# to benefit from SeqId methods (e.g., auto-removal of first '_'). This is |
|
45
|
|
|
|
|
|
|
# the most flexible approach without costing too much in CPU-time. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub all_seq_ids { |
|
49
|
5
|
|
|
5
|
1
|
11
|
my $self = shift; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# old code: |
|
52
|
|
|
|
|
|
|
# my @tips = @{ $self->tree->get_terminals }; |
|
53
|
|
|
|
|
|
|
# my @full_ids = map { $_->get_name } @tips; |
|
54
|
|
|
|
|
|
|
# return map { SeqId->new(full_id => $_) } @full_ids; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Note1: we use a slower visitor method to ensure that the id array |
|
57
|
|
|
|
|
|
|
# is sorted as when displayed by TreeDrawer methods |
|
58
|
|
|
|
|
|
|
# Note2: this order is consistent with FigTree display as well, but not |
|
59
|
|
|
|
|
|
|
# with Seaview (and njplot) renderings |
|
60
|
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
10
|
my @seq_ids; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->tree->visit_depth_first( |
|
64
|
|
|
|
|
|
|
# collect tip names and convert them to SeqIds |
|
65
|
|
|
|
|
|
|
-pre => sub { |
|
66
|
180
|
|
|
180
|
|
36898
|
my $node = shift; |
|
67
|
180
|
100
|
|
|
|
476
|
if ($node->is_terminal) { |
|
68
|
94
|
|
|
|
|
12639
|
push @seq_ids, SeqId->new( full_id => $node->get_name ); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
180
|
|
|
|
|
12591
|
return; |
|
71
|
|
|
|
|
|
|
}, |
|
72
|
5
|
|
|
|
|
241
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
5
|
|
|
|
|
1157
|
return @seq_ids; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# NODE-LABEL EDITING METHODS |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub shorten_ids { ## no critic (RequireArgUnpacking) |
|
82
|
0
|
|
|
0
|
1
|
0
|
return shift->_change_ids_(1, @_); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub restore_ids { ## no critic (RequireArgUnpacking) |
|
87
|
10
|
|
|
10
|
1
|
33
|
return shift->_change_ids_(0, @_); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _change_ids_ { |
|
92
|
10
|
|
|
10
|
|
20
|
my $self = shift; |
|
93
|
10
|
|
|
|
|
15
|
my $abbr = shift; |
|
94
|
10
|
|
|
|
|
14
|
my $id_mapper = shift; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# update only terminal nodes |
|
97
|
10
|
|
|
|
|
14
|
for my $tip ( @{ $self->tree->get_terminals } ) { |
|
|
10
|
|
|
|
|
283
|
|
|
98
|
360
|
|
|
|
|
108417
|
my $seq_id = SeqId->new( full_id => $tip->get_name ); |
|
99
|
360
|
50
|
|
|
|
10003
|
my $new_id = $abbr ? $id_mapper->abbr_id_for( $seq_id->full_id ) |
|
100
|
|
|
|
|
|
|
: $id_mapper->long_id_for( $seq_id->full_id ); |
|
101
|
360
|
50
|
|
|
|
1553
|
$tip->set_name($new_id) if $new_id; |
|
102
|
|
|
|
|
|
|
} # Note: leave id alone if not found |
|
103
|
|
|
|
|
|
|
|
|
104
|
10
|
|
|
|
|
96
|
return; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub switch_attributes_and_labels_for_terminals { ## no critic (RequireArgUnpacking) |
|
109
|
0
|
|
|
0
|
1
|
0
|
return shift->_switch_attributes_and_labels_(0, @_); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub switch_attributes_and_labels_for_internals { ## no critic (RequireArgUnpacking) |
|
114
|
0
|
|
|
0
|
1
|
0
|
return shift->_switch_attributes_and_labels_(1, @_); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub switch_attributes_and_labels_for_entities { ## no critic (RequireArgUnpacking) |
|
119
|
0
|
|
|
0
|
1
|
0
|
return shift->_switch_attributes_and_labels_(2, @_); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _switch_attributes_and_labels_ { |
|
124
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
|
125
|
0
|
|
|
|
|
0
|
my $mode = shift; |
|
126
|
0
|
|
|
|
|
0
|
my $key = shift; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# TODO: investigate options of Bio::Phylo::Unparsers::Newick |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# update either terminal or internal nodes |
|
131
|
0
|
|
|
|
|
0
|
my $tree = $self->tree; |
|
132
|
|
|
|
|
|
|
my @nodes = @{ |
|
133
|
0
|
0
|
|
|
|
0
|
$mode == 2 ? $tree->get_entities : |
|
|
0
|
0
|
|
|
|
0
|
|
|
134
|
|
|
|
|
|
|
$mode == 1 ? $tree->get_internals : |
|
135
|
|
|
|
|
|
|
$tree->get_terminals |
|
136
|
|
|
|
|
|
|
}; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Note: old labels are backuped in specified attributes and vice-versa |
|
139
|
|
|
|
|
|
|
# TODO: allow appending acc for terminal nodes? |
|
140
|
0
|
|
|
|
|
0
|
for my $node (@nodes) { |
|
141
|
0
|
|
|
|
|
0
|
my $label = $node->get_name; |
|
142
|
0
|
|
|
|
|
0
|
my $attribute = $node->get_generic($key); |
|
143
|
0
|
|
|
|
|
0
|
$node->set_generic($key => $label); |
|
144
|
0
|
|
|
|
|
0
|
$node->set_name($attribute); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
return; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub switch_branch_lengths_and_labels_for_entities { |
|
152
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
153
|
0
|
|
|
|
|
0
|
my $length = shift; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# use branch lengths as labels |
|
156
|
0
|
|
|
|
|
0
|
my $tree = $self->tree; |
|
157
|
0
|
|
|
|
|
0
|
for my $node ( @{ $tree->get_internals } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
158
|
0
|
|
|
|
|
0
|
$node->set_name($node->get_branch_length); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# delete branch lengths |
|
162
|
0
|
|
|
|
|
0
|
for my $node ( @{ $tree->get_entities } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
163
|
0
|
|
|
|
|
0
|
$node->set_branch_length($length); # default is undef |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
0
|
return; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub collapse_subtrees { |
|
171
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
172
|
0
|
|
0
|
|
|
0
|
my $key = shift // 'taxon_collapse'; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# compute maximal path length (from root) |
|
175
|
0
|
|
|
|
|
0
|
my $tree_max_path = $self->tree->get_root->calc_max_path_to_tips; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# "balanced"-order tree traversal |
|
178
|
0
|
|
|
|
|
0
|
my $collapsed; # will be defined when within a collapsed subtree |
|
179
|
|
|
|
|
|
|
$self->tree->visit_depth_first( |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# collapse subtrees with identical attributes |
|
182
|
|
|
|
|
|
|
-pre_daughter => sub { |
|
183
|
0
|
|
|
0
|
|
0
|
my $node = shift; |
|
184
|
0
|
0
|
|
|
|
0
|
return if $node->is_terminal; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# reset collapsing for robustness |
|
187
|
0
|
|
|
|
|
0
|
$node->set_generic('!collapse' => undef); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# do not further collapse children of a collapsed subtree |
|
190
|
|
|
|
|
|
|
# to facilitate interactive uncollapsing (e.g., in FigTree) |
|
191
|
0
|
0
|
|
|
|
0
|
return if $collapsed; |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# collect children attributes |
|
194
|
0
|
|
|
|
|
0
|
my @attrs; |
|
195
|
0
|
|
|
|
|
0
|
for (my $i = 0; my $child = $node->get_child($i); $i++) { |
|
196
|
0
|
|
|
|
|
0
|
push @attrs, $child->get_generic($key); |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# collapse subtree if all attributes are defined and identical |
|
200
|
0
|
0
|
|
|
|
0
|
return if List::AllUtils::any { not defined $_ } @attrs; |
|
|
0
|
|
|
|
|
0
|
|
|
201
|
0
|
0
|
|
|
|
0
|
return if uniq(@attrs) > 1; |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# skip black color when collapsing at color |
|
204
|
0
|
|
|
|
|
0
|
my $color = shift @attrs; |
|
205
|
0
|
0
|
|
|
|
0
|
return if $color eq $BLACK; |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# compute and set FigTree's "node height" for collapsed clade |
|
208
|
|
|
|
|
|
|
# Note: the tallest tip will be 0 |
|
209
|
0
|
|
|
|
|
0
|
my $sub_max_path = $node->calc_max_path_to_tips |
|
210
|
|
|
|
|
|
|
+ $node->calc_path_to_root; |
|
211
|
0
|
|
|
|
|
0
|
my $node_height = $tree_max_path - $sub_max_path; |
|
212
|
0
|
|
|
|
|
0
|
$node->set_generic('!collapse' => qq|{"collapsed",$node_height}|); |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# set "within a collapsed subtree" status |
|
215
|
0
|
|
|
|
|
0
|
$collapsed = $node->get_id; |
|
216
|
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
0
|
return; |
|
218
|
|
|
|
|
|
|
}, |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
-post_daughter => sub { |
|
221
|
0
|
|
|
0
|
|
0
|
my $node = shift; |
|
222
|
0
|
0
|
|
|
|
0
|
return if $node->is_terminal; |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# unset "within a collapsed subtree" status (when leaving subtree) |
|
225
|
0
|
0
|
0
|
|
|
0
|
$collapsed = undef |
|
226
|
|
|
|
|
|
|
if defined $collapsed && $collapsed eq $node->get_id; |
|
227
|
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
0
|
return; |
|
229
|
|
|
|
|
|
|
}, |
|
230
|
0
|
|
|
|
|
0
|
); |
|
231
|
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
0
|
return; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# Note: very naive approach and not applicable in practice. |
|
236
|
|
|
|
|
|
|
# Should probably use the derivative of branch length increase in log space. |
|
237
|
|
|
|
|
|
|
# Meanwhile: use treeshrink |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub long_leaf_list { |
|
240
|
1
|
|
|
1
|
0
|
317
|
my $self = shift; |
|
241
|
1
|
|
50
|
|
|
6
|
my $fact = shift // 1.5; |
|
242
|
|
|
|
|
|
|
|
|
243
|
1
|
|
|
|
|
3
|
my @tips = @{ $self->tree->get_terminals }; |
|
|
1
|
|
|
|
|
44
|
|
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# compute terminal branch length distribution |
|
246
|
1
|
|
|
|
|
76925
|
my @lengths = map { $_->get_branch_length } @tips; |
|
|
255
|
|
|
|
|
2642
|
|
|
247
|
1
|
|
|
|
|
33
|
#### list: sort { $a <=> $b } @lengths |
|
|
1569
|
|
|
|
|
1989
|
|
|
|
1
|
|
|
|
|
1701
|
|
|
248
|
1
|
|
|
|
|
32
|
my $stat = Statistics::Descriptive::Full->new; |
|
249
|
1
|
|
|
|
|
245
|
$stat->add_data( \@lengths ); |
|
250
|
|
|
|
|
|
|
|
|
251
|
1
|
|
|
|
|
523
|
my ($q1, $q3) = ( $stat->quantile(1), $stat->quantile(3) ); |
|
252
|
1
|
|
|
|
|
1802
|
#### $q1 |
|
|
1
|
|
|
|
|
212
|
|
|
253
|
1
|
|
|
|
|
14
|
#### $q3 |
|
|
1
|
|
|
|
|
161
|
|
|
254
|
1
|
|
|
|
|
5
|
#### iqr: $q3-$q1 |
|
|
1
|
|
|
|
|
190
|
|
|
255
|
1
|
|
|
|
|
12
|
#### $fact |
|
|
1
|
|
|
|
|
179
|
|
|
256
|
1
|
|
|
|
|
3
|
my $threshold = $q3 + $fact * ($q3 - $q1); |
|
257
|
1
|
|
|
|
|
12
|
#### $threshold |
|
|
1
|
|
|
|
|
179
|
|
|
258
|
|
|
|
|
|
|
|
|
259
|
32
|
|
|
|
|
165
|
my @seq_ids = map { SeqId->new( full_id => $_->get_name ) } |
|
260
|
1
|
|
|
|
|
7
|
grep { $_->get_branch_length > $threshold } @tips; |
|
|
255
|
|
|
|
|
2750
|
|
|
261
|
|
|
|
|
|
|
|
|
262
|
1
|
|
|
|
|
7
|
#### n: scalar @seq_ids |
|
|
1
|
|
|
|
|
200
|
|
|
263
|
1
|
|
|
|
|
63
|
return IdList->new( ids => \@seq_ids ); |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
# TREE-MATCHING METHODS |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# TODO1: need for a taxon pruning sub as it seems that the -keep option |
|
270
|
|
|
|
|
|
|
# TODO1: of Bio::Phylo Newick parser does not work completely |
|
271
|
|
|
|
|
|
|
# TODO2: need for a rerooting sub that completely works! |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub match_branch_lengths { |
|
274
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
275
|
0
|
|
|
|
|
0
|
my $other = shift; # second tree |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
0
|
my $tree1 = $self->tree; |
|
278
|
0
|
|
|
|
|
0
|
my $tree2 = $other->tree; |
|
279
|
0
|
|
|
|
|
0
|
tie my %blens_for, 'Tie::IxHash'; |
|
280
|
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
0
|
for my $tree ($tree1, $tree2) { |
|
282
|
0
|
|
|
|
|
0
|
for my $node ( @{ $tree->get_entities } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# compute clade key and store corresponding branch length |
|
285
|
|
|
|
|
|
|
my $clade_key |
|
286
|
|
|
|
|
|
|
= join '::', |
|
287
|
0
|
|
|
|
|
0
|
sort { $a cmp $b } |
|
288
|
0
|
|
|
|
|
0
|
map { $_->get_internal_name } @{ $node->get_terminals } |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
289
|
|
|
|
|
|
|
; |
|
290
|
0
|
|
|
|
|
0
|
my $branch_length = $node->get_branch_length; |
|
291
|
0
|
0
|
|
|
|
0
|
push @{ $blens_for{$clade_key} }, |
|
|
0
|
|
|
|
|
0
|
|
|
292
|
|
|
|
|
|
|
$branch_length if defined $branch_length; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# ensure that bipartitions matching proceeded as expected |
|
297
|
|
|
|
|
|
|
carp '[BMC] Warning: cannot match all bipartitions; returning useless hash!' |
|
298
|
|
|
|
|
|
|
unless List::AllUtils::all { |
|
299
|
0
|
|
|
0
|
|
0
|
@{ $blens_for{$_} } == 2 |
|
|
0
|
|
|
|
|
0
|
|
|
300
|
0
|
0
|
|
|
|
0
|
} keys %blens_for; |
|
301
|
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
0
|
return \%blens_for; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# I/O METHODS |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
sub load { |
|
310
|
9
|
|
|
9
|
1
|
508735
|
my $class = shift; |
|
311
|
9
|
|
|
|
|
24
|
my $infile = shift; |
|
312
|
|
|
|
|
|
|
|
|
313
|
9
|
|
|
|
|
59
|
open my $in, '<', $infile; |
|
314
|
|
|
|
|
|
|
|
|
315
|
9
|
|
|
|
|
5243
|
my $tree = $class->new(); |
|
316
|
9
|
|
|
|
|
21
|
my $newick_str; |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
LINE: |
|
319
|
9
|
|
|
|
|
7976
|
while (my $line = <$in>) { |
|
320
|
15
|
|
|
|
|
62
|
chomp $line; |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
# skip empty lines and process comment lines |
|
323
|
15
|
100
|
66
|
|
|
237
|
next LINE if $line =~ $EMPTY_LINE |
|
324
|
|
|
|
|
|
|
|| $tree->is_comment($line); |
|
325
|
|
|
|
|
|
|
|
|
326
|
9
|
|
|
|
|
205
|
$newick_str .= $line; |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
9
|
|
|
|
|
78
|
my $forest = parse(-format => 'newick', -string => $newick_str); |
|
330
|
9
|
|
|
|
|
20582309
|
$tree->_set_tree($forest->first); |
|
331
|
|
|
|
|
|
|
|
|
332
|
9
|
|
|
|
|
54
|
return $tree; |
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# Note: it seems that to_newick automatically replace spaces by '_' in node |
|
337
|
|
|
|
|
|
|
# labels (ids), which is a quite reasonable behavior. |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# TODO: define better API for outputting branch lengths/support values |
|
340
|
|
|
|
|
|
|
# TODO: use constants for to_newick parameters |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
sub store { |
|
345
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
|
346
|
1
|
|
|
|
|
3
|
my $outfile = shift; |
|
347
|
1
|
|
50
|
|
|
12
|
my $args = shift // {}; # HashRef (should not be empty...) |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
# TODO: consider allowing this hash for all store methods? |
|
350
|
|
|
|
|
|
|
|
|
351
|
1
|
|
50
|
|
|
23
|
$args->{-nodelabels} //= 1; # default to nodelabels on |
|
352
|
|
|
|
|
|
|
|
|
353
|
1
|
|
|
|
|
15
|
open my $out, '>', $outfile; |
|
354
|
1
|
|
|
|
|
329
|
say {$out} _clean_newick_str( $self->tree->to_newick( %{$args} ) ); |
|
|
1
|
|
|
|
|
31
|
|
|
|
1
|
|
|
|
|
7
|
|
|
355
|
|
|
|
|
|
|
|
|
356
|
1
|
|
|
|
|
51
|
return; |
|
357
|
|
|
|
|
|
|
} |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
sub store_itol_datasets { |
|
361
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
362
|
0
|
|
|
|
|
0
|
my $outfile = shift; |
|
363
|
0
|
|
0
|
|
|
0
|
my $key = shift // 'taxon'; |
|
364
|
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
# name dataset files |
|
366
|
0
|
|
|
|
|
0
|
my $outbase = change_suffix($outfile, '.txt'); |
|
367
|
0
|
|
|
|
|
0
|
my $color_file = insert_suffix($outbase, '-color'); |
|
368
|
0
|
|
|
|
|
0
|
my $clade_file = insert_suffix($outbase, '-clade'); |
|
369
|
0
|
|
|
|
|
0
|
my $range_file = insert_suffix($outbase, '-range'); |
|
370
|
0
|
|
|
|
|
0
|
my $label_file = insert_suffix($outbase, '-label'); |
|
371
|
0
|
|
|
|
|
0
|
my $colps_file = insert_suffix($outbase, '-collapse'); |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
# open and setup dataset files |
|
374
|
0
|
|
|
|
|
0
|
open my $color_out, '>', $color_file; |
|
375
|
0
|
|
|
|
|
0
|
say {$color_out} join "\n", 'TREE_COLORS', 'SEPARATOR COMMA', 'DATA'; |
|
|
0
|
|
|
|
|
0
|
|
|
376
|
0
|
|
|
|
|
0
|
open my $clade_out, '>', $clade_file; |
|
377
|
0
|
|
|
|
|
0
|
say {$clade_out} join "\n", 'TREE_COLORS', 'SEPARATOR COMMA', 'DATA'; |
|
|
0
|
|
|
|
|
0
|
|
|
378
|
0
|
|
|
|
|
0
|
open my $range_out, '>', $range_file; |
|
379
|
0
|
|
|
|
|
0
|
say {$range_out} join "\n", 'TREE_COLORS', 'SEPARATOR COMMA', 'DATA'; |
|
|
0
|
|
|
|
|
0
|
|
|
380
|
0
|
|
|
|
|
0
|
open my $label_out, '>', $label_file; |
|
381
|
0
|
|
|
|
|
0
|
say {$label_out} join "\n", 'LABELS', 'SEPARATOR COMMA', 'DATA'; |
|
|
0
|
|
|
|
|
0
|
|
|
382
|
0
|
|
|
|
|
0
|
open my $colps_out, '>', $colps_file; |
|
383
|
0
|
|
|
|
|
0
|
say {$colps_out} join "\n", 'COLLAPSE', 'DATA'; |
|
|
0
|
|
|
|
|
0
|
|
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
# setup format |
|
386
|
0
|
|
|
|
|
0
|
my $type = 'normal', |
|
387
|
|
|
|
|
|
|
my $size = 1; |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
NODE: |
|
390
|
0
|
|
|
|
|
0
|
for my $node ( @{ $self->tree->get_entities } ){ |
|
|
0
|
|
|
|
|
0
|
|
|
391
|
0
|
|
0
|
|
|
0
|
my $color = $node->get_generic('!color') // $BLACK; |
|
392
|
0
|
|
|
|
|
0
|
my $label = $node->get_generic($key); |
|
393
|
0
|
|
|
|
|
0
|
my $collapse = $node->get_generic('!collapse'); |
|
394
|
|
|
|
|
|
|
|
|
395
|
0
|
0
|
|
|
|
0
|
if ($node->is_terminal) { |
|
396
|
0
|
0
|
|
|
|
0
|
next NODE if $color eq $BLACK; |
|
397
|
|
|
|
|
|
|
|
|
398
|
0
|
|
|
|
|
0
|
my $id = SeqId->new( full_id => $node->get_name )->foreign_id; |
|
399
|
0
|
|
|
|
|
0
|
say {$color_out} join q{,}, $id, 'label', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
400
|
0
|
|
|
|
|
0
|
say {$clade_out} join q{,}, $id, 'clade', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
401
|
0
|
|
|
|
|
0
|
say {$range_out} join q{,}, $id, 'range', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
402
|
|
|
|
|
|
|
|
|
403
|
0
|
|
|
|
|
0
|
next NODE; |
|
404
|
|
|
|
|
|
|
} |
|
405
|
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
0
|
my @descendants; |
|
407
|
0
|
|
|
|
|
0
|
for (my $i = 0; my $child = $node->get_child($i); $i++) { |
|
408
|
0
|
|
|
|
|
0
|
push @descendants, @{ $child->get_terminals }; |
|
|
0
|
|
|
|
|
0
|
|
|
409
|
|
|
|
|
|
|
} |
|
410
|
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
# Note: Simply calling get_terminals on node returns descendants |
|
412
|
|
|
|
|
|
|
# in an order that leads to mis-selecting the first and last ones. |
|
413
|
|
|
|
|
|
|
# Instead we store the descendants from node's main two (or more) |
|
414
|
|
|
|
|
|
|
# children sequentially. This seems to fix the issue. |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
# determine first and last descendants to build node id |
|
417
|
|
|
|
|
|
|
my $id = join '|', map { |
|
418
|
0
|
0
|
|
|
|
0
|
SeqId->new( full_id => $_->get_name )->foreign_id |
|
|
0
|
|
|
|
|
0
|
|
|
419
|
|
|
|
|
|
|
} @descendants[ @descendants > 1 ? (0,-1) : (0) ]; |
|
420
|
|
|
|
|
|
|
# Note: should always > 1 but one never knows... |
|
421
|
|
|
|
|
|
|
|
|
422
|
0
|
0
|
|
|
|
0
|
say {$label_out} join q{,}, $id, $label if $label; |
|
|
0
|
|
|
|
|
0
|
|
|
423
|
0
|
0
|
|
|
|
0
|
say {$colps_out} $id if $collapse; |
|
|
0
|
|
|
|
|
0
|
|
|
424
|
|
|
|
|
|
|
|
|
425
|
0
|
0
|
|
|
|
0
|
next NODE if $color eq $BLACK; |
|
426
|
|
|
|
|
|
|
|
|
427
|
0
|
|
|
|
|
0
|
say {$color_out} join q{,}, $id, 'label', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
428
|
0
|
|
|
|
|
0
|
say {$clade_out} join q{,}, $id, 'clade', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
429
|
0
|
|
|
|
|
0
|
say {$range_out} join q{,}, $id, 'range', $color, $type, $size; |
|
|
0
|
|
|
|
|
0
|
|
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
|
|
432
|
0
|
|
|
|
|
0
|
return; |
|
433
|
|
|
|
|
|
|
} |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
sub store_figtree { |
|
437
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
438
|
0
|
|
|
|
|
0
|
my $outfile = shift; |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
# transfer taxon names for internals only |
|
441
|
|
|
|
|
|
|
# this is needed to avoid double naming of tips (std label + taxon) |
|
442
|
0
|
|
|
|
|
0
|
for my $node ( @{ $self->tree->get_internals } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
443
|
0
|
|
|
|
|
0
|
my $taxon = $node->get_generic('taxon'); |
|
444
|
0
|
0
|
|
|
|
0
|
$node->set_generic('!name' => qq|"$taxon"|) if $taxon; |
|
445
|
|
|
|
|
|
|
} # Note: get_generic does not return undef, hence: if $taxon |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
# build mesquite-enabled Newick string |
|
448
|
0
|
|
|
|
|
0
|
my $newick_str = $self->tree->to_newick( |
|
449
|
|
|
|
|
|
|
-nodelabels => 1, |
|
450
|
|
|
|
|
|
|
# -blformat => '%.10f', |
|
451
|
|
|
|
|
|
|
-nhxkeys => [ '!name', '!color', '!collapse' ], |
|
452
|
|
|
|
|
|
|
-nhxstyle => 'mesquite', |
|
453
|
|
|
|
|
|
|
); |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
# ... and adapt it for FigTree |
|
456
|
0
|
|
|
|
|
0
|
$newick_str =~ s{\[%}{[&}xmsg; |
|
457
|
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
# ... then restore zero-valued bootstrap values |
|
459
|
|
|
|
|
|
|
# since 'false' internal names are converted to 'NodeNNN' strings |
|
460
|
0
|
|
|
|
|
0
|
$newick_str =~ s{\b Node\d+ \b}{0}xmsg; |
|
461
|
|
|
|
|
|
|
# TODO: consider doing that also in the standard store? |
|
462
|
|
|
|
|
|
|
|
|
463
|
0
|
|
|
|
|
0
|
open my $out, '>', $outfile; |
|
464
|
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
# output minimal NEXUS tree file |
|
466
|
0
|
|
|
|
|
0
|
print {$out} <<"EOF"; |
|
|
0
|
|
|
|
|
0
|
|
|
467
|
|
|
|
|
|
|
#NEXUS |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
begin trees; |
|
470
|
|
|
|
|
|
|
tree tree_1 = [&R] $newick_str |
|
471
|
|
|
|
|
|
|
end; |
|
472
|
|
|
|
|
|
|
EOF |
|
473
|
|
|
|
|
|
|
|
|
474
|
0
|
|
|
|
|
0
|
return; |
|
475
|
|
|
|
|
|
|
} |
|
476
|
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
sub store_arb { |
|
479
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
|
480
|
3
|
|
|
|
|
6
|
my $outfile = shift; |
|
481
|
3
|
|
50
|
|
|
12
|
my $args = shift // {}; # HashRef (should not be empty...) |
|
482
|
|
|
|
|
|
|
|
|
483
|
3
|
|
|
|
|
7
|
my $alifile = $args->{alifile}; |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
# optionally link to Ali (without path) |
|
486
|
3
|
100
|
|
|
|
11
|
if ($alifile) { |
|
487
|
1
|
|
|
|
|
85
|
my ($basename, $dir, $ext) = fileparse($alifile, qr{\.[^.]*}xms); |
|
488
|
1
|
|
|
|
|
53
|
$self->insert_comment("$basename$ext"); |
|
489
|
|
|
|
|
|
|
} |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
# build standard Newick string |
|
492
|
3
|
|
|
|
|
112
|
my $newick_str = _clean_newick_str( |
|
493
|
|
|
|
|
|
|
$self->tree->to_newick( -nodelabels => 0 ) |
|
494
|
|
|
|
|
|
|
); |
|
495
|
|
|
|
|
|
|
|
|
496
|
3
|
|
|
|
|
23
|
open my $out, '>', $outfile; |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
# output ARB tree file |
|
499
|
3
|
|
|
|
|
1201
|
print {$out} $self->header; |
|
|
3
|
|
|
|
|
21
|
|
|
500
|
3
|
|
|
|
|
11
|
say {$out} $newick_str; |
|
|
3
|
|
|
|
|
102
|
|
|
501
|
|
|
|
|
|
|
|
|
502
|
3
|
|
|
|
|
189
|
return; |
|
503
|
|
|
|
|
|
|
} |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
sub store_grp { |
|
507
|
5
|
|
|
5
|
1
|
21
|
my $self = shift; |
|
508
|
5
|
|
|
|
|
17
|
my $outfile = shift; |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
# extract tip ids, non-root nodes and support values |
|
511
|
5
|
|
|
|
|
23
|
my @tip_ids = map { $_->foreign_id } $self->all_seq_ids; |
|
|
94
|
|
|
|
|
240
|
|
|
512
|
5
|
|
|
|
|
169
|
my @nodes = grep { not $_->is_root } @{ $self->tree->get_internals }; |
|
|
86
|
|
|
|
|
3607
|
|
|
|
5
|
|
|
|
|
148
|
|
|
513
|
5
|
|
|
|
|
90
|
my @bp_vals = map { $_->get_name } @nodes; |
|
|
81
|
|
|
|
|
1080
|
|
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
# determine support value type (BP or PP) |
|
516
|
5
|
50
|
|
8
|
|
140
|
my $pp = List::AllUtils::all { $_ >= 0.0 && $_ <= 1.0 } @bp_vals; |
|
|
8
|
|
|
|
|
48
|
|
|
517
|
|
|
|
|
|
|
|
|
518
|
5
|
|
|
|
|
36
|
open my $out, '>', $outfile; |
|
519
|
|
|
|
|
|
|
|
|
520
|
5
|
|
|
|
|
1681
|
for my $node (@nodes) { |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
# build bipartition string |
|
523
|
|
|
|
|
|
|
my %in_bip = map { |
|
524
|
755
|
|
|
|
|
234251
|
SeqId->new( full_id => $_->get_name )->foreign_id => 1 |
|
525
|
81
|
|
|
|
|
169
|
} @{ $node->get_terminals }; |
|
|
81
|
|
|
|
|
517
|
|
|
526
|
81
|
100
|
|
|
|
467
|
my $bip = join q{}, map { $in_bip{$_} ? '*' : '.' } @tip_ids; |
|
|
5304
|
|
|
|
|
10606
|
|
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
# fetch (and possibly fix) support value for bipartition |
|
529
|
81
|
|
|
|
|
426
|
my $support = shift @bp_vals; |
|
530
|
81
|
100
|
|
|
|
358
|
$support = int( $support * 100.0 ) if $pp; |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# write bipartition line |
|
533
|
81
|
|
|
|
|
192
|
say {$out} "$bip $support"; |
|
|
81
|
|
|
|
|
758
|
|
|
534
|
|
|
|
|
|
|
} |
|
535
|
|
|
|
|
|
|
|
|
536
|
5
|
|
|
|
|
365
|
return; |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
sub store_tpl { |
|
541
|
1
|
|
|
1
|
1
|
19
|
my $self = shift; |
|
542
|
1
|
|
|
|
|
12
|
my $outfile = shift; |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
# backup and discard branch lengths |
|
545
|
|
|
|
|
|
|
# Note: I have to do that since I cannot clone the tree (Bio::Phylo bug?) |
|
546
|
1
|
|
|
|
|
11
|
my @branch_lengths; |
|
547
|
1
|
|
|
|
|
12
|
for my $node ( @{ $self->tree->get_entities } ) { |
|
|
1
|
|
|
|
|
52
|
|
|
548
|
914
|
|
|
|
|
12081
|
push @branch_lengths, $node->get_branch_length; |
|
549
|
914
|
|
|
|
|
9867
|
$node->set_branch_length(undef); |
|
550
|
|
|
|
|
|
|
} |
|
551
|
|
|
|
|
|
|
|
|
552
|
1
|
|
|
|
|
22
|
open my $out, '>', $outfile; |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
# output topology |
|
555
|
1
|
|
|
|
|
411
|
say {$out} '1'; # TODO: improve this for multiple topologies |
|
|
1
|
|
|
|
|
16
|
|
|
556
|
1
|
|
|
|
|
4
|
say {$out} _clean_newick_str( |
|
|
1
|
|
|
|
|
34
|
|
|
557
|
|
|
|
|
|
|
$self->tree->to_newick( -nodelabels => 0 ) |
|
558
|
|
|
|
|
|
|
); |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
# restore branch lengths |
|
561
|
1
|
|
|
|
|
7
|
for my $node ( @{ $self->tree->get_entities } ) { |
|
|
1
|
|
|
|
|
70
|
|
|
562
|
914
|
|
|
|
|
16255
|
$node->set_branch_length( shift @branch_lengths ); |
|
563
|
|
|
|
|
|
|
} |
|
564
|
|
|
|
|
|
|
|
|
565
|
1
|
|
|
|
|
91
|
return; |
|
566
|
|
|
|
|
|
|
} |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub _clean_newick_str { |
|
570
|
5
|
|
|
5
|
|
1543957
|
my $newick_str = shift; |
|
571
|
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
# remove quotes... |
|
573
|
|
|
|
|
|
|
# ...and trailing zero-length branch length (RAxML) if any |
|
574
|
5
|
|
|
|
|
208
|
$newick_str =~ tr{'"}{}d; |
|
575
|
5
|
|
|
|
|
199
|
$newick_str =~ s{:0\.0+;}{;}xmsg; |
|
576
|
|
|
|
|
|
|
|
|
577
|
5
|
|
|
|
|
324
|
return $newick_str; |
|
578
|
|
|
|
|
|
|
} |
|
579
|
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
581
|
|
|
|
|
|
|
1; |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
__END__ |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=pod |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=head1 NAME |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
Bio::MUST::Core::Tree - Thin wrapper around Bio::Phylo trees |
|
590
|
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=head1 VERSION |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
version 0.212650 |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
# TODO |
|
598
|
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
600
|
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
# TODO |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
=head1 METHODS |
|
604
|
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
=head2 all_seq_ids |
|
606
|
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
=head2 shorten_ids |
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=head2 restore_ids |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
=head2 switch_attributes_and_labels_for_terminals |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
=head2 switch_attributes_and_labels_for_internals |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
=head2 switch_attributes_and_labels_for_entities |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
=head2 switch_branch_lengths_and_labels_for_entities |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=head2 collapse_subtrees |
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
=head2 match_branch_lengths |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
=head2 load |
|
624
|
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=head2 store |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
=head2 store_itol_datasets |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
=head2 store_figtree |
|
630
|
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
=head2 store_arb |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
=head2 store_grp |
|
634
|
|
|
|
|
|
|
|
|
635
|
|
|
|
|
|
|
=head2 store_tpl |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
=head1 AUTHOR |
|
638
|
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
Denis BAURAIN <denis.baurain@uliege.be> |
|
640
|
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
|
642
|
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
=for stopwords Valerian LUPO |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
Valerian LUPO <valerian.lupo@doct.uliege.be> |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
648
|
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN. |
|
650
|
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
652
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
=cut |