data.tree 是你的朋友。例如:
newick <- '((((penHA34a,penHA34b,penHA32b,penHA32a,penSH30b,penSH30a,penSH28b,penSH28a,penIT13b,penIT13a,penIT12a,firSA26b,firGU7b,firGU8b,firSP18b,firSP20b,firSP36b,firSP39b,penSH31a,penSH31b),(firSP19b,(firSP17b,penIT12b))),firSA24a,firSA24b,firSA25a,firSA26a,firGU7a,firGU8a,firSP17a,firSP18a,firSP19a,firSP20a,firSP36a,firSP39a,(firSA25b,firSP40b),firSP40a,penIT11b,penIT11a),(ovi47a,ovi47b));'
library(data.tree)
library(ape)
phylo <- read.tree(text = newick)
tree <- as.Node(phylo)
#find a specific individual:
tree$FindNode('firSA24b')$path
这会给你:
[1] "43/44/firSA24b"
您可以打印整个树或将其输出到文件以查找特定节点:
print(tree)
#print a sub-tree
tree$FindNode('45')
#print only part of the tree:
print(tree, pruneMethod = "dist", limit = 25)
#slightly more sophisticated:
print(tree, pruneFun = function(node) !node$isLeaf || node$position <= 5)
#or:
print(tree, pruneFun = function(node) !node$isLeaf || substr(node$name, 1, 4) == 'firS')
最后一条语句输出:
levelName
1 43
2 ¦--44
3 ¦ ¦--45
4 ¦ ¦ ¦--46
5 ¦ ¦ ¦ ¦--firSA26b
6 ¦ ¦ ¦ ¦--firSP18b
7 ¦ ¦ ¦ ¦--firSP20b
8 ¦ ¦ ¦ ¦--firSP36b
9 ¦ ¦ ¦ °--firSP39b
10 ¦ ¦ °--47
11 ¦ ¦ ¦--firSP19b
12 ¦ ¦ °--48
13 ¦ ¦ °--firSP17b
14 ¦ ¦--firSA24a
15 ¦ ¦--firSA24b
16 ¦ ¦--firSA25a
17 ¦ ¦--firSA26a
18 ¦ ¦--firSP17a
19 ¦ ¦--firSP18a
20 ¦ ¦--firSP19a
21 ¦ ¦--firSP20a
22 ¦ ¦--firSP36a
23 ¦ ¦--firSP39a
24 ¦ ¦--49
25 ¦ ¦ ¦--firSA25b
26 ¦ ¦ °--firSP40b
27 ¦ °--firSP40a
28 °--50
查找整棵树的提示也很容易:
Get(tree$leaves, "name")
这将产生:
penHA34a penHA34b penHA32b penHA32a penSH30b penSH30a penSH28b penSH28a penIT13b penIT13a penIT12a firSA26b firGU7b
"penHA34a" "penHA34b" "penHA32b" "penHA32a" "penSH30b" "penSH30a" "penSH28b" "penSH28a" "penIT13b" "penIT13a" "penIT12a" "firSA26b" "firGU7b"
firGU8b firSP18b firSP20b firSP36b firSP39b penSH31a penSH31b firSP19b firSP17b penIT12b firSA24a firSA24b firSA25a
"firGU8b" "firSP18b" "firSP20b" "firSP36b" "firSP39b" "penSH31a" "penSH31b" "firSP19b" "firSP17b" "penIT12b" "firSA24a" "firSA24b" "firSA25a"
firSA26a firGU7a firGU8a firSP17a firSP18a firSP19a firSP20a firSP36a firSP39a firSA25b firSP40b firSP40a penIT11b
"firSA26a" "firGU7a" "firGU8a" "firSP17a" "firSP18a" "firSP19a" "firSP20a" "firSP36a" "firSP39a" "firSA25b" "firSP40b" "firSP40a" "penIT11b"
penIT11a ovi47a ovi47b
"penIT11a" "ovi47a" "ovi47b"
或者,您可以对特定路径执行相同的操作:
Get(tree$Climb(44, 45, 47, 48)$children, "name")