Browse code

version 1.5.5

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@118092 bc3139a8-67e5-0310-9ffc-ced21a209358

Guangchuang Yu authored on 02/06/2016 03:14:43
Showing 12 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: a phylogenetic tree viewer for different types of tree annotations
4
-Version: 1.5.4
4
+Version: 1.5.5
5 5
 Author: Guangchuang Yu and Tommy Tsan-Yuk Lam
6 6
 Maintainer: Guangchuang Yu <guangchuangyu@gmail.com>
7 7
 Description: ggtree extends the ggplot2 plotting system which implemented the
... ...
@@ -1,5 +1,12 @@
1
+CHANGES IN VERSION 1.5.5
2
+------------------------
3
+ o bug fixed if time-scaled tree extend into the BCE. <2016-06-02, Thu>
4
+   + as.Date won't work for BCE time.
5
+   + as.Date=FALSE by default in fortify method, just use the time in decimal format (real number, not Date object).
6
+ 
1 7
 CHANGES IN VERSION 1.5.4
2 8
 ------------------------
9
+ o reroot method for raxml object <2016-05-22, Sun>
3 10
  o bug fixed in scaleClade, now y positions are (hopefully) always correct. <2016-05-20, Fri>
4 11
  o bug fixed in collapse <2016-05-20, Fri>
5 12
    + if user collapse a node that is an offspring of a collapsed node, print warning msg and return the tree directly
... ...
@@ -1,3 +1,31 @@
1
+## not used.
2
+## we don't guess mrsd from tip labels
3
+## user should provide mrsd parameter in ggtree if they want to use time-scaled tree
4
+scaleX_by_time <- function(df, as.Date=FALSE) {
5
+    time <- with(df, gsub(".*[_/]{1}(\\d+\\.*\\d+)$", "\\1", label[isTip])) %>% as.numeric
6
+    latest <- which.max(time)
7
+
8
+    scaleX_by_time_from_mrsd(df, decimal2Date(time[latest]), as.Date)
9
+}
10
+
11
+
12
+scaleX_by_time_from_mrsd <- function(df, mrsd, as.Date) {
13
+    mrsd %<>% as.Date
14
+    date <- Date2decimal(mrsd)
15
+
16
+    df$x <- df$x + date - max(df$x)
17
+    df$branch <- (df[df$parent, "x"] + df[, "x"])/2
18
+
19
+    if (as.Date) {
20
+        df$x <- decimal2Date(df$x)
21
+        df$branch <- decimal2Date(df$branch)
22
+    }
23
+    
24
+    return(df)
25
+}
26
+
27
+
28
+
1 29
 ##' convert Date to decimal format, eg "2014-05-05" to "2014.34"
2 30
 ##'
3 31
 ##' 
... ...
@@ -289,17 +289,4 @@ add_pseudo_nodelabel <- function(phylo, treetext) {
289 289
 }
290 290
 
291 291
 
292
-##' @rdname reroot-methods
293
-##' @exportMethod reroot
294
-setMethod("reroot", signature(object="beast"),
295
-          function(object, node, ...) {
296
-              object@phylo <- reroot(object@phylo, node, ...)
297
-
298
-              node_map <- attr(object@phylo, "node_map")
299
-              idx <- match(object@stats$node, node_map[,1])
300
-              object@stats$node <- node_map[idx, 2]
301
-              
302
-              return(object)
303
-          })
304
-
305 292
 
... ...
@@ -211,26 +211,6 @@ fortify.beast <- function(model, data,
211 211
     append_extraInfo(df, model)
212 212
 }
213 213
 
214
-scaleX_by_time_from_mrsd <- function(df, mrsd) {
215
-    mrsd %<>% as.Date
216
-    date <- Date2decimal(mrsd)
217
-
218
-    df$x <- df$x + date - max(df$x)
219
-    df$branch <- (df[df$parent, "x"] + df[, "x"])/2
220
-    
221
-    df$x <- decimal2Date(df$x)
222
-    df$branch <- decimal2Date(df$branch)
223
-    return(df)
224
-
225
-}
226
-
227
-
228
-scaleX_by_time <- function(df) {
229
-    time <- with(df, gsub(".*[_/]{1}(\\d+\\.*\\d+)$", "\\1", label[isTip])) %>% as.numeric
230
-    latest <- which.max(time)
231
-
232
-    scaleX_by_time_from_mrsd(df, decimal2Date(time[latest]))
233
-}
234 214
 
235 215
 ##' @method fortify codeml
236 216
 ##' @export
... ...
@@ -499,11 +479,7 @@ fortify.phylo <- function(model, data, layout="rectangular",
499 479
     }
500 480
     
501 481
     if (!is.null(mrsd)) {
502
-        df <- scaleX_by_time_from_mrsd(df, mrsd)
503
-        if (!as.Date) {
504
-            df$x <- Date2decimal(df$x)
505
-            df$branch <- Date2decimal(df$branch)
506
-        }
482
+        df <- scaleX_by_time_from_mrsd(df, mrsd, as.Date)
507 483
     }
508 484
     return(df)
509 485
 }
... ...
@@ -59,3 +59,9 @@ setMethod("get.tree", signature(object="phylip"),
59 59
           }
60 60
           )
61 61
 
62
+##' @rdname get.tree-methods
63
+##' @exportMethod get.tree
64
+setMethod("get.tree", signature(object="phylo"),
65
+          function(object, ...) {
66
+              return(object)
67
+          })
62 68
new file mode 100644
... ...
@@ -0,0 +1,50 @@
1
+
2
+##' @rdname reroot-methods
3
+##' @exportMethod reroot
4
+setMethod("reroot", signature(object="beast"),
5
+          function(object, node, ...) {
6
+              object@phylo <- reroot(object@phylo, node, ...)
7
+
8
+              node_map <- attr(object@phylo, "node_map")
9
+              idx <- match(object@stats$node, node_map[,1])
10
+              object@stats$node <- node_map[idx, 2]
11
+              
12
+              return(object)
13
+          })
14
+
15
+##' @rdname reroot-methods
16
+##' @exportMethod reroot
17
+setMethod("reroot", signature(object="raxml"),
18
+          function(object, node, ...) {
19
+              object@phylo <- reroot(object@phylo, node, ...)
20
+
21
+              node_map <- attr(object@phylo, "node_map")
22
+              idx <- match(object@bootstrap$node, node_map[,1])
23
+              object@bootstrap$node <- node_map[idx, 2]
24
+              
25
+              return(object)
26
+          })
27
+
28
+
29
+##' reroot a tree
30
+##'
31
+##' 
32
+##' @rdname reroot-methods
33
+##' @exportMethod reroot
34
+setMethod("reroot", signature(object="phylo"),
35
+          function(object, node, ...) {
36
+              pos <- 0.5* object$edge.length[which(object$edge[,2] == node)]
37
+
38
+              ## @importFrom phytools reroot
39
+              phytools <- "phytools"
40
+              require(phytools, character.only = TRUE)
41
+              
42
+              phytools_reroot <- eval(parse(text="phytools::reroot"))
43
+
44
+              tree <- phytools_reroot(object, node, pos)
45
+              attr(tree, "reroot") <- TRUE
46
+              node_map <- reroot_node_mapping(object, tree)
47
+              attr(tree, "node_map") <- node_map
48
+              return(tree)
49
+          })
50
+
... ...
@@ -24,6 +24,12 @@ setMethod("scale_color", signature(object="paml_rst"),
24 24
           })
25 25
 
26 26
 
27
+##' @rdname scale_color-methods
28
+##' @exportMethod scale_color
29
+setMethod("scale_color", signature(object="phylo"),
30
+          function(object, by, ...) {
31
+              scale_color_(object, by, ...)
32
+          })
27 33
 
28 34
 
29 35
 ##' add colorbar legend
30 36
deleted file mode 100644
... ...
@@ -1,42 +0,0 @@
1
-##' reroot a tree
2
-##'
3
-##' 
4
-##' @rdname reroot-methods
5
-##' @exportMethod reroot
6
-setMethod("reroot", signature(object="phylo"),
7
-          function(object, node, ...) {
8
-              pos <- 0.5* object$edge.length[which(object$edge[,2] == node)]
9
-
10
-              ## @importFrom phytools reroot
11
-              phytools <- "phytools"
12
-              require(phytools, character.only = TRUE)
13
-              
14
-              phytools_reroot <- eval(parse(text="phytools::reroot"))
15
-
16
-              tree <- phytools_reroot(object, node, pos)
17
-              attr(tree, "reroot") <- TRUE
18
-              node_map <- reroot_node_mapping(object, tree)
19
-              attr(tree, "node_map") <- node_map
20
-              return(tree)
21
-          })
22
-
23
-
24
-
25
-##' @rdname get.tree-methods
26
-##' @exportMethod get.tree
27
-setMethod("get.tree", signature(object="phylo"),
28
-          function(object, ...) {
29
-              return(object)
30
-          })
31
-
32
-##' @rdname scale_color-methods
33
-##' @exportMethod scale_color
34
-setMethod("scale_color", signature(object="phylo"),
35
-          function(object, by, ...) {
36
-              scale_color_(object, by, ...)
37
-          })
38
-
39
-
40
-
41
-
42
-
... ...
@@ -1,5 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/AllGenerics.R, R/RAxML.R, R/codeml_mlc.R, R/hyphy.R, R/method-get-tree.R, R/paml_rst.R, R/phangorn.R, R/phylo.R, R/r8s.R
2
+% Please edit documentation in R/AllGenerics.R, R/RAxML.R, R/codeml_mlc.R, R/hyphy.R, R/method-get-tree.R, R/paml_rst.R, R/phangorn.R, R/r8s.R
3 3
 \docType{methods}
4 4
 \name{get.tree}
5 5
 \alias{get.tree}
... ...
@@ -38,12 +38,12 @@ get.tree(object, ...)
38 38
 
39 39
 \S4method{get.tree}{phylip}(object, ...)
40 40
 
41
+\S4method{get.tree}{phylo}(object, ...)
42
+
41 43
 \S4method{get.tree}{paml_rst}(object)
42 44
 
43 45
 \S4method{get.tree}{phangorn}(object, ...)
44 46
 
45
-\S4method{get.tree}{phylo}(object, ...)
46
-
47 47
 \S4method{get.tree}{r8s}(object, ...)
48 48
 }
49 49
 \arguments{
... ...
@@ -1,16 +1,19 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/AllGenerics.R, R/beast.R, R/phylo.R
2
+% Please edit documentation in R/AllGenerics.R, R/method-reroot.R
3 3
 \docType{methods}
4 4
 \name{reroot}
5 5
 \alias{reroot}
6 6
 \alias{reroot,beast-method}
7 7
 \alias{reroot,phylo-method}
8
+\alias{reroot,raxml-method}
8 9
 \title{reroot method}
9 10
 \usage{
10 11
 reroot(object, node, ...)
11 12
 
12 13
 \S4method{reroot}{beast}(object, node, ...)
13 14
 
15
+\S4method{reroot}{raxml}(object, node, ...)
16
+
14 17
 \S4method{reroot}{phylo}(object, node, ...)
15 18
 }
16 19
 \arguments{
... ...
@@ -1,5 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/AllGenerics.R, R/RAxML.R, R/ape.R, R/codeml.R, R/codeml_mlc.R, R/hyphy.R, R/jplace.R, R/method-scale-color.R, R/phangorn.R, R/phylo.R, R/r8s.R
2
+% Please edit documentation in R/AllGenerics.R, R/RAxML.R, R/ape.R, R/codeml.R, R/codeml_mlc.R, R/hyphy.R, R/jplace.R, R/method-scale-color.R, R/phangorn.R, R/r8s.R
3 3
 \docType{methods}
4 4
 \name{scale_color}
5 5
 \alias{scale_color}
... ...
@@ -37,10 +37,10 @@ scale_color(object, by, ...)
37 37
 
38 38
 \S4method{scale_color}{paml_rst}(object, by, ...)
39 39
 
40
-\S4method{scale_color}{phangorn}(object, by, ...)
41
-
42 40
 \S4method{scale_color}{phylo}(object, by, ...)
43 41
 
42
+\S4method{scale_color}{phangorn}(object, by, ...)
43
+
44 44
 \S4method{scale_color}{r8s}(object, by = "bootstrap", tree = "TREE")
45 45
 }
46 46
 \arguments{