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

If tree has defined node.labels AddTips() will not change them #149

Closed
stitam opened this issue Mar 22, 2024 · 2 comments · Fixed by #150
Closed

If tree has defined node.labels AddTips() will not change them #149

stitam opened this issue Mar 22, 2024 · 2 comments · Fixed by #150

Comments

@stitam
Copy link

stitam commented Mar 22, 2024

Hi,

I'm not sure if I'm using AddTips() incorrectly or there is an issue with the function. Reprex below:

# create a random tree
set.seed(0)
tree <- ape::rtree(10)
# define node labels and plot
tree$node.label <- paste0("Node_", 1:tree$Nnode)
plot(tree, show.node.label = TRUE)

# add a tip
tree2 <- TreeTools::AddTip(tree, where = "t8", label = "new", edgeLength = 0)
# plot, notice that: 1. internal node labels change, 2. "Node_1" is now recycled!
plot(tree2, show.node.label = TRUE)

# Also node.label does not change
tree2$node.label
#> [1] "Node_1" "Node_2" "Node_3" "Node_4" "Node_5" "Node_6" "Node_7" "Node_8"
#> [9] "Node_9"

Created on 2024-03-22 with reprex v2.1.0

This is a problem because tools that make use of the node.label element will produce all sorts of issues downstream.

Not sure this is a proper fix but adding something like this may work:

if ("node.label" %in% names(tree) {
  tree$node.label <- paste0("Node_",  1:tree$Nnode)
}

The names of the internal nodes will still change but the redundancy will be eliminated.

@ms609
Copy link
Owner

ms609 commented Mar 22, 2024

Thanks for the report; AddTip() is not currently set up to support node labels, but I can take a look at this.

@stitam
Copy link
Author

stitam commented Mar 22, 2024

To add more context, I was completely unaware of the issue. I built a tree, added the new tips, exported the resulting tree, and then a downstream process produced funky results. It turned out that tree building produced a tree with internal node labels. AddTips() added the tips but did not touch node labels and then ape::write.tree() exported a tree with redundant internal node labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants