... | ... |
@@ -9,6 +9,8 @@ S3method(fortify,phylo4) |
9 | 9 |
S3method(fortify,phylo4d) |
10 | 10 |
S3method(fortify,phyloseq) |
11 | 11 |
S3method(fortify,treedata) |
12 |
+S3method(groupClade,ggtree) |
|
13 |
+S3method(groupOTU,ggtree) |
|
12 | 14 |
S3method(identify,gg) |
13 | 15 |
S3method(print,beastList) |
14 | 16 |
export("%+>%") |
... | ... |
@@ -90,8 +92,6 @@ export(theme_tree2) |
90 | 92 |
export(viewClade) |
91 | 93 |
export(xlim_expand) |
92 | 94 |
export(xlim_tree) |
93 |
-exportMethods(groupClade) |
|
94 |
-exportMethods(groupOTU) |
|
95 | 95 |
exportMethods(gzoom) |
96 | 96 |
exportMethods(reroot) |
97 | 97 |
exportMethods(scale_color) |
... | ... |
@@ -185,13 +185,13 @@ importFrom(scales,alpha) |
185 | 185 |
importFrom(tibble,data_frame) |
186 | 186 |
importFrom(tidyr,gather) |
187 | 187 |
importFrom(tidytree,as_data_frame) |
188 |
+importFrom(tidytree,get_tree_data) |
|
189 |
+importFrom(tidytree,groupClade) |
|
190 |
+importFrom(tidytree,groupOTU) |
|
188 | 191 |
importFrom(treeio,Nnode) |
189 | 192 |
importFrom(treeio,Ntip) |
190 | 193 |
importFrom(treeio,as.phylo) |
191 | 194 |
importFrom(treeio,as.treedata) |
192 |
-importFrom(treeio,get_tree_data) |
|
193 |
-importFrom(treeio,groupClade) |
|
194 |
-importFrom(treeio,groupOTU) |
|
195 | 195 |
importFrom(utils,modifyList) |
196 | 196 |
importFrom(utils,packageDescription) |
197 | 197 |
importFrom(utils,packageVersion) |
... | ... |
@@ -7,20 +7,6 @@ as.binary <- function(tree, ...) { |
7 | 7 |
UseMethod("as.binary") |
8 | 8 |
} |
9 | 9 |
|
10 |
-## ##' plot method generics |
|
11 |
-## ##' |
|
12 |
-## ##' |
|
13 |
-## ##' @docType methods |
|
14 |
-## ##' @name plot |
|
15 |
-## ##' @rdname plot-methods |
|
16 |
-## ##' @title plot method |
|
17 |
-## ##' @param x object |
|
18 |
-## ##' @param ... Additional argument list |
|
19 |
-## ##' @return plot |
|
20 |
-## ##' @importFrom stats4 plot |
|
21 |
-## ##' @export |
|
22 |
-## if ( !isGeneric("plot") ) |
|
23 |
-## setGeneric("plot", function(x, ...) standardGeneric("plot")) |
|
24 | 10 |
|
25 | 11 |
##' @docType methods |
26 | 12 |
##' @name reroot |
... | ... |
@@ -34,112 +20,6 @@ as.binary <- function(tree, ...) { |
34 | 20 |
##' @export |
35 | 21 |
setGeneric("reroot", function(object, node, ...) standardGeneric("reroot")) |
36 | 22 |
|
37 |
-## ##' @docType methods |
|
38 |
-## ##' @name get.tree |
|
39 |
-## ##' @rdname get.tree-methods |
|
40 |
-## ##' @title get.tree method |
|
41 |
-## ##' @param object one of \code{phylo}, \code{jplace}, \code{nhx}, \code{phangorn}, \code{beast}, \code{hyphy}, \code{codeml}, \code{codeml_mlc}, \code{paml_rst} object |
|
42 |
-## ##' @param ... additional parameter |
|
43 |
-## ##' @return phylo object |
|
44 |
-## ##' @export |
|
45 |
-## setGeneric("get.tree", function(object, ...) standardGeneric("get.tree")) |
|
46 |
- |
|
47 |
-## ##' @docType methods |
|
48 |
-## ##' @name get.treetext |
|
49 |
-## ##' @rdname get.treetext-methods |
|
50 |
-## ##' @title get.treetext method |
|
51 |
-## ##' @param object one of \code{phylo}, \code{jplace}, \code{beast}, \code{hyphy}, \code{codeml}, \code{codeml_mlc}, \code{paml_rst} object |
|
52 |
-## ##' @param ... additional parameter |
|
53 |
-## ##' @return phylo object |
|
54 |
-## ##' @export |
|
55 |
-## setGeneric("get.treetext", function(object, ...) standardGeneric("get.treetext")) |
|
56 |
- |
|
57 |
- |
|
58 |
-## ##' @docType methods |
|
59 |
-## ##' @name get.treeinfo |
|
60 |
-## ##' @rdname get.treeinfo-methods |
|
61 |
-## ##' @title get.treeinfo method |
|
62 |
-## ##' @param object jplace object |
|
63 |
-## ##' @param layout layout |
|
64 |
-## ##' @param ladderize ladderize, logical |
|
65 |
-## ##' @param right logical, parameter for ladderize |
|
66 |
-## ##' @param ... additional parameter |
|
67 |
-## ##' @return data.frame |
|
68 |
-## ##' @export |
|
69 |
-## setGeneric("get.treeinfo", function(object, layout="phylogram", ladderize=TRUE, right=FALSE, ...) standardGeneric("get.treeinfo")) |
|
70 |
- |
|
71 |
- |
|
72 |
-## ##' @docType methods |
|
73 |
-## ##' @name get.fields |
|
74 |
-## ##' @rdname get.fields-methods |
|
75 |
-## ##' @title get.fields method |
|
76 |
-## ##' @param object one of \code{jplace}, \code{beast}, \code{hyphy}, \code{codeml}, \code{codeml_mlc}, \code{paml_rst} object |
|
77 |
-## ##' @param ... additional parameter |
|
78 |
-## ##' @return available annotation variables |
|
79 |
-## ##' @export |
|
80 |
-## setGeneric("get.fields", function(object, ...) standardGeneric("get.fields")) |
|
81 |
- |
|
82 |
- |
|
83 |
-## ##' @docType methods |
|
84 |
-## ##' @name get.placements |
|
85 |
-## ##' @rdname get.placements-methods |
|
86 |
-## ##' @title get.placements method |
|
87 |
-## ##' @param object jplace object |
|
88 |
-## ##' @param by get best hit or others |
|
89 |
-## ##' @param ... additional parameter |
|
90 |
-## ##' @return data.frame |
|
91 |
-## ##' @export |
|
92 |
-## setGeneric("get.placements", function(object, by, ...) standardGeneric("get.placements")) |
|
93 |
- |
|
94 |
-## ##' @docType methods |
|
95 |
-## ##' @name get.subs |
|
96 |
-## ##' @rdname get.subs-methods |
|
97 |
-## ##' @title get.subs method |
|
98 |
-## ##' @param object paml_rst object |
|
99 |
-## ##' @param type one of 'marginal_subs', 'marginal_AA_subs', |
|
100 |
-## ##' 'joint_subs' or 'joint_AA_subs'. |
|
101 |
-## ##' @param ... additional parameter |
|
102 |
-## ##' @return data.frame |
|
103 |
-## ##' @export |
|
104 |
-## setGeneric("get.subs", function(object, type, ...) standardGeneric("get.subs")) |
|
105 |
- |
|
106 |
- |
|
107 |
-## ##' @docType methods |
|
108 |
-## ##' @name get.tipseq |
|
109 |
-## ##' @rdname get.tipseq-methods |
|
110 |
-## ##' @title get.tipseq method |
|
111 |
-## ##' @param object one of paml_rst or codeml object |
|
112 |
-## ##' @param ... additional parameter |
|
113 |
-## ##' @return character |
|
114 |
-## ##' @export |
|
115 |
-## setGeneric("get.tipseq", function(object, ...) standardGeneric("get.tipseq")) |
|
116 |
- |
|
117 |
-## ##' @docType methods |
|
118 |
-## ##' @name groupOTU |
|
119 |
-## ##' @rdname groupOTU-methods |
|
120 |
-## ##' @title groupOTU method |
|
121 |
-## ##' @param object supported objects, including phylo, paml_rst, |
|
122 |
-## ##' codeml_mlc, codeml, jplace, beast, hyphy |
|
123 |
-## ##' @param focus a vector of tip (label or number) or a list of tips. |
|
124 |
-## ##' @param group_name name of the group, 'group' by default |
|
125 |
-## ##' @param ... additional parameter |
|
126 |
-## ##' @return group index |
|
127 |
-## ##' @export |
|
128 |
-## setGeneric("groupOTU", function(object, focus, group_name="group", ...) standardGeneric("groupOTU")) |
|
129 |
- |
|
130 |
-## ##' @docType methods |
|
131 |
-## ##' @name groupClade |
|
132 |
-## ##' @rdname groupClade-methods |
|
133 |
-## ##' @title groupClade method |
|
134 |
-## ##' @param object supported objects, including phylo, paml_rst, |
|
135 |
-## ##' codeml_mlc, codeml, jplace, beast, hyphy |
|
136 |
-## ##' @param node a internal node or a vector of internal nodes |
|
137 |
-## ##' @param group_name name of the group, 'group' by default |
|
138 |
-## ##' @param ... additional parameter |
|
139 |
-## ##' @return group index |
|
140 |
-## ##' @export |
|
141 |
-## setGeneric("groupClade", function(object, node, group_name="group", ...) standardGeneric("groupClade")) |
|
142 |
- |
|
143 | 23 |
|
144 | 24 |
##' @docType methods |
145 | 25 |
##' @name scale_color |
... | ... |
@@ -166,18 +46,3 @@ setGeneric("scale_color", function(object, by, ...) standardGeneric("scale_color |
166 | 46 |
##' @export |
167 | 47 |
setGeneric("gzoom", function(object, focus, subtree=FALSE, widths=c(.3, .7), ...) standardGeneric("gzoom")) |
168 | 48 |
|
169 |
- |
|
170 |
-## ##' @docType methods |
|
171 |
-## ##' @name drop.tip |
|
172 |
-## ##' @rdname drop.tip-methods |
|
173 |
-## ##' @title drop.tip method |
|
174 |
-## ##' @param object An nhx or phylo object |
|
175 |
-## ##' @param tip a vector of mode numeric or character specifying the tips to delete |
|
176 |
-## ##' @param ... additional parameters |
|
177 |
-## ##' @return updated object |
|
178 |
-## ##' @export |
|
179 |
-## setGeneric ( |
|
180 |
-## name = "drop.tip", |
|
181 |
-## def = function( object, tip, ... ) |
|
182 |
-## { standardGeneric("drop.tip") } |
|
183 |
-## ) |
... | ... |
@@ -82,7 +82,7 @@ fortify.phylo <- function(model, data, |
82 | 82 |
scaleY(as.phylo(model), res, yscale, layout, ...) |
83 | 83 |
} |
84 | 84 |
|
85 |
-##' @importFrom treeio get_tree_data |
|
85 |
+##' @importFrom tidytree get_tree_data |
|
86 | 86 |
set_branch_length <- function(tree_object, branch.length) { |
87 | 87 |
if (branch.length == "branch.length") { |
88 | 88 |
return(tree_object) |
89 | 89 |
deleted file mode 100644 |
... | ... |
@@ -1,70 +0,0 @@ |
1 |
-## ##' drop.tip method |
|
2 |
-## ##' |
|
3 |
-## ##' |
|
4 |
-## ##' @rdname drop.tip-methods |
|
5 |
-## ##' @aliases drop.tip,nhx |
|
6 |
-## ##' @exportMethod drop.tip |
|
7 |
-## ##' @author Casey Dunn \url{http://dunnlab.org} and Guangchuang Yu \url{https://guangchuangyu.github.io} |
|
8 |
-## ##' @usage drop.tip(object, tip, ...) |
|
9 |
-## setMethod("drop.tip", signature(object="nhx"), |
|
10 |
-## function(object, tip, ...) { |
|
11 |
- |
|
12 |
-## ## label the internal tree nodes by their number |
|
13 |
-## no_node_label <- FALSE |
|
14 |
-## if (is.null(object@phylo$node.label)) { |
|
15 |
-## object@phylo$node.label <- Ntip(object) + (1:Nnode(object)) |
|
16 |
-## no_node_label <- TRUE |
|
17 |
-## } |
|
18 |
- |
|
19 |
-## ## Prepare the nhx object for subsampling |
|
20 |
-## object@nhx_tags$node <- as.numeric(object@nhx_tags$node) |
|
21 |
-## object@nhx_tags <- object@nhx_tags[order(object@nhx_tags$node),] |
|
22 |
- |
|
23 |
-## ## add a colmn that has labels for both tips and internal nodes |
|
24 |
-## object@nhx_tags$node.label <- c(object@phylo$tip.label, as.character(object@phylo$node.label)) |
|
25 |
- |
|
26 |
-## ## Will need to take different approaches for subsampling tips |
|
27 |
-## ## and internal nodes, add a column to make it easy to tell them apart |
|
28 |
-## object@nhx_tags$is_tip <- object@nhx_tags$node <= Ntip(object) |
|
29 |
- |
|
30 |
-## ## Remove tips |
|
31 |
-## object@phylo = ape::drop.tip( object@phylo, tip ) |
|
32 |
- |
|
33 |
-## ## Subsample the tags |
|
34 |
-## object@nhx_tags = object@nhx_tags[object@nhx_tags$node.label %in% (c(object@phylo$tip.label, as.character(object@phylo$node.label))),] |
|
35 |
- |
|
36 |
-## ## Update tip node numbers |
|
37 |
-## tip_nodes <- object@nhx_tags$node.label[ object@nhx_tags$is_tip ] |
|
38 |
-## object@nhx_tags$node[ object@nhx_tags$is_tip ] = match(object@phylo$tip.label, tip_nodes) |
|
39 |
- |
|
40 |
-## internal_nodes <- object@nhx_tags$node.label[ !object@nhx_tags$is_tip ] |
|
41 |
-## object@nhx_tags$node[ !object@nhx_tags$is_tip ] = match(object@phylo$node.label, internal_nodes) + length(object@phylo$tip.label) |
|
42 |
- |
|
43 |
-## ## Clean up |
|
44 |
-## object@nhx_tags$node.label = NULL |
|
45 |
-## object@nhx_tags$is_tip = NULL |
|
46 |
-## if (no_node_label) { |
|
47 |
-## object@phylo$node.label <- NULL |
|
48 |
-## } |
|
49 |
- |
|
50 |
-## return(object) |
|
51 |
-## }) |
|
52 |
- |
|
53 |
- |
|
54 |
- |
|
55 |
- |
|
56 |
- |
|
57 |
-## ##' @rdname drop.tip-methods |
|
58 |
-## ##' @exportMethod drop.tip |
|
59 |
-## ##' @aliases drop.tip,phylo |
|
60 |
-## ##' @source |
|
61 |
-## ##' drop.tip for phylo object is a wrapper method of ape::drop.tip |
|
62 |
-## ##' from the ape package. The documentation you should |
|
63 |
-## ##' read for the drop.tip function can be found here: \link[ape]{drop.tip} |
|
64 |
-## ##' |
|
65 |
-## ##' @seealso |
|
66 |
-## ##' \link[ape]{drop.tip} |
|
67 |
-## setMethod("drop.tip", signature(object="phylo"), |
|
68 |
-## function(object, tip, ...){ |
|
69 |
-## ape::drop.tip(object, tip, ...) |
|
70 |
-## }) |
... | ... |
@@ -1,109 +1,6 @@ |
1 |
-## ##' @rdname groupClade-methods |
|
2 |
-## ##' @exportMethod groupClade |
|
3 |
-## setMethod("groupClade", signature(object="beast"), |
|
4 |
-## function(object, node, group_name="group") { |
|
5 |
-## groupClade_(object, node, group_name) |
|
6 |
-## }) |
|
7 |
- |
|
8 |
-## ##' @rdname groupClade-methods |
|
9 |
-## ##' @exportMethod groupClade |
|
10 |
-## setMethod("groupClade", signature(object="codeml"), |
|
11 |
-## function(object, node, group_name="group") { |
|
12 |
-## groupClade_(object, node, group_name) |
|
13 |
-## } |
|
14 |
-## ) |
|
15 |
- |
|
16 |
-##' groupClade method for ggtree object |
|
17 |
-##' |
|
18 |
-##' |
|
19 |
-##' @name groupClade |
|
20 |
-##' @title groupClade method |
|
21 |
-##' @rdname groupClade-methods |
|
22 |
-##' @param object ggtree object |
|
23 |
-##' @param node internal node number |
|
24 |
-##' @param group_name name of the group |
|
25 |
-##' @importFrom treeio groupClade |
|
26 |
-##' @exportMethod groupClade |
|
27 |
-##' @aliases groupClade,ggtree-method |
|
28 |
-setMethod("groupClade", signature(object="ggtree"), |
|
29 |
- function(object, node, group_name) { |
|
30 |
- groupClade.ggtree(object, node, group_name) |
|
31 |
- }) |
|
32 |
- |
|
33 |
-## ##' @rdname groupClade-methods |
|
34 |
-## ##' @exportMethod groupClade |
|
35 |
-## setMethod("groupClade", signature(object="jplace"), |
|
36 |
-## function(object, node, group_name="group") { |
|
37 |
-## groupClade_(object, node, group_name) |
|
38 |
-## } |
|
39 |
-## ) |
|
40 |
- |
|
41 |
-## ##' group selected clade |
|
42 |
-## ##' |
|
43 |
-## ##' |
|
44 |
-## ##' @rdname groupClade-methods |
|
45 |
-## ##' @exportMethod groupClade |
|
46 |
-## setMethod("groupClade", signature(object="nhx"), |
|
47 |
-## function(object, node, group_name="group") { |
|
48 |
-## groupClade_(object, node, group_name) |
|
49 |
-## }) |
|
50 |
- |
|
51 |
-## ##' @rdname groupClade-methods |
|
52 |
-## ##' @exportMethod groupClade |
|
53 |
-## setMethod("groupClade", signature(object="phylip"), |
|
54 |
-## function(object, node, group_name="group") { |
|
55 |
-## groupClade_(object, node, group_name) |
|
56 |
-## }) |
|
57 |
- |
|
58 |
- |
|
59 |
-## ##' @rdname groupClade-methods |
|
60 |
-## ##' @exportMethod groupClade |
|
61 |
-## setMethod("groupClade", signature(object="phylo"), |
|
62 |
-## function(object, node, group_name="group") { |
|
63 |
-## groupClade.phylo(object, node, group_name) |
|
64 |
-## }) |
|
65 |
- |
|
66 |
- |
|
67 |
- |
|
68 |
-## groupClade.phylo <- function(object, node, group_name) { |
|
69 |
-## if (length(node) == 1) { |
|
70 |
-## clade <- extract.clade(object, node) |
|
71 |
-## tips <- clade$tip.label |
|
72 |
-## } else { |
|
73 |
-## tips <- lapply(node, function(x) { |
|
74 |
-## clade <- extract.clade(object, x) |
|
75 |
-## clade$tip.label |
|
76 |
-## }) |
|
77 |
-## } |
|
78 |
- |
|
79 |
-## groupOTU.phylo(object, tips, group_name) |
|
80 |
-## } |
|
81 |
- |
|
82 |
- |
|
83 |
-## groupClade_ <- function(object, node, group_name) { |
|
84 |
-## if (is(object, "phylo")) { |
|
85 |
-## object <- groupClade.phylo(object, node, group_name) |
|
86 |
-## } else { |
|
87 |
-## object@phylo <- groupClade.phylo(get.tree(object), node, group_name) |
|
88 |
-## } |
|
89 |
-## return(object) |
|
90 |
-## } |
|
91 |
- |
|
92 |
- |
|
93 |
-groupClade.ggtree <- function(object, nodes, group_name) { |
|
94 |
- df <- object$data |
|
95 |
- df[, group_name] <- 0 |
|
96 |
- for (node in nodes) { |
|
97 |
- df <- groupClade.tbl(df, node, group_name) |
|
98 |
- } |
|
99 |
- df[, group_name] <- factor(df[[group_name]]) |
|
100 |
- object$data <- df |
|
101 |
- return(object) |
|
102 |
-} |
|
103 |
- |
|
104 |
-groupClade.tbl <- function(df, node, group_name) { |
|
105 |
- foc <- c(node, get.offspring.df(df, node)) |
|
106 |
- idx <- match(foc, df$node) |
|
107 |
- df[idx, group_name] <- max(df[[group_name]]) + 1 |
|
108 |
- return(df) |
|
1 |
+##' @importFrom tidytree groupClade |
|
2 |
+##' @method groupClade ggtree |
|
3 |
+##' @export |
|
4 |
+groupClade.ggtree <- function(.data, .node, group_name = "group", ...) { |
|
5 |
+ .data$data <- groupClade(.data$data, .node, group_name, ...) |
|
109 | 6 |
} |
... | ... |
@@ -1,251 +1,7 @@ |
1 |
-## ##' @rdname groupOTU-methods |
|
2 |
-## ##' @exportMethod groupOTU |
|
3 |
-## setMethod("groupOTU", signature(object="apeBootstrap"), |
|
4 |
-## function(object, focus, group_name="group", ...) { |
|
5 |
-## groupOTU_(object, focus, group_name, ...) |
|
6 |
-## } |
|
7 |
-## ) |
|
8 |
- |
|
9 |
- |
|
10 |
-## ##' @rdname groupOTU-methods |
|
11 |
-## ##' @exportMethod groupOTU |
|
12 |
-## setMethod("groupOTU", signature(object="beast"), |
|
13 |
-## function(object, focus, group_name="group", ...) { |
|
14 |
-## groupOTU_(object, focus, group_name, ...) |
|
15 |
-## } |
|
16 |
-## ) |
|
17 |
- |
|
18 |
-## ##' @rdname groupOTU-methods |
|
19 |
-## ##' @exportMethod groupOTU |
|
20 |
-## setMethod("groupOTU", signature(object="codeml"), |
|
21 |
-## function(object, focus, group_name="group", ...) { |
|
22 |
-## groupOTU_(object, focus, group_name, ...) |
|
23 |
-## } |
|
24 |
-## ) |
|
25 |
- |
|
26 |
- |
|
27 |
-## ##' @rdname groupOTU-methods |
|
28 |
-## ##' @exportMethod groupOTU |
|
29 |
-## setMethod("groupOTU", signature(object="codeml_mlc"), |
|
30 |
-## function(object, focus, group_name="group", ...) { |
|
31 |
-## groupOTU_(object, focus, group_name, ...) |
|
32 |
-## } |
|
33 |
-## ) |
|
34 |
- |
|
35 |
- |
|
36 |
-## ##' @rdname groupOTU-methods |
|
37 |
-## ##' @exportMethod groupOTU |
|
38 |
-## setMethod("groupOTU", signature(object="jplace"), |
|
39 |
-## function(object, focus, group_name="group", ...) { |
|
40 |
-## groupOTU_(object, focus, group_name, ...) |
|
41 |
-## } |
|
42 |
-## ) |
|
43 |
- |
|
44 |
-## ##' @rdname groupOTU-methods |
|
45 |
-## ##' @exportMethod groupOTU |
|
46 |
-## setMethod("groupOTU", signature(object="nhx"), |
|
47 |
-## function(object, focus, group_name="group", ...) { |
|
48 |
-## groupOTU_(object, focus, group_name, ...) |
|
49 |
-## } |
|
50 |
-## ) |
|
51 |
- |
|
52 |
-## ##' @rdname groupOTU-methods |
|
53 |
-## ##' @exportMethod groupOTU |
|
54 |
-## setMethod("groupOTU", signature(object="phangorn"), |
|
55 |
-## function(object, focus, group_name="group", ...) { |
|
56 |
-## groupOTU_(object, focus, group_name, ...) |
|
57 |
-## } |
|
58 |
-## ) |
|
59 |
- |
|
60 |
-## ##' @rdname groupOTU-methods |
|
61 |
-## ##' @exportMethod groupOTU |
|
62 |
-## setMethod("groupOTU", signature(object="phylip"), |
|
63 |
-## function(object, focus, group_name="group", ...) { |
|
64 |
-## groupOTU_(object, focus, group_name, ...) |
|
65 |
-## } |
|
66 |
-## ) |
|
67 |
- |
|
68 |
-## ##' @rdname groupOTU-methods |
|
69 |
-## ##' @exportMethod groupOTU |
|
70 |
-## setMethod("groupOTU", signature(object="paml_rst"), |
|
71 |
-## function(object, focus, group_name="group", ...) { |
|
72 |
-## groupOTU_(object, focus, group_name, ...) |
|
73 |
-## } |
|
74 |
-## ) |
|
75 |
- |
|
76 |
- |
|
77 |
-## ##' group tree based on selected OTU, will traceback to MRCA |
|
78 |
-## ##' |
|
79 |
-## ##' |
|
80 |
-## ##' @rdname groupOTU-methods |
|
81 |
-## ##' @exportMethod groupOTU |
|
82 |
-## setMethod("groupOTU", signature(object="phylo"), |
|
83 |
-## function(object, focus, group_name="group", ...) { |
|
84 |
-## groupOTU.phylo(object, focus, group_name, ...) |
|
85 |
-## }) |
|
86 |
- |
|
87 |
-## ##' @rdname groupOTU-methods |
|
88 |
-## ##' @exportMethod groupOTU |
|
89 |
-## ##' @param tree which tree selected |
|
90 |
-## setMethod("groupOTU", signature(object="r8s"), |
|
91 |
-## function(object, focus, group_name="group", tree="TREE", ...) { |
|
92 |
-## groupOTU_(get.tree(object)[[tree]], focus, group_name, ...) |
|
93 |
-## } |
|
94 |
-## ) |
|
95 |
- |
|
96 |
- |
|
97 |
- |
|
98 |
- |
|
99 |
-## ##' @importFrom ape which.edge |
|
100 |
-## gfocus <- function(phy, focus, group_name, focus_label=NULL, overlap="overwrite") { |
|
101 |
-## overlap <- match.arg(overlap, c("origin", "overwrite", "abandon")) |
|
102 |
- |
|
103 |
-## if (is.character(focus)) { |
|
104 |
-## focus <- which(phy$tip.label %in% focus) |
|
105 |
-## } |
|
106 |
- |
|
107 |
-## n <- getNodeNum(phy) |
|
108 |
-## if (is.null(attr(phy, group_name))) { |
|
109 |
-## foc <- rep(0, n) |
|
110 |
-## } else { |
|
111 |
-## foc <- attr(phy, group_name) |
|
112 |
-## } |
|
113 |
-## i <- max(suppressWarnings(as.numeric(foc)), na.rm=TRUE) + 1 |
|
114 |
-## if (is.null(focus_label)) { |
|
115 |
-## focus_label <- i |
|
116 |
-## } |
|
117 |
- |
|
118 |
-## ## sn <- phy$edge[which.edge(phy, focus),] %>% as.vector %>% unique |
|
119 |
-## hit <- unique(as.vector(phy$edge[which.edge(phy, focus),])) |
|
120 |
-## if (overlap == "origin") { |
|
121 |
-## sn <- hit[is.na(foc[hit]) | foc[hit] == 0] |
|
122 |
-## } else if (overlap == "abandon") { |
|
123 |
-## idx <- !is.na(foc[hit]) & foc[hit] != 0 |
|
124 |
-## foc[hit[idx]] <- NA |
|
125 |
-## sn <- hit[!idx] |
|
126 |
-## } else { |
|
127 |
-## sn <- hit |
|
128 |
-## } |
|
129 |
- |
|
130 |
-## if (length(sn) > 0) { |
|
131 |
-## foc[sn] <- focus_label |
|
132 |
-## } |
|
133 |
- |
|
134 |
-## attr(phy, group_name) <- foc |
|
135 |
-## phy |
|
136 |
-## } |
|
137 |
- |
|
138 |
- |
|
139 |
-## ##' group OTU |
|
140 |
-## ##' |
|
141 |
-## ##' |
|
142 |
-## ##' @title groupOTU.phylo |
|
143 |
-## ##' @param phy tree object |
|
144 |
-## ##' @param focus tip list |
|
145 |
-## ##' @param group_name name of the group |
|
146 |
-## ##' @param ... additional parameters |
|
147 |
-## ##' @return phylo object |
|
148 |
-## ##' @author ygc |
|
149 |
-## groupOTU.phylo <- function(phy, focus, group_name="group", ...) { |
|
150 |
-## attr(phy, group_name) <- NULL |
|
151 |
-## if ( is(focus, "list") ) { |
|
152 |
-## for (i in 1:length(focus)) { |
|
153 |
-## phy <- gfocus(phy, focus[[i]], group_name, names(focus)[i], ...) |
|
154 |
-## } |
|
155 |
-## } else { |
|
156 |
-## phy <- gfocus(phy, focus, group_name, ...) |
|
157 |
-## } |
|
158 |
-## res <- attr(phy, group_name) |
|
159 |
-## res[is.na(res)] <- 0 |
|
160 |
-## attr(phy, group_name) <- factor(res) |
|
161 |
-## return(phy) |
|
162 |
-## } |
|
163 |
- |
|
164 |
-## groupOTU_ <- function(object, focus, group_name, ...) { |
|
165 |
-## if (is(object, "phylo")) { |
|
166 |
-## object <- groupOTU.phylo(object, focus, group_name, ...) |
|
167 |
-## } else { |
|
168 |
-## object@phylo <- groupOTU.phylo(get.tree(object), focus, group_name, ...) |
|
169 |
-## } |
|
170 |
-## return(object) |
|
171 |
-## } |
|
172 |
- |
|
173 |
-##' groupOTU method for ggtree object |
|
174 |
-##' |
|
175 |
-##' |
|
176 |
-##' @name groupOTU |
|
177 |
-##' @title groupOTU method |
|
178 |
-##' @rdname groupOTU-methods |
|
179 |
-##' @param object ggtree object |
|
180 |
-##' @param focus OTU to focus |
|
181 |
-##' @param group_name name of the group |
|
182 |
-##' @param ... additional parameters |
|
183 |
-##' @importFrom treeio groupOTU |
|
184 |
-##' @exportMethod groupOTU |
|
185 |
-##' @aliases groupOTU,ggtree-method |
|
186 |
-setMethod("groupOTU", signature(object="ggtree"), |
|
187 |
- function(object, focus, group_name="group", ...) { |
|
188 |
- groupOTU.ggtree(object, focus, group_name, ...) |
|
189 |
- }) |
|
190 |
- |
|
191 |
- |
|
192 |
-groupOTU.ggtree <- function(object, focus, group_name, ...) { |
|
193 |
- df <- object$data |
|
194 |
- df[[group_name]] <- 0 |
|
195 |
- object$data <- groupOTU.tbl(df, focus, group_name, ...) |
|
196 |
- return(object) |
|
197 |
-} |
|
198 |
- |
|
199 |
- |
|
200 |
-groupOTU.tbl <- function(df, focus, group_name, ...) { |
|
201 |
- if (is(focus, "list")) { |
|
202 |
- for (i in 1:length(focus)) { |
|
203 |
- df <- gfocus.tbl(df, focus[[i]], group_name, names(focus)[i], ...) |
|
204 |
- } |
|
205 |
- } else { |
|
206 |
- df <- gfocus.tbl(df, focus, group_name, ...) |
|
207 |
- } |
|
208 |
- df[[group_name]] <- factor(df[[group_name]]) |
|
209 |
- return(df) |
|
210 |
-} |
|
211 |
- |
|
212 |
-gfocus.tbl <- function(df, focus, group_name, focus_label=NULL, overlap="overwrite") { |
|
213 |
- overlap <- match.arg(overlap, c("origin", "overwrite", "abandon")) |
|
214 |
- |
|
215 |
- focus <- df$node[which(df$label %in% focus)] |
|
216 |
- if (is.null(focus_label)) |
|
217 |
- focus_label <- max(suppressWarnings(as.numeric(df[[group_name]])), na.rm=TRUE) + 1 |
|
218 |
- |
|
219 |
- if (length(focus) == 1) { |
|
220 |
- hit <- match(focus, df$node) |
|
221 |
- } else { |
|
222 |
- anc <- getAncestor.df(df, focus[1]) |
|
223 |
- foc <- c(focus[1], anc) |
|
224 |
- for (j in 2:length(focus)) { |
|
225 |
- anc2 <- getAncestor.df(df, focus[j]) |
|
226 |
- comAnc <- intersect(anc, anc2) |
|
227 |
- foc <- c(foc, focus[j], anc2) |
|
228 |
- foc <- foc[! foc %in% comAnc] |
|
229 |
- foc <- c(foc, comAnc[1]) |
|
230 |
- } |
|
231 |
- hit <- match(foc, df$node) |
|
232 |
- } |
|
233 |
- |
|
234 |
- foc <- df[[group_name]] |
|
235 |
- if (overlap == "origin") { |
|
236 |
- sn <- hit[is.na(foc[hit]) | foc[hit] == 0] |
|
237 |
- } else if (overlap == "abandon") { |
|
238 |
- idx <- !is.na(foc[hit]) & foc[hit] != 0 |
|
239 |
- foc[hit[idx]] <- NA |
|
240 |
- sn <- hit[!idx] |
|
241 |
- } else { |
|
242 |
- sn <- hit |
|
243 |
- } |
|
244 |
- |
|
245 |
- if (length(sn) > 0) { |
|
246 |
- foc[sn] <- focus_label |
|
247 |
- } |
|
248 |
- |
|
249 |
- df[, group_name] <- foc |
|
250 |
- return(df) |
|
1 |
+##' @method groupOTU ggtree |
|
2 |
+##' @export |
|
3 |
+##' @importFrom tidytree groupOTU |
|
4 |
+groupOTU.ggtree <- function(.data, .node, group_name = "group", ...) { |
|
5 |
+ .data$data <- groupOTU(.data$data, .node, group_name, ...) |
|
6 |
+ return(.data) |
|
251 | 7 |
} |
... | ... |
@@ -1,30 +1,4 @@ |
1 | 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 | 2 |
|
29 | 3 |
##' reroot a tree |
30 | 4 |
##' |
... | ... |
@@ -1,8 +1,6 @@ |
1 | 1 |
has.slot <- treeio:::has.slot |
2 | 2 |
getNodeNum <- treeio:::getNodeNum |
3 |
-getRoot <- treeio:::getRoot |
|
4 |
-has.field <- treeio:::has.field |
|
5 |
-#append_extraInfo <- treeio:::append_extraInfo |
|
3 |
+getRoot <- treeio:::rootnode |
|
6 | 4 |
get.tree <- treeio::get.tree |
7 | 5 |
drop.tip <- treeio::drop.tip |
8 | 6 |
get.fields <- treeio::get.fields |
... | ... |
@@ -4,9 +4,9 @@ ggtree: an R package for visualization and annotation of phylogenetic trees with |
4 | 4 |
|
5 | 5 |
<img src="https://raw.githubusercontent.com/Bioconductor/BiocStickers/master/ggtree/ggtree.png" height="200" align="right" /> |
6 | 6 |
|
7 |
-[](https://bioconductor.org/packages/ggtree) [](https://github.com/guangchuangyu/ggtree) [](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) |
|
7 |
+[](https://bioconductor.org/packages/ggtree) [](https://github.com/guangchuangyu/ggtree) [](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) |
|
8 | 8 |
|
9 |
-[](http://www.repostatus.org/#active) [](https://codecov.io/gh/GuangchuangYu/ggtree) [](https://github.com/GuangchuangYu/ggtree/commits/master) [](https://github.com/GuangchuangYu/ggtree/network) [](https://github.com/GuangchuangYu/ggtree/stargazers) [](https://awesome-r.com/#awesome-r-graphic-displays) |
|
9 |
+[](http://www.repostatus.org/#active) [](https://codecov.io/gh/GuangchuangYu/ggtree) [](https://github.com/GuangchuangYu/ggtree/commits/master) [](https://github.com/GuangchuangYu/ggtree/network) [](https://github.com/GuangchuangYu/ggtree/stargazers) [](https://awesome-r.com/#awesome-r-graphic-displays) |
|
10 | 10 |
|
11 | 11 |
[](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [](https://travis-ci.org/GuangchuangYu/ggtree) [](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [](#backers) [](#sponsors) |
12 | 12 |
|
... | ... |
@@ -27,7 +27,7 @@ Please cite the following article when using `ggtree`: |
27 | 27 |
|
28 | 28 |
**G Yu**, DK Smith, H Zhu, Y Guan, TTY Lam<sup>\*</sup>. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. ***Methods in Ecology and Evolution***. 2017, 8(1):28-36. |
29 | 29 |
|
30 |
-[](http://dx.doi.org/10.1111/2041-210X.12628) [](https://www.altmetric.com/details/10533079) [](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) |
|
30 |
+[](http://dx.doi.org/10.1111/2041-210X.12628) [](https://www.altmetric.com/details/10533079) [](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) |
|
31 | 31 |
|
32 | 32 |
------------------------------------------------------------------------ |
33 | 33 |
|
... | ... |
@@ -37,7 +37,7 @@ Please cite the following article when using `ggtree`: |
37 | 37 |
|
38 | 38 |
### Download stats |
39 | 39 |
|
40 |
-[](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) |
|
40 |
+[](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) [](https://bioconductor.org/packages/stats/bioc/ggtree) |
|
41 | 41 |
|
42 | 42 |
<img src="docs/images/dlstats.png" width="890"/> |
43 | 43 |
|
45 | 45 |
deleted file mode 100644 |
... | ... |
@@ -1,20 +0,0 @@ |
1 |
-% Generated by roxygen2: do not edit by hand |
|
2 |
-% Please edit documentation in R/method-groupClade.R |
|
3 |
-\docType{methods} |
|
4 |
-\name{groupClade} |
|
5 |
-\alias{groupClade} |
|
6 |
-\alias{groupClade,ggtree-method} |
|
7 |
-\title{groupClade method} |
|
8 |
-\usage{ |
|
9 |
-\S4method{groupClade}{ggtree}(object, node, group_name) |
|
10 |
-} |
|
11 |
-\arguments{ |
|
12 |
-\item{object}{ggtree object} |
|
13 |
- |
|
14 |
-\item{node}{internal node number} |
|
15 |
- |
|
16 |
-\item{group_name}{name of the group} |
|
17 |
-} |
|
18 |
-\description{ |
|
19 |
-groupClade method for ggtree object |
|
20 |
-} |
21 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,22 +0,0 @@ |
1 |
-% Generated by roxygen2: do not edit by hand |
|
2 |
-% Please edit documentation in R/method-groupOTU.R |
|
3 |
-\docType{methods} |
|
4 |
-\name{groupOTU} |
|
5 |
-\alias{groupOTU} |
|
6 |
-\alias{groupOTU,ggtree-method} |
|
7 |
-\title{groupOTU method} |
|
8 |
-\usage{ |
|
9 |
-\S4method{groupOTU}{ggtree}(object, focus, group_name = "group", ...) |
|
10 |
-} |
|
11 |
-\arguments{ |
|
12 |
-\item{object}{ggtree object} |
|
13 |
- |
|
14 |
-\item{focus}{OTU to focus} |
|
15 |
- |
|
16 |
-\item{group_name}{name of the group} |
|
17 |
- |
|
18 |
-\item{...}{additional parameters} |
|
19 |
-} |
|
20 |
-\description{ |
|
21 |
-groupOTU method for ggtree object |
|
22 |
-} |
... | ... |
@@ -73,21 +73,21 @@ The `ggtree` package defined several functions to manipulate tree view. _`groupC |
73 | 73 |
Both _`groupClade`_ and _`groupOTU`_ work fine with tree and graphic object. |
74 | 74 |
|
75 | 75 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
76 |
-tree <- groupClade(tree, node=21) |
|
76 |
+tree <- groupClade(tree, .node=21) |
|
77 | 77 |
ggtree(tree, aes(color=group, linetype=group)) |
78 | 78 |
``` |
79 | 79 |
|
80 | 80 |
The following command will produce the same figure. |
81 | 81 |
|
82 | 82 |
```{r eval=FALSE} |
83 |
-ggtree(read.tree(nwk)) %>% groupClade(node=21) + aes(color=group, linetype=group) |
|
83 |
+ggtree(read.tree(nwk)) %>% groupClade(.node=21) + aes(color=group, linetype=group) |
|
84 | 84 |
``` |
85 | 85 |
|
86 | 86 |
|
87 | 87 |
With `groupClade` and `groupOTU`, it's easy to highlight selected taxa and easy to select taxa to display related features. |
88 | 88 |
|
89 | 89 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |
90 |
-tree <- groupClade(tree, node=c(21, 17)) |
|
90 |
+tree <- groupClade(tree, .node=c(21, 17)) |
|
91 | 91 |
ggtree(tree, aes(color=group, linetype=group)) + geom_tiplab(aes(subset=(group==2))) |
92 | 92 |
``` |
93 | 93 |
|
... | ... |
@@ -97,7 +97,7 @@ _`groupOTU`_ accepts a vector of OTUs (taxa name) or a list of OTUs. _`groupOTU |
97 | 97 |
|
98 | 98 |
|
99 | 99 |
```{r} |
100 |
-tree <- groupOTU(tree, focus=c("D", "E", "F", "G")) |
|
100 |
+tree <- groupOTU(tree, .node=c("D", "E", "F", "G")) |
|
101 | 101 |
``` |
102 | 102 |
|
103 | 103 |
```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE} |