Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treenode to R phylo: handle root length properly #879

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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