]> git.donarmstrong.com Git - ape.git/blob - R/identify.phylo.R
130a8788c658b35471af23895981068e9d622e58
[ape.git] / R / identify.phylo.R
1 ## identify.phylo.R (2008-02-28)
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     lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
16     d <- sqrt((xy$x - lastPP$xx)^2 + (xy$y - lastPP$yy)^2)
17     NODE <- which.min(d)
18     res <- list()
19     if (NODE <= lastPP$Ntip) {
20         res$tips <- if (labels) x$tip.label[NODE] else NODE
21         return(res)
22     }
23     if (tips) {
24         TIPS <- prop.part(x)[[NODE - lastPP$Ntip]]
25         res$tips <- if (labels) x$tip.label[TIPS] else TIPS
26     }
27     if (nodes) {
28         if (is.null(x$node.label)) labels <- FALSE
29         res$nodes <- if (labels) x$node.label[NODE - lastPP$Ntip] else NODE
30     }
31     res
32 }