Skip to content

Commit

Permalink
Merge pull request #879 from shawnlaffan/issue_877_part2
Browse files Browse the repository at this point in the history
treenode to R phylo: handle root length properly
  • Loading branch information
shawnlaffan authored Sep 19, 2023
2 parents 9216d7f + 1e856b9 commit f1b4962
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/Biodiverse/TreeNode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,6 @@ sub to_R_phylo {

my $length = $node->get_length;
$length =~ s/,/./; # hack for issue #775 (another comma radix char)
push @length_arr, $length;

if ($node->is_terminal_node) {
push @tip_labels, $name;
Expand All @@ -2367,6 +2366,8 @@ sub to_R_phylo {

next NODE if $node->is_root_node;

push @length_arr, $length;

my $parent_id;
my $parent = $node->get_parent;

Expand All @@ -2389,7 +2390,7 @@ sub to_R_phylo {
'Nnode' => (scalar @internal_labels + 1),
'node.label' => \@internal_labels,
'tip.label' => \@tip_labels,
'root.edge' => 0,
'root.edge' => $self->get_length,
);

return wantarray ? %str : \%str;
Expand Down
9 changes: 8 additions & 1 deletion t/13-Tree.t
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,15 @@ sub test_export_Rphylo {
my @trees = $rn->get_tree_array;
my $tree1 = shift @trees;

# another one
$nwk = '(A:1, B:1):5.8';
$rn = Biodiverse::ReadNexus->new;
$success = $rn->import_newick (data => $nwk);
@trees = $rn->get_tree_array;
my $tree3 = shift @trees;

my $i;
foreach my $tree ($tree1, $tree2) {
foreach my $tree ($tree1, $tree2, $tree3) {
$i++;
my $result = $tree->to_R_phylo;
# round trip it
Expand Down

0 comments on commit f1b4962

Please sign in to comment.