X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fread.nexus.R;h=969d42c0e403c23c28bb459ecdc41dc1d2a3305c;hb=a03a8c554a6fde0dc4313688e3248bfae2e521e4;hp=8c9abc24002e57a27d36e064e92d5317d6f91fc5;hpb=bd53d983d5daf867bc50b00ace48d017506599ef;p=ape.git diff --git a/R/read.nexus.R b/R/read.nexus.R index 8c9abc2..969d42c 100644 --- a/R/read.nexus.R +++ b/R/read.nexus.R @@ -1,4 +1,4 @@ -## read.nexus.R (2009-10-27) +## read.nexus.R (2009-11-21) ## Read Tree File in Nexus Format @@ -9,12 +9,20 @@ .treeBuildWithTokens <- function(x) { + ## remove potential node labels; see ?read.nexus for justification + node.label <- gsub("[:;].*$", "", strsplit(x, ")")[[1]][-1]) + has.node.labels <- FALSE + if (any(node.label != "")) { + x <- gsub(")[^:]*:", "):", x) + x <- gsub(")[^:]*;", ");", x) # if there's no root edge + has.node.labels <- TRUE + } phy <- .Call("treeBuildWithTokens", x, PACKAGE = "ape") dim(phy[[1]]) <- c(length(phy[[1]])/2, 2) - nms <- c("edge", "edge.length", "Nnode", "node.label") - if (length(phy) == 5) nms <- c(nms, "root.edge") + nms <- c("edge", "edge.length", "Nnode", "root.edge") + if (length(phy) == 3) nms <- nms[-4] names(phy) <- nms - if (!sum(phy[[4]])) phy[[4]] <- NULL + if (has.node.labels) phy$node.label <- node.label class(phy) <- "phylo" phy }