From cb4cf2223925527306ed925b6bffeca549691f7c Mon Sep 17 00:00:00 2001 From: xiangpin Date: Mon, 8 Mar 2021 17:46:20 +0800 Subject: [PATCH 1/3] update read.beast --- R/beast.R | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/R/beast.R b/R/beast.R index d0b9f9e..68db8a2 100644 --- a/R/beast.R +++ b/R/beast.R @@ -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) @@ -184,12 +192,17 @@ read.stats_beast_internal <- function(beast, tree) { stats <- sub("^&", "", stats) stats <- sub("];*$", "", stats) stats <- gsub("\"", "", stats) - + stats2 <- lapply(seq_along(stats), function(i) { x <- stats[[i]] y <- unlist(strsplit(x, ",")) - sidx <- grep("=\\{", y) - eidx <- grep("\\}$", y) + # the stats information has not always {} + #sidx <- grep("=\\{", y) + #eidx <- grep("\\}$", y) + # [&mutation="test1,test2",rate=80,90] + sidx <- grep("=", y) + eidx <- sidx - 1 + eidx <- c(eidx[-1], length(y)) flag <- FALSE if (length(sidx) > 0) { From 2938b4d1f53d790822cdc72673fea28d9f73d6bd Mon Sep 17 00:00:00 2001 From: xiangpin Date: Tue, 9 Mar 2021 15:51:16 +0800 Subject: [PATCH 2/3] better parse single value to single key in stats infor of beast --- R/beast.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/beast.R b/R/beast.R index 68db8a2..04d71cb 100644 --- a/R/beast.R +++ b/R/beast.R @@ -192,18 +192,21 @@ read.stats_beast_internal <- function(beast, tree) { stats <- sub("^&", "", stats) stats <- sub("];*$", "", stats) stats <- gsub("\"", "", stats) - + stats2 <- lapply(seq_along(stats), function(i) { x <- stats[[i]] y <- unlist(strsplit(x, ",")) - # the stats information has not always {} + # the stats information does not has always {} #sidx <- grep("=\\{", y) #eidx <- grep("\\}$", y) # [&mutation="test1,test2",rate=80,90] - sidx <- grep("=", y) - eidx <- sidx - 1 - eidx <- c(eidx[-1], length(y)) - + 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 From bf379f92b383c3420b0bdda72cfa7305db80aa40 Mon Sep 17 00:00:00 2001 From: xiangpin Date: Wed, 10 Mar 2021 10:09:34 +0800 Subject: [PATCH 3/3] remove elements before = in values of annotation --- R/beast.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/beast.R b/R/beast.R index 04d71cb..be532e5 100644 --- a/R/beast.R +++ b/R/beast.R @@ -212,7 +212,9 @@ read.stats_beast_internal <- function(beast, tree) { 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])