data.tree is you friend. For example:
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
This will give you:
[1] "43/44/firSA24b"
You can print the entire tree or output it to a file to look for a particular node:
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')
The last statement outputs this:
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
Finding tips of the entire tree is also easy:
Get(tree$leaves, "name")
This will yield:
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"
Or, you can do the same thing for a specific path:
Get(tree$Climb(44, 45, 47, 48)$children, "name")
tree <- ape::read.tree(file = textConnection("((((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));")); tree$tip.label
. – lukeA