]> git.donarmstrong.com Git - ape.git/blob - R/identify.phylo.R
stabler and faster C code for ME and BIONJ
[ape.git] / R / identify.phylo.R
1 ## identify.phylo.R (2008-01-14)
2
3 ##   Graphical Identification of Nodes and Tips
4
5 ## Copyright 2008 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 identify.phylo <- function(x, nodes = TRUE, tips = FALSE,
11                            labels = FALSE, ...)
12 {
13     cat("Click close to a node of the tree...\n")
14     xy <- locator(1)
15     Ntip <- .last_plot.phylo$Ntip
16     d <- sqrt((xy$x - .last_plot.phylo$xx)^2 +
17               (xy$y - .last_plot.phylo$yy)^2)
18     NODE <- which.min(d)
19     res <- list()
20     if (NODE <= Ntip) {
21         res$tips <- if (labels) x$tip.label[NODE] else NODE
22         return(res)
23     }
24     if (tips) {
25         TIPS <- prop.part(x)[[NODE - Ntip]]
26         res$tips <- if (labels) x$tip.label[TIPS] else TIPS
27     }
28     if (nodes) {
29         if (is.null(x$node.label)) labels <- FALSE
30         res$nodes <- if (labels) x$node.label[NODE - Ntip] else NODE
31     }
32     res
33 }