Reputation: 1
I'm working with the ape
package in R. I want a list of every possible subtree
from a phylogenetic
tree. I then want to iterate through the list of subtrees and get the root of every subtree. My question is, is the first internal node listed for each subtree the root of that subtree?
An example might illustrates my question better. I created a random tree with 12 tips, then extract the subtrees. I've copied the output for subtree 1. R then lists a couple of things including Node labels: 13, 14, ...
for each subtree. Is the first node listed in Node labels (in this case node 13) always the root of the subtree?
phy = rtree(12)
st = subtrees(phy)
>st[[1]]
> st
[[1]]
Phylogenetic tree with 12 tips and 11 internal nodes.
Tip labels:
t12, t2, t10, t1, t9, t4, ...
Node labels:
13, 14, 15, 16, 17, 18, ...
Rooted; includes branch lengths.
Upvotes: 0
Views: 1660
Reputation: 1244
That seems to be the case. To verify, you can visualize the tree by converting it to a data.tree structure:
library(data.tree)
tr <- as.Node(phy)
print(tr)
This will show as:
levelName
1 13
2 ¦--t7
3 °--14
4 ¦--15
5 ¦ ¦--t5
6 ¦ °--t6
7 °--16
8 ¦--17
9 ¦ ¦--18
10 ¦ ¦ ¦--19
11 ¦ ¦ ¦ ¦--20
12 ¦ ¦ ¦ ¦ ¦--t2
13 ¦ ¦ ¦ ¦ °--t9
14 ¦ ¦ ¦ °--t12
15 ¦ ¦ °--t4
16 ¦ °--21
17 ¦ ¦--22
18 ¦ ¦ ¦--t3
19 ¦ ¦ °--t1
20 ¦ °--23
21 ¦ ¦--t10
22 ¦ °--t11
23 °--t8
Upvotes: 1