]> git.donarmstrong.com Git - ape.git/blob - R/identify.phylo.R
current 2.1 release
[ape.git] / R / identify.phylo.R
1 ## identify.phylo.R (2007-12-14)
2
3 ##   Graphical Identification of Nodes and Tips
4
5 ## Copyright 2007 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     xy <- locator(1)
14     Ntip <- .last_plot.phylo$Ntip
15     d <- sqrt((xy$x - .last_plot.phylo$xx)^2 +
16               (xy$y - .last_plot.phylo$yy)^2)
17     NODE <- which.min(d)
18     print(NODE)
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 }