Open jayoung opened 9 months ago
I also tried an older version treeio_1.20.2 (on a different computer) and this time, the tip.label and node.labels are retained. So something went wrong between versions 1.20.2 and version 1.26.0.
I can reproduce the error on treeio 1.25.4
actually, not so sure that treeio_1.20.2 does work as I said on Friday. Now that I'm back on the first computer, and I've installed treeio_1.20.2 here, I still have a problem.
Might be some interaction with one of the other packages I have installed - I'm a little unclear on what's going on under the hood, and which package(s) are most relevant.
I guess my first question is - should I expect root
on a treedata object to return updated tree@phylo$tip.label and tree@phylo$node.label (some resorting of the original character vector I would think). Or are these new arbitrary "1", "2" type labels expected?
I figured out a workaround for this issue in my code: I go back to the tree as a plain phylo object, reroot that, and regenerate the treedata object by adding the metadata.
Interestingly, when I plot the new rerooted trees (using root(phylo)
), the node labels are placed differently than they were when I rerooted using old package versions androot(treedata)
. I think the new version (re-rooting the plain phylo object) is the correct one: the old one seemed to be entirely dropping the node label that was associated with the most basal (and shifting positions of nearby node labels), whereas the new method keeps that node label.
Was there an error before in the 'root' method for treedata objects with node labels? Is that why node.labels are dropped now?
I can't figure out how to make a reproducible example for the possibly wrongly placed node labels now that I've updated my R packages (because root(treedata)
doesn't even keep node labels any more). But if this issue gets fixed so that root no longer drops node.labels on treedata objects, I'll test to make sure that it gives the same result as rerooting the plain phylo object.
Hello, I can offer more detail, I tried to read the code of root.treedata
. I ran codes one by one. I found the changing of tip label occur during this line:
phy@phylo <- build_new_tree(tree = re_tree, node2old_new_lab = node2oldnewlab)
if checking the code of treeio:::build_new_tree:
function (tree, node2old_new_lab)
{
treeda <- tree %>% as_tibble()
treeda1 <- treeda %>% dplyr::filter(.data$label %in% node2old_new_lab$new)
treeda2 <- treeda %>% dplyr::filter(!(.data$label %in% node2old_new_lab$new))
treeda1$label <- node2old_new_lab[match(treeda1$label, node2old_new_lab$new),
"old"] %>% unlist(use.names = FALSE)
treeda <- rbind(treeda1, treeda2)
tree <- treeda[order(treeda$node), ] %>% as.phylo()
return(tree)
}
<bytecode: 0x000001386e341da0>
<environment: namespace:treeio>
I used same data as @jayoung , here is the content of re_tree
before input
>re_tree
Phylogenetic tree with 23 tips and 21 internal nodes.
Tip labels:
t1, t2, t3, t4, t5, t6, ...
Node labels:
n1, n2, n3, n4, n5, n6, ...
Unrooted; no branch lengths.
but after ran tree <- treeda[order(treeda$node), ] %>% as.phylo()
> tree
Phylogenetic tree with 23 tips and 21 internal nodes.
Tip labels:
1, 2, 3, 4, 5, 6, ...
Node labels:
24, 25, 26, 27, 28, 29, ...
Unrooted; no branch lengths.
I don't know whether this is correct class type for as.phylo
here, and no more ability to resolve it.
thanks for read 👍🏽
edit: I found changing is not happened in line tree <- treeda[order(treeda$node), ] %>% as.phylo()
hi there,
I am trying to reroot a treedata object, and I find that the tip.label and node.labels are getting lost from the phylogeny (they're getting replaced with
c("1","2","3",etc)
The example code below should show you what I mean. I get the same problem if I use the trda treedata object defined in the treedata book
Am I doing something wrong, or is this a bug?
thanks very much!
Janet Young
Here's sessionInfo() output: