Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed bug when some node labels are blank in read.beast #63

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(filenamer,filename)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
importFrom(magrittr,"%>%")
Expand All @@ -170,6 +171,7 @@ importFrom(methods,missingArg)
importFrom(methods,new)
importFrom(methods,setGeneric)
importFrom(methods,slot)
importFrom(purrr,is_numeric)
importFrom(rlang,.data)
importFrom(rlang,enexpr)
importFrom(rlang,quo)
Expand Down
7 changes: 7 additions & 0 deletions R/beast.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ read.beast.newick <- function(file) {
return(obj)
}

#' @importFrom filenamer filename
BEAST <- function(file, treetext, stats, phylo) {
stats$node <- gsub("\"*'*", "", stats$node)

Expand Down Expand Up @@ -142,6 +143,7 @@ read.stats_beast <- function(beast, trees) {



##' @importFrom purrr is_numeric
read.stats_beast_internal <- function(beast, tree) {
##tree <- gsub(" ", "", tree)
## tree2 <- gsub("\\[[^\\[]*\\]", "", tree)
Expand Down Expand Up @@ -350,6 +352,11 @@ add_pseudo_nodelabel <- function(phylo) {
## treetext)
## }
}
# assign blank labels
if (any(phylo$node.label == "")) {
blanks <- sum(phylo$node.label == "")
phylo$node.label[phylo$node.label == ""] <- paste("X", 1:blanks, sep="")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this method can solve the problem. when the tree contained X1 of node label or the same node label. This method can't also solve the problem.

for example

> xx <- '((1[&x="1"]:1,2[&x="2"]:1)5[&x="3"]:1,(3[&x="4"]:1,4[&x="5"]:1)X1[&x="6"]:1)[&x="7"];'
> trda <- read.beast.newick(textConnection(xx))
> trda@data
# A tibble: 7 x 2
      x node
  <dbl> <chr>
1     1 1
2     2 2
3     3 6
4     4 3
5     5 4
6     6 5
7     7 5

I think all node.label can be replace with

nnode <- phylo$Nnode
phylo$node.label <- paste("X", 1:nnode, sep="")

Even node.label is not NULL sometimes. because the node.label does not effect the following calculation.

## if tip.label contains () which will broken node name extraction
phylo$tip.label <- gsub("[\\(\\)]", "_", phylo$tip.label)

Expand Down