Commit id: 06148bb3ff7d69f510bc9c3755ea80810415ad11
groupClade
git-svn-id: https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@100622 bc3139a8-67e5-0310-9ffc-ced21a209358
... | ... |
@@ -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: 0.99.24 |
|
4 |
+Version: 0.99.25 |
|
5 | 5 |
Author: Guangchuang Yu |
6 | 6 |
Maintainer: Guangchuang Yu <guangchuangyu@gmail.com> |
7 | 7 |
Description: ggtree extends the ggplot2 plotting system which implemented the |
... | ... |
@@ -16,9 +16,9 @@ export("%>%") |
16 | 16 |
export(.) |
17 | 17 |
export(aes) |
18 | 18 |
export(as.binary) |
19 |
-export(collapse_clade) |
|
19 |
+export(collapse) |
|
20 | 20 |
export(download.phylopic) |
21 |
-export(expand_clade) |
|
21 |
+export(expand) |
|
22 | 22 |
export(geom_aline) |
23 | 23 |
export(geom_hilight) |
24 | 24 |
export(geom_text) |
... | ... |
@@ -40,6 +40,7 @@ export(getRoot) |
40 | 40 |
export(ggplotGrob) |
41 | 41 |
export(ggtree) |
42 | 42 |
export(gplot) |
43 |
+export(groupClade) |
|
43 | 44 |
export(groupOTU) |
44 | 45 |
export(gzoom) |
45 | 46 |
export(hilight) |
... | ... |
@@ -71,6 +72,7 @@ exportMethods(get.tipseq) |
71 | 72 |
exportMethods(get.tree) |
72 | 73 |
exportMethods(get.treeinfo) |
73 | 74 |
exportMethods(get.treetext) |
75 |
+exportMethods(groupClade) |
|
74 | 76 |
exportMethods(groupOTU) |
75 | 77 |
exportMethods(gzoom) |
76 | 78 |
exportMethods(plot) |
... | ... |
@@ -1,3 +1,7 @@ |
1 |
+CHANGES IN VERSION 0.99.25 |
|
2 |
+------------------------ |
|
3 |
+ o implement groupClade <2015-03-13, Fri> |
|
4 |
+ |
|
1 | 5 |
CHANGES IN VERSION 0.99.24 |
2 | 6 |
------------------------ |
3 | 7 |
o use "round" segment end, look very better <2015-03-12, Thu> |
... | ... |
@@ -7,7 +11,7 @@ CHANGES IN VERSION 0.99.23 |
7 | 11 |
------------------------ |
8 | 12 |
o mv geom_hilight to hilight <2015-03-11, Wed> |
9 | 13 |
o mv geom_phylopic to phylopic <2015-03-11, Wed> |
10 |
- o implement collapse_clade and expand_clade for collapse and expand a selected clade <2015-03-11, Wed> |
|
14 |
+ o implement collapse and expand for collapse and expand a selected clade <2015-03-11, Wed> |
|
11 | 15 |
|
12 | 16 |
CHANGES IN VERSION 0.99.22 |
13 | 17 |
------------------------ |
... | ... |
@@ -114,6 +114,18 @@ setGeneric("get.tipseq", function(object, ...) standardGeneric("get.tipseq")) |
114 | 114 |
##' @export |
115 | 115 |
setGeneric("groupOTU", function(object, focus) standardGeneric("groupOTU")) |
116 | 116 |
|
117 |
+##' @docType methods |
|
118 |
+##' @name groupClade |
|
119 |
+##' @rdname groupClade-methods |
|
120 |
+##' @title groupClade method |
|
121 |
+##' @param object supported objects, including phylo, paml_rst, |
|
122 |
+##' codeml_mlc, codeml, jplace, beast, hyphy |
|
123 |
+##' @param node a internal node or a vector of internal nodes |
|
124 |
+##' @return group index |
|
125 |
+##' @export |
|
126 |
+setGeneric("groupClade", function(object, node) standardGeneric("groupClade")) |
|
127 |
+ |
|
128 |
+ |
|
117 | 129 |
##' @docType methods |
118 | 130 |
##' @name scale_color |
119 | 131 |
##' @rdname scale_color-methods |
... | ... |
@@ -97,6 +97,13 @@ setMethod("groupOTU", signature(object="beast"), |
97 | 97 |
} |
98 | 98 |
) |
99 | 99 |
|
100 |
+##' @rdname groupClade-methods |
|
101 |
+##' @exportMethod groupClade |
|
102 |
+setMethod("groupClade", signature(object="beast"), |
|
103 |
+ function(object, node) { |
|
104 |
+ groupClade_(object, node) |
|
105 |
+ }) |
|
106 |
+ |
|
100 | 107 |
##' @rdname scale_color-methods |
101 | 108 |
##' @exportMethod scale_color |
102 | 109 |
setMethod("scale_color", signature(object="beast"), |
... | ... |
@@ -30,6 +30,15 @@ setMethod("groupOTU", signature(object="codeml"), |
30 | 30 |
} |
31 | 31 |
) |
32 | 32 |
|
33 |
+##' @rdname groupClade-methods |
|
34 |
+##' @exportMethod groupClade |
|
35 |
+setMethod("groupClade", signature(object="codeml"), |
|
36 |
+ function(object, node) { |
|
37 |
+ groupClade_(object, node) |
|
38 |
+ } |
|
39 |
+ ) |
|
40 |
+ |
|
41 |
+ |
|
33 | 42 |
##' @rdname scale_color-methods |
34 | 43 |
##' @exportMethod scale_color |
35 | 44 |
setMethod("scale_color", signature(object="codeml"), |
... | ... |
@@ -39,6 +39,15 @@ setMethod("groupOTU", signature(object="codeml_mlc"), |
39 | 39 |
} |
40 | 40 |
) |
41 | 41 |
|
42 |
+##' @rdname groupClade-methods |
|
43 |
+##' @exportMethod groupClade |
|
44 |
+setMethod("groupClade", signature(object="codeml_mlc"), |
|
45 |
+ function(object, node) { |
|
46 |
+ groupClade_(object, node) |
|
47 |
+ } |
|
48 |
+ ) |
|
49 |
+ |
|
50 |
+ |
|
42 | 51 |
##' @rdname scale_color-methods |
43 | 52 |
##' @exportMethod scale_color |
44 | 53 |
setMethod("scale_color", signature(object="codeml_mlc"), |
... | ... |
@@ -94,6 +94,7 @@ ggtree <- function(tr, |
94 | 94 |
##' ggplot(tr) + geom_tree() |
95 | 95 |
geom_tree <- function(layout="phylogram", color="black", linetype="solid", size=0.5, ...) { |
96 | 96 |
x <- y <- parent <- NULL |
97 |
+ lineend = "round" |
|
97 | 98 |
if (layout == "phylogram" || layout == "fan") { |
98 | 99 |
if (length(color) != 1) { |
99 | 100 |
color <- c(color, color) |
... | ... |
@@ -111,7 +112,7 @@ geom_tree <- function(layout="phylogram", color="black", linetype="solid", size= |
111 | 112 |
color = color, |
112 | 113 |
linetype = linetype, |
113 | 114 |
size = size, |
114 |
- lineend = "round", ...) |
|
115 |
+ lineend = lineend, ...) |
|
115 | 116 |
} else if (layout == "cladogram" || layout == "unrooted") { |
116 | 117 |
geom_segment(aes(x = x[parent], |
117 | 118 |
xend = x, |
... | ... |
@@ -119,7 +120,8 @@ geom_tree <- function(layout="phylogram", color="black", linetype="solid", size= |
119 | 120 |
yend = y), |
120 | 121 |
color = color, |
121 | 122 |
linetype = linetype, |
122 |
- size = size, ...) |
|
123 |
+ size = size, |
|
124 |
+ lineend = lineend, ...) |
|
123 | 125 |
} |
124 | 126 |
} |
125 | 127 |
|
... | ... |
@@ -296,13 +298,14 @@ hilight <- function(tree_view, node, fill="steelblue", alpha=0.5, ...) { |
296 | 298 |
##' collapse a clade |
297 | 299 |
##' |
298 | 300 |
##' |
299 |
-##' @title collapse_clade |
|
301 |
+##' @title collapse |
|
300 | 302 |
##' @param tree_view tree view |
301 | 303 |
##' @param node clade node |
302 | 304 |
##' @return tree view |
303 | 305 |
##' @export |
306 |
+##' @seealso expand |
|
304 | 307 |
##' @author Guangchuang Yu |
305 |
-collapse_clade <- function(tree_view, node) { |
|
308 |
+collapse <- function(tree_view, node) { |
|
306 | 309 |
df <- tree_view$data |
307 | 310 |
sp <- get.offspring.df(df, node) |
308 | 311 |
sp.df <- df[sp,] |
... | ... |
@@ -336,13 +339,14 @@ collapse_clade <- function(tree_view, node) { |
336 | 339 |
##' expand collased clade |
337 | 340 |
##' |
338 | 341 |
##' |
339 |
-##' @title expand_clade |
|
342 |
+##' @title expand |
|
340 | 343 |
##' @param tree_view tree view |
341 | 344 |
##' @param node clade node |
342 | 345 |
##' @return tree view |
343 | 346 |
##' @export |
347 |
+##' @seealso collapse |
|
344 | 348 |
##' @author Guangchuang Yu |
345 |
-expand_clade <- function(tree_view, node) { |
|
349 |
+expand <- function(tree_view, node) { |
|
346 | 350 |
clade <- paste0("clade_", node) |
347 | 351 |
sp.df <- attr(tree_view, clade) |
348 | 352 |
if (is.null(sp.df)) { |
... | ... |
@@ -97,6 +97,14 @@ setMethod("groupOTU", signature(object="hyphy"), |
97 | 97 |
} |
98 | 98 |
) |
99 | 99 |
|
100 |
+##' @rdname groupClade-methods |
|
101 |
+##' @exportMethod groupClade |
|
102 |
+setMethod("groupClade", signature(object="hyphy"), |
|
103 |
+ function(object, node) { |
|
104 |
+ groupClade_(object, node) |
|
105 |
+ } |
|
106 |
+ ) |
|
107 |
+ |
|
100 | 108 |
##' @rdname scale_color-methods |
101 | 109 |
##' @exportMethod scale_color |
102 | 110 |
setMethod("scale_color", signature(object="hyphy"), |
... | ... |
@@ -34,6 +34,15 @@ setMethod("groupOTU", signature(object="jplace"), |
34 | 34 |
} |
35 | 35 |
) |
36 | 36 |
|
37 |
+##' @rdname groupClade-methods |
|
38 |
+##' @exportMethod groupClade |
|
39 |
+setMethod("groupClade", signature(object="jplace"), |
|
40 |
+ function(object, node) { |
|
41 |
+ groupClade_(object, node) |
|
42 |
+ } |
|
43 |
+ ) |
|
44 |
+ |
|
45 |
+ |
|
37 | 46 |
##' @rdname scale_color-methods |
38 | 47 |
##' @exportMethod scale_color |
39 | 48 |
setMethod("scale_color", signature(object="jplace"), |
... | ... |
@@ -76,6 +76,14 @@ setMethod("groupOTU", signature(object="paml_rst"), |
76 | 76 |
} |
77 | 77 |
) |
78 | 78 |
|
79 |
+##' @rdname groupClade-methods |
|
80 |
+##' @exportMethod groupClade |
|
81 |
+setMethod("groupClade", signature(object="paml_rst"), |
|
82 |
+ function(object, node) { |
|
83 |
+ groupClade_(object, node) |
|
84 |
+ } |
|
85 |
+ ) |
|
86 |
+ |
|
79 | 87 |
##' @rdname scale_color-methods |
80 | 88 |
##' @exportMethod scale_color |
81 | 89 |
setMethod("scale_color", signature(object="paml_rst"), |
... | ... |
@@ -40,6 +40,27 @@ groupOTU.phylo <- function(phy, focus) { |
40 | 40 |
attr(phy, "focus") |
41 | 41 |
} |
42 | 42 |
|
43 |
+##' @rdname groupClade-methods |
|
44 |
+##' @exportMethod groupClade |
|
45 |
+setMethod("groupClade", signature(object="phylo"), |
|
46 |
+ function(object, node) { |
|
47 |
+ groupClade.phylo(object, node) |
|
48 |
+ }) |
|
49 |
+ |
|
50 |
+groupClade.phylo <- function(object, node) { |
|
51 |
+ if (length(node) == 1) { |
|
52 |
+ clade <- extract.clade(object, node) |
|
53 |
+ tips <- clade$tip.label |
|
54 |
+ } else { |
|
55 |
+ tips <- lapply(node, function(x) { |
|
56 |
+ clade <- extract.clade(object, x) |
|
57 |
+ clade$tip.label |
|
58 |
+ }) |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ groupOTU.phylo(object, tips) |
|
62 |
+} |
|
63 |
+ |
|
43 | 64 |
|
44 | 65 |
##' @rdname gzoom-methods |
45 | 66 |
##' @exportMethod gzoom |
... | ... |
@@ -41,6 +41,9 @@ scale_color_ <- function(phylo, by, low=NULL, high=NULL, na.color=NULL, default. |
41 | 41 |
return(df$color) |
42 | 42 |
} |
43 | 43 |
|
44 |
+groupClade_ <- function(object, node) { |
|
45 |
+ groupClade.phylo(get.tree(object), node) |
|
46 |
+} |
|
44 | 47 |
|
45 | 48 |
groupOTU_ <- function(object, focus) { |
46 | 49 |
groupOTU.phylo(get.tree(object), focus) |
47 | 50 |
similarity index 71% |
48 | 51 |
rename from man/collapse_clade.Rd |
49 | 52 |
rename to man/collapse.Rd |
... | ... |
@@ -1,10 +1,10 @@ |
1 | 1 |
% Generated by roxygen2 (4.1.0): do not edit by hand |
2 | 2 |
% Please edit documentation in R/ggtree.R |
3 |
-\name{collapse_clade} |
|
4 |
-\alias{collapse_clade} |
|
5 |
-\title{collapse_clade} |
|
3 |
+\name{collapse} |
|
4 |
+\alias{collapse} |
|
5 |
+\title{collapse} |
|
6 | 6 |
\usage{ |
7 |
-collapse_clade(tree_view, node) |
|
7 |
+collapse(tree_view, node) |
|
8 | 8 |
} |
9 | 9 |
\arguments{ |
10 | 10 |
\item{tree_view}{tree view} |
... | ... |
@@ -20,4 +20,7 @@ collapse a clade |
20 | 20 |
\author{ |
21 | 21 |
Guangchuang Yu |
22 | 22 |
} |
23 |
+\seealso{ |
|
24 |
+expand |
|
25 |
+} |
|
23 | 26 |
|
24 | 27 |
similarity index 73% |
25 | 28 |
rename from man/expand_clade.Rd |
26 | 29 |
rename to man/expand.Rd |
... | ... |
@@ -1,10 +1,10 @@ |
1 | 1 |
% Generated by roxygen2 (4.1.0): do not edit by hand |
2 | 2 |
% Please edit documentation in R/ggtree.R |
3 |
-\name{expand_clade} |
|
4 |
-\alias{expand_clade} |
|
5 |
-\title{expand_clade} |
|
3 |
+\name{expand} |
|
4 |
+\alias{expand} |
|
5 |
+\title{expand} |
|
6 | 6 |
\usage{ |
7 |
-expand_clade(tree_view, node) |
|
7 |
+expand(tree_view, node) |
|
8 | 8 |
} |
9 | 9 |
\arguments{ |
10 | 10 |
\item{tree_view}{tree view} |
... | ... |
@@ -20,4 +20,7 @@ expand collased clade |
20 | 20 |
\author{ |
21 | 21 |
Guangchuang Yu |
22 | 22 |
} |
23 |
+\seealso{ |
|
24 |
+collapse |
|
25 |
+} |
|
23 | 26 |
|
24 | 27 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,43 @@ |
1 |
+% Generated by roxygen2 (4.1.0): do not edit by hand |
|
2 |
+% Please edit documentation in R/AllGenerics.R, R/beast.R, R/codeml.R, R/codeml_mlc.R, R/hyphy.R, R/jplace.R, R/paml_rst.R, R/phylo.R |
|
3 |
+\docType{methods} |
|
4 |
+\name{groupClade} |
|
5 |
+\alias{groupClade} |
|
6 |
+\alias{groupClade,beast-method} |
|
7 |
+\alias{groupClade,codeml-method} |
|
8 |
+\alias{groupClade,codeml_mlc-method} |
|
9 |
+\alias{groupClade,hyphy-method} |
|
10 |
+\alias{groupClade,jplace-method} |
|
11 |
+\alias{groupClade,paml_rst-method} |
|
12 |
+\alias{groupClade,phylo-method} |
|
13 |
+\title{groupClade method} |
|
14 |
+\usage{ |
|
15 |
+groupClade(object, node) |
|
16 |
+ |
|
17 |
+\S4method{groupClade}{beast}(object, node) |
|
18 |
+ |
|
19 |
+\S4method{groupClade}{codeml}(object, node) |
|
20 |
+ |
|
21 |
+\S4method{groupClade}{codeml_mlc}(object, node) |
|
22 |
+ |
|
23 |
+\S4method{groupClade}{hyphy}(object, node) |
|
24 |
+ |
|
25 |
+\S4method{groupClade}{jplace}(object, node) |
|
26 |
+ |
|
27 |
+\S4method{groupClade}{paml_rst}(object, node) |
|
28 |
+ |
|
29 |
+\S4method{groupClade}{phylo}(object, node) |
|
30 |
+} |
|
31 |
+\arguments{ |
|
32 |
+\item{object}{supported objects, including phylo, paml_rst, |
|
33 |
+codeml_mlc, codeml, jplace, beast, hyphy} |
|
34 |
+ |
|
35 |
+\item{node}{a internal node or a vector of internal nodes} |
|
36 |
+} |
|
37 |
+\value{ |
|
38 |
+group index |
|
39 |
+} |
|
40 |
+\description{ |
|
41 |
+groupClade method |
|
42 |
+} |
|
43 |
+ |
... | ... |
@@ -29,12 +29,12 @@ knitr::opts_chunk$set(tidy = FALSE, |
29 | 29 |
|
30 | 30 |
|
31 | 31 |
```{r echo=FALSE, results="hide", message=FALSE} |
32 |
-library("ape") |
|
33 | 32 |
library("colorspace") |
34 |
-library("ggplot2") |
|
35 |
-library("ggtree") |
|
36 | 33 |
library("Biostrings") |
34 |
+library("ape") |
|
35 |
+library("ggplot2") |
|
37 | 36 |
library("gridExtra") |
37 |
+library("ggtree") |
|
38 | 38 |
``` |
39 | 39 |
|
40 | 40 |
|
... | ... |
@@ -542,19 +542,19 @@ ggtree(tree, layout="fan") %>% hilight(node=21, fill="steelblue", alpha=.6) %>% |
542 | 542 |
|
543 | 543 |
## collapse clade |
544 | 544 |
|
545 |
-With _`collapse_clade`_ function, user can collapse a selected clade. |
|
545 |
+With _`collapse`_ function, user can collapse a selected clade. |
|
546 | 546 |
|
547 | 547 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
548 |
-cp <- ggtree(tree) %>% collapse_clade(node=21) |
|
548 |
+cp <- ggtree(tree) %>% collapse(node=21) |
|
549 | 549 |
cp + geom_point(subset=.(node == 21), size=5, shape=23, fill="steelblue") |
550 | 550 |
``` |
551 | 551 |
|
552 | 552 |
## expand collapsed clade |
553 | 553 |
|
554 |
-The collapsed clade can be expanded via _`expand_clade`_ function. |
|
554 |
+The collapsed clade can be expanded via _`expand`_ function. |
|
555 | 555 |
|
556 | 556 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
557 |
-cp %>% expand_clade(node=21) |
|
557 |
+cp %>% expand(node=21) |
|
558 | 558 |
``` |
559 | 559 |
|
560 | 560 |
## phylopic |
... | ... |
@@ -626,7 +626,7 @@ ggtree(tree, color=cols[cls_ind], linetype=linetype[cls_ind]) + |
626 | 626 |
|
627 | 627 |
And also size: |
628 | 628 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
629 |
-size <- 1:5 |
|
629 |
+size <- seq(1, 3, length.out=5) |
|
630 | 630 |
ggtree(tree, color=cols[cls_ind], linetype=linetype[cls_ind], size=size[cls_ind]) + |
631 | 631 |
geom_text(aes(label=label), color=cols[cls_ind], hjust=-.25) |
632 | 632 |
``` |
... | ... |
@@ -679,6 +679,24 @@ ggtree(tree_iris, color=cols[cls_ind]) %<+% species + |
679 | 679 |
|
680 | 680 |
This example demonstrates how the separation of the _`bionj`_ is very good with the _`setosa`_ species, but misses in labeling several _`versicolor`_ and _`virginica`_ species. |
681 | 681 |
|
682 |
+## group clades |
|
683 |
+ |
|
684 |
+As demonstrated above, _`groupOTU`_ is used for clustering related OTUs. Related OTUs are not necessarily within a clade, they can be distantly related as demonstrated in __[`iris example`](#iris-example)__. _`groupOTU`_ works fine for monophyletic (clade), polyphyletic and paraphyletic. If user wants to hilight a specific clade, we provides a more friendly function _`groupClade`_ that accept an internal node or a vector of internal nodes and return cluster index just exactly like _`groupOTU`_. User can also use _`hilight`_ function demonstrated in __[`hilight clades`](#hilight-clades)__ section for highlighting selected clades. |
|
685 |
+ |
|
686 |
+```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
|
687 |
+idx <- groupClade(tree, node=21) |
|
688 |
+cols <- c("black", "darkgreen")[idx] |
|
689 |
+lty <- c("solid", "dashed")[idx] |
|
690 |
+ggtree(tree, color=cols, linetype=lty) |
|
691 |
+``` |
|
692 |
+ |
|
693 |
+```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
|
694 |
+idx <- groupClade(tree, node=c(21, 17)) |
|
695 |
+cols <- c("black", "darkgreen", "firebrick")[idx] |
|
696 |
+lty <- c("solid", "dashed", "dotted")[idx] |
|
697 |
+ggtree(tree, color=cols, linetype=lty) |
|
698 |
+``` |
|
699 |
+ |
|
682 | 700 |
|
683 | 701 |
## visualize tree with associated matrix |
684 | 702 |
```{r} |