]> git.donarmstrong.com Git - ape.git/blob - R/identify.phylo.R
changes in reorder(, "cladewise")
[ape.git] / R / identify.phylo.R
1 ## identify.phylo.R (2011-03-23)
2
3 ##   Graphical Identification of Nodes and Tips
4
5 ## Copyright 2008-2011 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, quiet = FALSE, ...)
12 {
13     if (!quiet)
14         cat("Click close to a node of the tree...\n")
15     xy <- locator(1)
16     if (is.null(xy)) return(NULL)
17     lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
18     ## rescale the coordinates (especially if the x- and
19     ## y-scales are very different):
20     pin <- par("pin")
21     rescaleX <- pin[1]/max(lastPP$xx)
22     xx <- rescaleX * lastPP$xx
23     rescaleY <- pin[2]/max(lastPP$yy)
24     yy <- rescaleY * lastPP$yy
25     xy$x <- rescaleX * xy$x
26     xy$y <- rescaleY * xy$y
27     ## end of rescaling
28     d <- (xy$x - xx)^2 + (xy$y - yy)^2 # no need to sqrt()
29     NODE <- which.min(d)
30     res <- list()
31     if (NODE <= lastPP$Ntip) {
32         res$tips <- if (labels) x$tip.label[NODE] else NODE
33         return(res)
34     }
35     if (tips) {
36         TIPS <- prop.part(x)[[NODE - lastPP$Ntip]]
37         res$tips <- if (labels) x$tip.label[TIPS] else TIPS
38     }
39     if (nodes) {
40         if (is.null(x$node.label)) labels <- FALSE
41         res$nodes <- if (labels) x$node.label[NODE - lastPP$Ntip] else NODE
42     }
43     res
44 }