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

update read.beast #48

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Changes from all commits
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
30 changes: 24 additions & 6 deletions R/beast.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,16 @@ read.stats_beast_internal <- function(beast, tree) {
## BEAST output
stats <- strsplit(tree, ":") %>% unlist
}

names(stats) <- node

# check whether the stats info is after edge length or not.
if (!all(grepl("]$", stats) || grepl("];$", stats))){
# t1:0.04[&mutation="test1"]
stats <- sub("].*", "", stats)
names(stats) <- c(rep(node[1],2),node[-c(1,length(node))])
}else{
# t1[&mutation="test1"]:0.04
names(stats) <- node
}

stats <- stats[grep("\\[", stats)]
stats <- sub("[^\\[]*\\[", "", stats)
Expand All @@ -188,15 +196,25 @@ read.stats_beast_internal <- function(beast, tree) {
stats2 <- lapply(seq_along(stats), function(i) {
x <- stats[[i]]
y <- unlist(strsplit(x, ","))
sidx <- grep("=\\{", y)
eidx <- grep("\\}$", y)

# the stats information does not has always {}
#sidx <- grep("=\\{", y)
#eidx <- grep("\\}$", y)
# [&mutation="test1,test2",rate=80,90]
sidx1 <- grep("=", y)
eidx1 <- sidx1 - 1
eidx1 <- c(eidx1[-1], length(y))
# for better parsing [&mutation="test",name="A"] single value to key.
sidx <- sidx1[!(sidx1==eidx1)]
eidx <- eidx1[!(sidx1==eidx1)]

flag <- FALSE
if (length(sidx) > 0) {
flag <- TRUE
SETS <- lapply(seq_along(sidx), function(k) {
p <- y[sidx[k]:eidx[k]]
gsub(".*=\\{", "", p) %>% gsub("\\}$", "", .)
gsub(".*=\\{", "", p) %>%
gsub("\\}$", "", .) %>%
gsub(".*=", "", .)
})
names(SETS) <- gsub("=.*", "", y[sidx])

Expand Down