[Phylobase-commits] r846 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 12 19:45:24 CET 2014
Author: francois
Date: 2014-02-12 19:45:24 +0100 (Wed, 12 Feb 2014)
New Revision: 846
Modified:
pkg/R/readNCL.R
pkg/man/readNCL.Rd
Log:
adding option convert.edge.length to readNCL to convert negative branch lengths to 0 so that objects can be imported into phylobase
Modified: pkg/R/readNCL.R
===================================================================
--- pkg/R/readNCL.R 2014-02-12 18:34:20 UTC (rev 845)
+++ pkg/R/readNCL.R 2014-02-12 18:45:24 UTC (rev 846)
@@ -8,11 +8,12 @@
levels.uniform=FALSE, quiet=TRUE,
check.node.labels=c("keep", "drop", "asdata"),
return.labels=TRUE, file.format=c("nexus", "newick"),
- check.names=TRUE, ...) {
+ check.names=TRUE, convert.edge.length=FALSE, ...) {
## turn on to TRUE to test new way of building trees in NCL
experimental <- FALSE
+ file <- path.expand(file)
type <- match.arg(type)
check.node.labels <- match.arg(check.node.labels)
file.format <- match.arg(file.format)
@@ -144,6 +145,9 @@
tr$tip.label <- ncl$taxaNames[as.numeric(tr$tip.label)]
}
else stop("phylobase doesn't deal with multiple taxa block at this time.")
+ if (convert.edge.length) {
+ tr$edge.length[tr$edge.length < 0] <- 0
+ }
if (is.null(tr$node.label)) {
if (check.node.labels == "asdata") {
warning("Could not use value \"asdata\" for ",
@@ -169,6 +173,9 @@
edgeMat <- cbind(ncl$parentVector, c(1:length(ncl$parentVector)))
edgeLgth <- ncl$branchLengthVector
edgeLgth[edgeLgth == -1] <- NA
+ if (convert.edge.length) {
+ edgeLgth[edgeLgth < 0] <- 0
+ }
if (length(ncl$taxaNames) != min(ncl$parentVector)-1) {
stop("phylobase doesn't deal with multiple taxa block at this time.")
}
@@ -224,18 +231,21 @@
char.all=FALSE, polymorphic.convert=TRUE,
levels.uniform=FALSE, quiet=TRUE,
check.node.labels=c("keep", "drop", "asdata"),
- return.labels=TRUE, check.names=TRUE, ...) {
+ return.labels=TRUE, check.names=TRUE, convert.edge.length=FALSE,
+ ...) {
return(readNCL(file=file, simplify=simplify, type=type, char.all=char.all,
polymorphic.convert=polymorphic.convert, levels.uniform=levels.uniform,
quiet=quiet, check.node.labels=check.node.labels,
return.labels=return.labels, file.format="nexus",
- check.names=check.names, ...))
+ check.names=check.names, convert.edge.length=convert.edge.length, ...))
}
readNewick <- function(file, simplify=FALSE, quiet=TRUE,
- check.node.labels=c("keep", "drop", "asdata"), ...) {
+ check.node.labels=c("keep", "drop", "asdata"),
+ convert.edge.length=FALSE, ...) {
return(readNCL(file=file, simplify=simplify, quiet=quiet,
- check.node.labels=check.node.labels, file.format="newick", ...))
+ check.node.labels=check.node.labels, file.format="newick",
+ convert.edge.length=convert.edge.length, ...))
}
Modified: pkg/man/readNCL.Rd
===================================================================
--- pkg/man/readNCL.Rd 2014-02-12 18:34:20 UTC (rev 845)
+++ pkg/man/readNCL.Rd 2014-02-12 18:45:24 UTC (rev 846)
@@ -19,10 +19,12 @@
readNexus(file, simplify=FALSE, type=c("all", "tree", "data"),
char.all=FALSE, polymorphic.convert=TRUE, levels.uniform=FALSE,
quiet=TRUE, check.node.labels=c("keep", "drop", "asdata"),
- return.labels=TRUE, check.names=TRUE, ...)
+ return.labels=TRUE, check.names=TRUE, convert.edge.length=FALSE,
+ ...)
readNewick(file, simplify=FALSE, quiet=TRUE,
- check.node.labels=c("keep", "drop", "asdata"), ...)
+ check.node.labels=c("keep", "drop", "asdata"),
+ convert.edge.length=FALSE, ...)
}
@@ -63,6 +65,12 @@
are syntactically valid variable names and are not duplicated.
If necessary they are adjusted (by \sQuote{make.names}) so
that they are.}
+
+ \item{convert.edge.length}{logical. If \sQuote{TRUE} negative edge
+ lengths are replaced with 0. At this time \code{phylobase} does not
+ accept objects with negative branch lengths, this workaround allows
+ to still use trees with negative branch lengths are an artifact of
+ the method used to build the tree.}
\item{\dots}{Additional arguments to be passed to phylo4 or phylo4d
constructor (see Details)}
More information about the Phylobase-commits
mailing list