Commit id: 14b025be7f7d5d1a895e5bee2012681ce984ba75
better performance of parsing beast tree
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@103617 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -1,5 +1,8 @@ |
1 | 1 |
CHANGES IN VERSION 1.1.4 |
2 | 2 |
------------------------ |
3 |
+ o better performance of parsing beast tree <2015-05-11, Mon> |
|
4 |
+ + support beast tree begin with 'tree tree_1 = ' and other forms. |
|
5 |
+ + support file that only contains one evidence for some of the nodes/tips |
|
3 | 6 |
o update add_colorbar to auto determine the position <2015-05-04, Mon> |
4 | 7 |
o add_colorbar function <2015-04-30, Thu> |
5 | 8 |
|
... | ... |
@@ -158,14 +158,22 @@ setMethod("get.fields", signature(object="beast"), |
158 | 158 |
read.treetext_beast <- function(file) { |
159 | 159 |
beast <- readLines(file) |
160 | 160 |
ii <- grep("tree TREE1\\s+=", beast) |
161 |
+ if (length(ii) == 0) { |
|
162 |
+ ii <- grep("begin trees;", beast) |
|
163 |
+ } |
|
164 |
+ |
|
161 | 165 |
jj <- grep("[Ee]nd;", beast) |
162 | 166 |
jj <- jj[jj > ii][1] |
163 | 167 |
tree <- beast[ii:(jj-1)] |
164 | 168 |
if (length(tree) > 1) { |
165 | 169 |
tree <- paste0(tree) |
166 | 170 |
} |
167 |
- tree %<>% sub("tree TREE1\\s+=\\s+\\[&R\\]\\s+", "", .) |
|
168 |
- tree %<>% sub("[^(]*", "", .) |
|
171 |
+ ## tree %<>% sub("tree TREE1\\s+=\\s+\\[&R\\]\\s+", "", .) |
|
172 |
+ ## tree %<>% sub("[^(]*", "", .) |
|
173 |
+ tree %<>% sub("[^=]+=", "", .) %>% |
|
174 |
+ sub("\\s+\\[&R\\]\\s+", "", .) %>% |
|
175 |
+ sub("[^(]*", "", .) |
|
176 |
+ |
|
169 | 177 |
return(tree) |
170 | 178 |
} |
171 | 179 |
|
... | ... |
@@ -258,10 +266,13 @@ read.stats_beast <- function(file) { |
258 | 266 |
root:(root+nnode-1)) |
259 | 267 |
node <- label2[match(nn, treeinfo$label)] |
260 | 268 |
|
269 |
+ ## stats <- unlist(strsplit(tree, "\\["))[-1] |
|
270 |
+ ## stats <- sub(":.+$", "", stats |
|
271 |
+ stats <- strsplit(tree, ":") %>% unlist |
|
272 |
+ names(stats) <- node |
|
273 |
+ stats <- stats[grep("\\[", stats)] |
|
274 |
+ stats <- sub("[^\\[]+\\[", "", stats) |
|
261 | 275 |
|
262 |
- |
|
263 |
- stats <- unlist(strsplit(tree, "\\["))[-1] |
|
264 |
- stats <- sub(":.+$", "", stats) |
|
265 | 276 |
stats <- sub("^&", "", stats) |
266 | 277 |
stats <- sub("];*$", "", stats) |
267 | 278 |
|
... | ... |
@@ -323,9 +334,17 @@ read.stats_beast <- function(file) { |
323 | 334 |
})) |
324 | 335 |
|
325 | 336 |
stats3 <- as.data.frame(stats3) |
337 |
+ if (nrow(stats3) == 1) { |
|
338 |
+ ## only has one evidence |
|
339 |
+ ## transpose |
|
340 |
+ stats3 <- data.frame(X=unlist(stats3[1,])) |
|
341 |
+ colnames(stats3) <- nn |
|
342 |
+ } |
|
326 | 343 |
colnames(stats3) <- gsub("(\\d+)%", "0.\\1", colnames(stats3)) |
327 | 344 |
|
328 |
- stats3$node <- node |
|
345 |
+ ## stats3$node <- node |
|
346 |
+ stats3$node <- names(stats) |
|
329 | 347 |
return(stats3) |
330 | 348 |
} |
331 | 349 |
|
350 |
+ |
... | ... |
@@ -185,9 +185,14 @@ fortify.beast <- function(model, data, |
185 | 185 |
|
186 | 186 |
idx <- match(df$node, stats$node) |
187 | 187 |
stats <- stats[idx,] |
188 |
- stats <- stats[,colnames(stats) != "node"] |
|
188 |
+ cn_stats <- colnames(stats) |
|
189 |
+ stats <- stats[, cn_stats != "node"] |
|
189 | 190 |
|
190 | 191 |
df <- cbind(df, stats) |
192 |
+ if (is(stats, "data.frame") == FALSE) { |
|
193 |
+ colnames(df)[colnames(df) == "stats"] <- cn_stats[cn_stats != "node"] |
|
194 |
+ } |
|
195 |
+ |
|
191 | 196 |
df <- scaleY(phylo, df, yscale, layout, ...) |
192 | 197 |
|
193 | 198 |
if (time_scale) { |