X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fas.phylo.R;h=8ebd54049fa1b9693a48bd034a8203a71aaaa633;hb=453ad4ce9e573998f28185d92c8d71367dd32f23;hp=e8d0f667a325b8df396f2f552d38ecbfa78e1f74;hpb=821974300c3d4c88584832e3f4b2c99ed56601cb;p=ape.git diff --git a/R/as.phylo.R b/R/as.phylo.R index e8d0f66..8ebd540 100644 --- a/R/as.phylo.R +++ b/R/as.phylo.R @@ -1,8 +1,8 @@ -## as.phylo.R (2010-12-15) +## as.phylo.R (2011-03-16) ## Conversion Among Tree Objects -## Copyright 2005-2010 Emmanuel Paradis +## Copyright 2005-2011 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -110,3 +110,24 @@ as.hclust.phylo <- function(x, ...) class(obj) <- "hclust" obj } + +as.network.phylo <- function(x, directed = is.rooted(x), ...) +{ + if (is.null(x$node.label)) x <- makeNodeLabel(x) + res <- network(x$edge, directed = directed, ...) + network.vertex.names(res) <- c(x$tip.label, x$node.label) + res +} + +as.igraph <- function(x, ...) UseMethod("as.igraph") + +as.igraph.phylo <- function(x, directed = is.rooted(x), use.labels = TRUE, ...) +{ + ## local copy because x will be changed before evaluating is.rooted(x): + directed <- directed + if (use.labels) { + if (is.null(x$node.label)) x <- makeNodeLabel(x) + x$edge <- matrix(c(x$tip.label, x$node.label)[x$edge], ncol = 2) + } else x$edge <- x$edge - 1L + graph.edgelist(x$edge, directed = directed, ...) +}