[Phylobase-commits] r444 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 25 22:12:15 CEST 2009


Author: regetz
Date: 2009-06-25 22:12:15 +0200 (Thu, 25 Jun 2009)
New Revision: 444

Modified:
   pkg/R/class-phylo4.R
   pkg/man/phylo4.Rd
Log:
* added phylo4 method for importing phylo objects, with an option to
  drop node labels (useful when phylo tree has invalid or messy names)
* removed automatic conversion of numeric node labels to data in the
  phylo4 method for matrix (to be reinstated in a phylo4d method)


Modified: pkg/R/class-phylo4.R
===================================================================
--- pkg/R/class-phylo4.R	2009-06-25 19:56:31 UTC (rev 443)
+++ pkg/R/class-phylo4.R	2009-06-25 20:12:15 UTC (rev 444)
@@ -96,37 +96,24 @@
     res at edge.length <- edge.length
     res at Nnode <- nnodes
     res at tip.label <- tip.label
+    res at node.label <- node.label
     res at edge.label <- edge.label
     res at order <- order
 
-    ## Tweak to deal with numerical values returned as node labels (ie. MrBayes)
-    if(!all(is.na(node.label)) && any(nchar(node.label) > 0) &&
-            !length(grep("[a-zA-Z]", node.label))) {
-        warning("All node labels are numeric values and converted as data.")
-        res at node.label <- character(0)
-        node.data <- node.label
+    ## checkPhylo4 will return a character string if object is
+    ##  bad, otherwise TRUE
+    if (is.character(checkval <- checkPhylo4(res))) stop(checkval)
 
-        node.data[!nzchar(node.data)] <- NA
+    return(res)
+})
 
-        node.label <- character(nnodes)
-        is.na(node.label) <- TRUE
+## first arg is a phylo
+setMethod("phylo4", c("phylo"), function(x, check.node.labels=c("keep",
+  "drop")){
 
-        node.data <- data.frame(labelValues=as.numeric(node.data))
-        res at node.label <- node.label
+  check.node.labels <- match.arg(check.node.labels)
+  if (check.node.labels == "drop") x$node.label <- NULL
+  res <- as(x, "phylo4")
 
-        res <- phylo4d(res, node.data=node.data, use.node.names=FALSE)
-        if(is.character(checkval <- checkPhylo4(res))) stop(checkval)
-
-        return(res)
-
-    }
-    else {
-        res at node.label <- node.label
-        ## checkPhylo4 will return a character string if object is
-        ##  bad, otherwise TRUE
-        if (is.character(checkval <- checkPhylo4(res))) stop(checkval)
-    }
-
-    return(res)
+  return(res)
 })
-

Modified: pkg/man/phylo4.Rd
===================================================================
--- pkg/man/phylo4.Rd	2009-06-25 19:56:31 UTC (rev 443)
+++ pkg/man/phylo4.Rd	2009-06-25 20:12:15 UTC (rev 444)
@@ -3,6 +3,7 @@
 \alias{phylo4}
 \alias{phylo4-methods}
 \alias{phylo4,matrix-method}
+\alias{phylo4,phylo-method}
 \title{Create a phylogenetic tree}
 \description{
   \code{phylo4} is a generic constructor that creates a phylogenetic tree object for use in phylobase methods. Phylobase contains functions for input of phylogenetic trees and data, manipulation of these objects including pruning and subsetting, and plotting. The phylobase package also contains translation functions to forms used in other comparative phylogenetic method packages.
@@ -11,13 +12,18 @@
   \describe{
      \item{x = "matrix"}{creates a phylobase tree from a matrix of
        edges}
+
+     \item{x = "phylo"}{creates a phylobase tree from an object of class
+       \code{phylo}}
    }}
 \usage{
      \S4method{phylo4}{matrix}(x, edge.length = NULL, tip.label = NULL, node.label = NULL,
         edge.label = NULL,  order="unknown", ...)
+     \S4method{phylo4}{phylo}(x, check.node.labels = c("keep", "drop"), ...)
 }
 \arguments{
-  \item{x}{a matrix of edges}
+  \item{x}{a matrix of edges or an object of class \code{phylo} (see
+    above)}
   \item{edge}{A numeric, two-column matrix with as many rows as branches in the phylogeny.}
   \item{edge.length}{Edge (branch) length. (Optional)}
   \item{tip.label}{A character vector of species names (names of "tip" nodes). (Optional)}
@@ -27,6 +33,9 @@
       listed in \code{phylo4_ordering}, currently "unknown", "reorder"
       (="pruningwise" in \code{ape}), "postorder" (="cladewise" in
       \code{ape}))}
+  \item{check.node.labels}{if \code{x} is of class \code{phylo}, either
+    "keep" (the default) or "drop" node labels. This argument is useful
+    if the \code{phylo} object has non-unique node labels.}
   \item{\dots}{fixme?}
 }
 \details{



More information about the Phylobase-commits mailing list