Browse code

clean up code

guangchuang yu authored on 13/12/2017 14:33:32
Showing 10 changed files

... ...
@@ -179,7 +179,6 @@ importFrom(magrittr,equals)
179 179
 importFrom(methods,is)
180 180
 importFrom(methods,missingArg)
181 181
 importFrom(methods,setGeneric)
182
-importFrom(methods,setOldClass)
183 182
 importFrom(rvcheck,get_fun_from_pkg)
184 183
 importFrom(scales,alpha)
185 184
 importFrom(tibble,data_frame)
186 185
deleted file mode 100644
... ...
@@ -1,388 +0,0 @@
1
-## setOldClass("phylo")
2
-## setOldClass("multiPhylo")
3
-##' @importFrom methods setOldClass
4
-setOldClass("ggtree")
5
-
6
-
7
-## setClassUnion("phyloOrmultiPhylo", c("phylo", "multiPhylo"))
8
-
9
-
10
-supported_tree_object <- function() {
11
-    c("apeBootstrap",
12
-      "beast",
13
-      "codeml_mlc",
14
-      "codeml",
15
-      "hyphy",
16
-      "jplace",
17
-      "nhx",
18
-      "paml_rst",
19
-      "phangorn",
20
-      "phylip",
21
-      "r8s",
22
-      "raxml")
23
-}
24
-
25
-## ##' Class "apeBootstrap"
26
-## ##' This class stores ape bootstrapping analysis result
27
-## ##'
28
-## ##'
29
-## ##' @name apeBootstrap-class
30
-## ##' @docType class
31
-## ##' @slot phylo phylo object of treetext
32
-## ##' @slot fields available features
33
-## ##' @slot bootstrap bootstrap value
34
-## ##' @slot extraInfo extra information
35
-## ##' @exportClass apeBootstrap
36
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
37
-## ##' @keywords classes
38
-## setClass("apeBootstrap",
39
-##          representation = representation(
40
-##              phylo = "phylo",
41
-##              fields = "character",
42
-##              bootstrap = "data.frame",
43
-##              extraInfo = "data.frame"
44
-##          )
45
-##          )
46
-
47
-## ##' Class "beast"
48
-## ##' This class stores information of beast output
49
-## ##'
50
-## ##'
51
-## ##' @name beast-class
52
-## ##' @aliases beast-class
53
-## ##'      get.tree,beast-method
54
-## ##'
55
-## ##' @docType class
56
-## ##' @slot fields beast statistic variables
57
-## ##' @slot treetext tree text in beast file
58
-## ##' @slot phylo tree phylo object
59
-## ##' @slot translation tip number to name translation in beast file
60
-## ##' @slot stats beast statistics
61
-## ##' @slot file beast file, nexus format
62
-## ##' @slot extraInfo extra information
63
-## ##' @exportClass beast
64
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
65
-## ##' @seealso \code{\link{show}} \code{\link{get.fields}}
66
-## ##'           \code{\link{ggtree}}
67
-## ##' @keywords classes
68
-## setClass("beast",
69
-##          representation  = representation(
70
-##              fields      = "character",
71
-##              treetext    = "character",
72
-##              phylo       = "phylo",
73
-##              translation = "matrix",
74
-##              stats       = "data.frame",
75
-##              file        = "character",
76
-##              extraInfo   = "data.frame"
77
-##              )
78
-##          )
79
-
80
-
81
-## ##' Class "codeml_mlc"
82
-## ##' This class stores information of mlc file frm codeml output
83
-## ##'
84
-## ##'
85
-## ##' @name codeml_mlc-class
86
-## ##' @docType class
87
-## ##' @slot fields available features
88
-## ##' @slot treetext tree text
89
-## ##' @slot phylo phylo object
90
-## ##' @slot dNdS dN dS information
91
-## ##' @slot mlcfile mlc file
92
-## ##' @slot extraInfo extra information
93
-## ##' @exportClass codeml_mlc
94
-## ##' @author Guangchuang Yu
95
-## ##' @seealso \linkS4class{paml_rst} \linkS4class{codeml}
96
-## ##' @keywords classes
97
-## setClass("codeml_mlc",
98
-##          representation = representation(
99
-##              fields     = "character",
100
-##              treetext   = "character",
101
-##              phylo      = "phylo",
102
-##              dNdS       = "matrix",
103
-##              ## seq_type   = "character",
104
-##              ## tip_seq    = "character",
105
-##              mlcfile    = "character",
106
-##              extraInfo  = "data.frame"
107
-##              )
108
-##          )
109
-
110
-## ##' Class "paml_rst"
111
-## ##' This class stores information of rst file from PAML output
112
-## ##'
113
-## ##'
114
-## ##' @name paml_rst-class
115
-## ##' @aliases paml_rst-class
116
-## ##'   set.subs,paml_rst-method
117
-## ##'   set.subs<-,paml_rst-method
118
-## ##'
119
-## ##' @docType class
120
-## ##' @slot fields availabel attributes
121
-## ##' @slot treetext tree text
122
-## ##' @slot phylo phylo object
123
-## ##' @slot seq_type one of "NT" and "AA"
124
-## ##' @slot tip_seq sequences of tips
125
-## ##' @slot marginal_ancseq Marginal reconstruction of ancestral sequences
126
-## ##' @slot joint_ancseq Joint reconstruction of ancestral sequences
127
-## ##' @slot marginal_subs sequence substitutions based on marginal_ancseq
128
-## ##' @slot joint_subs sequence substitutions based on joint_ancseq
129
-## ##' @slot marginal_AA_subs Amino acid sequence substitutions based on marginal_ancseq
130
-## ##' @slot joint_AA_subs Amino acid sequence substitutions based on joint_ancseq
131
-## ##' @slot rstfile rst file
132
-## ##' @slot extraInfo extra information
133
-## ##' @exportClass paml_rst
134
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
135
-## ##' @seealso \linkS4class{codeml} \linkS4class{codeml_mlc}
136
-## ##' @keywords classes
137
-## setClass("paml_rst",
138
-##          representation       = representation(
139
-##              fields           = "character",
140
-##              treetext         = "character",
141
-##              phylo            = "phylo",
142
-##              seq_type         = "character",
143
-##              tip_seq          = "character",
144
-##              marginal_ancseq  = "character",
145
-##              joint_ancseq     = "character",
146
-##              marginal_subs    = "data.frame",
147
-##              joint_subs       = "data.frame",
148
-##              marginal_AA_subs = "data.frame",
149
-##              joint_AA_subs    = "data.frame",
150
-##              rstfile          = "character",
151
-##              extraInfo        = "data.frame"
152
-##          )
153
-##          )
154
-
155
-## ##' Class "codeml"
156
-## ##' This class stores information of output from codeml
157
-## ##'
158
-## ##'
159
-## ##' @name codeml-class
160
-## ##' @docType class
161
-## ##' @slot mlc A \code{code_mlc} object
162
-## ##' @slot rst A \code{paml_rst} object
163
-## ##' @slot extraInfo extra information
164
-## ##' @exportClass codeml
165
-## ##' @seealso \linkS4class{codeml_mlc} \linkS4class{paml_rst}
166
-## ##' @keywords codeml
167
-## setClass("codeml",
168
-##          representation = representation(
169
-##              mlc       = "codeml_mlc",
170
-##              rst       = "paml_rst",
171
-##              extraInfo = "data.frame"
172
-##              )
173
-##          )
174
-
175
-
176
-
177
-## ##' Class "hyphy"
178
-## ##' This class stores information of HYPHY output
179
-## ##'
180
-## ##'
181
-## ##' @name hyphy-class
182
-## ##' @docType class
183
-## ##' @slot fields available features
184
-## ##' @slot treetext tree text
185
-## ##' @slot phylo phylo object
186
-## ##' @slot seq_type one of "NT" and "AA"
187
-## ##' @slot subs sequence substitutions
188
-## ##' @slot AA_subs Amino acid sequence substitution
189
-## ##' @slot ancseq ancestral sequences
190
-## ##' @slot tip_seq tip sequences
191
-## ##' @slot tip.fasfile fasta file of tip sequences
192
-## ##' @slot tree.file tree file
193
-## ##' @slot ancseq.file ancestral sequence file, nexus format
194
-## ##' @slot extraInfo extra information
195
-## ##' @exportClass hyphy
196
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
197
-## ##' @seealso \linkS4class{paml_rst}
198
-## ##' @keywords classes
199
-## setClass("hyphy",
200
-##          representation  = representation(
201
-##              fields      = "character",
202
-##              treetext    = "character",
203
-##              phylo       = "phylo",
204
-##              seq_type    = "character",
205
-##              subs        = "data.frame",
206
-##              AA_subs     = "data.frame",
207
-##              ancseq      = "character",
208
-##              tip_seq     = "character",
209
-##              tip.fasfile = "character",
210
-##              tree.file   = "character",
211
-##              ancseq.file = "character",
212
-##              extraInfo   = "data.frame"
213
-##              )
214
-##          )
215
-
216
-## ##' Class "jplace"
217
-## ##' This class stores information of jplace file.
218
-## ##'
219
-## ##'
220
-## ##' @name jplace-class
221
-## ##' @aliases jplace-class
222
-## ##'   show,jplace-method
223
-## ##'   get.placements,jplace-method
224
-## ##'   get.treeinfo,jplace-method
225
-## ##'   get.fields,jplace-method
226
-## ##'   get.treetext,jplace-method
227
-## ##'
228
-## ##' @docType class
229
-## ##' @slot fields colnames of first variable of placements
230
-## ##' @slot treetext tree text
231
-## ##' @slot phylo tree phylo object
232
-## ##' @slot placements placement information
233
-## ##' @slot version version
234
-## ##' @slot metadata metadata
235
-## ##' @slot file jplace file
236
-## ##' @slot extraInfo extra information
237
-## ##' @exportClass jplace
238
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
239
-## ##' @seealso \code{\link{show}} \code{\link{get.tree}}
240
-## ##'          \code{\link{ggtree}}
241
-## ##' @keywords classes
242
-## setClass("jplace",
243
-##          representation = representation(
244
-##              fields     = "character",
245
-##              treetext   = "character",
246
-##              phylo      = "phylo",
247
-##              placements = "data.frame",
248
-##              version    = "numeric",
249
-##              metadata   = "list",
250
-##              file       = "character",
251
-##              extraInfo  = "data.frame"
252
-##              )
253
-##          )
254
-
255
-
256
-## ##' Class "nhx"
257
-## ##' This class stores nhx tree
258
-## ##'
259
-## ##'
260
-## ##' @name nhx-class
261
-## ##' @rdname nhx-class
262
-## ##' @docType class
263
-## ##' @slot file input file
264
-## ##' @slot fields available feature
265
-## ##' @slot phylo phylo object
266
-## ##' @slot nhx_tags tag information in nhx file
267
-## ##' @slot extraInfo extra information
268
-## ##' @exportClass nhx
269
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
270
-## ##' @keywords classes
271
-## setClass("nhx",
272
-##          representation = representation(
273
-##              file = "character",
274
-##              fields = "character",
275
-##              phylo = "phylo",
276
-##              nhx_tags = "data.frame",
277
-##              extraInfo = "data.frame"
278
-##          )
279
-##          )
280
-
281
-
282
-## ##' Class "phangorn"
283
-## ##' This class stores ancestral sequences inferred from 'phangorn'
284
-## ##'
285
-## ##'
286
-## ##' @name phangorn-class
287
-## ##' @docType class
288
-## ##' @slot fields available attributes
289
-## ##' @slot phylo phylo object
290
-## ##' @slot seq_type one of "NT" and "AA"
291
-## ##' @slot tip_seq sequences of tips
292
-## ##' @slot ancseq ancenstral sequences
293
-## ##' @slot subs sequence substitution
294
-## ##' @slot AA_subs Amino acid sequence substitution
295
-## ##' @slot extraInfo extra information
296
-## ##' @exportClass phangorn
297
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
298
-## ##' @seealso \linkS4class{paml_rst}
299
-## ##' @keywords classes
300
-## setClass("phangorn",
301
-##          representation = representation(
302
-##              fields = "character",
303
-##              phylo = "phylo",
304
-##              seq_type = "character",
305
-##              tip_seq = "character",
306
-##              ancseq = "character",
307
-##              subs = "data.frame",
308
-##              AA_subs = "data.frame",
309
-##              extraInfo = "data.frame")
310
-##          )
311
-
312
-
313
-
314
-## ##' Class "phylip"
315
-## ##' This class stores phylip tree(s)
316
-## ##'
317
-## ##'
318
-## ##' @name phylip-class
319
-## ##' @docType class
320
-## ##' @slot file input file
321
-## ##' @slot fields available feature
322
-## ##' @slot phylo phylo or multiPhylo
323
-## ##' @slot ntree number of trees
324
-## ##' @slot sequence sequences
325
-## ##' @slot extraInfo extra information
326
-## ##' @exportClass phylip
327
-## ##' @author Guangchuang Yu
328
-## ##' @keywords classes
329
-## setClass("phylip",
330
-##          representation = representation(
331
-##              file = "character",
332
-##              fields = "character",
333
-##              phylo = "phyloOrmultiPhylo",
334
-##              ntree = "numeric",
335
-##              sequence = "character",
336
-##              extraInfo = "data.frame")
337
-##          )
338
-
339
-
340
-## ##' Class "r8s"
341
-## ##' This class stores output info from r8s
342
-## ##'
343
-## ##'
344
-## ##' @name r8s-class
345
-## ##' @docType class
346
-## ##' @slot file input file
347
-## ##' @slot fields available feature
348
-## ##' @slot treetext tree text
349
-## ##' @slot phylo multiPhylo, time tree, rate tree and absolute substitution tree
350
-## ##' @slot extraInfo extra information
351
-## ##' @exportClass r8s
352
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
353
-## ##' @keywords classes
354
-## setClass("r8s",
355
-##          representation = representation(
356
-##              file      = "character",
357
-##              fields    = "character",
358
-##              treetext  = "character",
359
-##              phylo     = "multiPhylo",
360
-##              extraInfo = "data.frame"
361
-##              )
362
-##          )
363
-
364
-
365
-## ##' Class "raxml"
366
-## ##' This class stores RAxML bootstrapping analysis result
367
-## ##'
368
-## ##'
369
-## ##' @name raxml-class
370
-## ##' @docType class
371
-## ##' @slot file input file
372
-## ##' @slot fields available features
373
-## ##' @slot treetext tree text
374
-## ##' @slot phylo phylo object of treetext
375
-## ##' @slot bootstrap bootstrap value
376
-## ##' @slot extraInfo extra information
377
-## ##' @exportClass raxml
378
-## ##' @author Guangchuang Yu \url{http://guangchuangyu.github.io}
379
-## ##' @keywords classes
380
-## setClass("raxml",
381
-##          representation = representation(
382
-##              file       = "character",
383
-##              treetext   = "character"
384
-##          ),
385
-##          contains = "apeBootstrap"
386
-##          )
387
-
388
-
... ...
@@ -12,7 +12,7 @@ as.binary <- function(tree, ...) {
12 12
 ##' @name reroot
13 13
 ##' @rdname reroot-methods
14 14
 ##' @title reroot method
15
-##' @param object one of \code{phylo}, \code{nhx}, \code{phangorn}, \code{jplace}, \code{beast}, \code{hyphy}, \code{codeml}, \code{codeml_mlc}, \code{paml_rst} object
15
+##' @param object \code{treedata} object
16 16
 ##' @param node internal nnode number
17 17
 ##' @param ... additional parameter
18 18
 ##' @return tree object
... ...
@@ -20,6 +20,7 @@ as.binary <- function(tree, ...) {
20 20
 ##' @export
21 21
 setGeneric("reroot", function(object, node, ...) standardGeneric("reroot"))
22 22
 
23
+## may change to implement ape::root method
23 24
 
24 25
 ##' @docType methods
25 26
 ##' @name scale_color
... ...
@@ -13,13 +13,7 @@ MRCA <- function(obj, tip) {
13 13
         return(getMRCA.df(obj$data, tip))
14 14
     }
15 15
 
16
-    if(class(obj) %in% supported_tree_object()) {
17
-        obj <- get.tree(obj)
18
-    }
19
-    if (class(obj) == "phylo") {
20
-        return(getMRCA(obj, tip))
21
-    }
22
-    stop("obj is not supported...")
16
+    getMRCA(as.phylo(obj), tip)
23 17
 }
24 18
 
25 19
 
26 20
deleted file mode 100644
... ...
@@ -1,95 +0,0 @@
1
-## ##' parse RAxML bootstrapping analysis output
2
-## ##'
3
-## ##' 
4
-## ##' @title read.raxml
5
-## ##' @param file RAxML bootstrapping analysis output
6
-## ##' @return raxml object
7
-## ##' @export
8
-## ##' @author Guangchuang Yu
9
-## read.raxml <- function(file) {
10
-##     tree.text <- readLines(file)
11
-##     tree_text <- gsub('(:[0-9\\.eE+\\-]+)\\[(\\d+)\\]', '\\@\\2\\1', tree.text)
12
-##     phylo <- read.tree(text=tree_text)
13
-##     if(any(grepl('@', phylo$node.label))) {
14
-##         bootstrap <- as.numeric(gsub("[^@]*@(\\d+)", "\\1", phylo$node.label))
15
-##         phylo$node.label <- gsub("@\\d+", "", phylo$node.label)
16
-##     }
17
-
18
-##     if (all(phylo$node.label == "")) {
19
-##         phylo$node.label <- NULL
20
-##     }
21
-
22
-##     bootstrap <- data.frame(node = Ntip(phylo) + 1:phylo$Nnode,
23
-##                             bootstrap = bootstrap)
24
-
25
-##     new("raxml",
26
-##         file      = file,
27
-##         fields    = "bootstrap",
28
-##         treetext  = tree.text,
29
-##         phylo     = phylo,
30
-##         bootstrap = bootstrap
31
-##         )
32
-## }
33
-
34
-
35
-## ##' @rdname show-methods
36
-## ##' @importFrom ape print.phylo
37
-## ##' @exportMethod show
38
-## setMethod("show", signature(object = "raxml"),
39
-##           function(object) {
40
-##               cat("'raxml' S4 object that stored information of\n\t",
41
-##                   paste0("'", object@file, "'.\n\n"))
42
-##               cat("...@ tree: ")
43
-##               print.phylo(get.tree(object))                  
44
-##               cat("\nwith the following features available:\n")
45
-##               print_fields(object)
46
-##           })
47
-
48
-## ##' @rdname groupOTU-methods
49
-## ##' @exportMethod groupOTU
50
-## setMethod("groupOTU", signature(object="raxml"),
51
-##           function(object, focus, group_name="group") {
52
-##               groupOTU_(object, focus, group_name)
53
-##           }
54
-##           )
55
-
56
-## ##' @rdname groupClade-methods
57
-## ##' @exportMethod groupClade
58
-## setMethod("groupClade", signature(object="raxml"),
59
-##           function(object, node, group_name="group") {
60
-##               groupClade_(object, node, group_name)
61
-##           })
62
-
63
-## ##' @rdname scale_color-methods
64
-## ##' @exportMethod scale_color
65
-## setMethod("scale_color", signature(object="raxml"),
66
-##           function(object, by="bootstrap", ...) {
67
-##               scale_color_(object, by, ...)
68
-##           })
69
-
70
-
71
-## ##' @rdname gzoom-methods
72
-## ##' @exportMethod gzoom
73
-## setMethod("gzoom", signature(object="raxml"),
74
-##           function(object, focus, subtree=FALSE, widths=c(.3, .7)) {
75
-##               gzoom.phylo(get.tree(object), focus, subtree, widths)
76
-##           })
77
-
78
-
79
-## ##' @rdname get.tree-methods
80
-## ##' @exportMethod get.tree
81
-## setMethod("get.tree", signature(object="raxml"),
82
-##           function(object,...) {
83
-##               object@phylo
84
-##           }
85
-##           )
86
-
87
-
88
-## ##' @rdname get.fields-methods
89
-## ##' @exportMethod get.fields
90
-## setMethod("get.fields", signature(object="raxml"),
91
-##           function(object, ...) {
92
-##               get.fields.tree(object)
93
-##           }
94
-##           )
95
-
96 0
deleted file mode 100644
... ...
@@ -1,15 +0,0 @@
1
-##' merge phylo and output of boot.phylo to 'apeBootstrap' object
2
-##'
3
-##'
4
-##' @title apeBoot
5
-##' @param phylo phylo
6
-##' @param boot bootstrap values
7
-##' @return an instance of 'apeBootstrap'
8
-##' @importFrom treeio as.treedata
9
-##' @export
10
-##' @author Guangchuang Yu
11
-apeBoot <- function(phylo, boot) {
12
-    message("this function was deprecated, please use treeio::as.treedata")
13
-    as.treedata(phylo, boot)
14
-}
15
-
... ...
@@ -9,240 +9,6 @@ get_tree_view <- function(tree_view) {
9 9
     return(tree_view)
10 10
 }
11 11
 
12
-
13
-
14
-## has.field <- function(tree_object, field) {
15
-##     if ( ! field %in% get.fields(tree_object) ) {
16
-##         return(FALSE)
17
-##     }
18
-
19
-##     if (is(tree_object, "codeml")) {
20
-##         is_codeml <- TRUE
21
-##         tree <- tree_object@rst
22
-##     } else {
23
-##         is_codeml <- FALSE
24
-##         tree <- tree_object
25
-##     }
26
-
27
-##     if (.hasSlot(tree, field)) {
28
-##         has_slot <- TRUE
29
-##     } else {
30
-##         has_slot <- FALSE
31
-##     }
32
-
33
-##     if (has_slot == FALSE) {
34
-##         if (has.extraInfo(tree_object) == FALSE) {
35
-##             return(FALSE)
36
-##         }
37
-
38
-##         if (nrow(tree_object@extraInfo) == 0) {
39
-##             return(FALSE)
40
-##         }
41
-
42
-##         if (!field %in% colnames(tree_object@extraInfo)) {
43
-##             return(FALSE)
44
-##         }
45
-##     }
46
-##     res <- TRUE
47
-##     attr(res, "has_slot") <- has_slot
48
-##     attr(res, "is_codeml") <- is_codeml
49
-##     return(res)
50
-## }
51
-
52
-## append_extraInfo <- function(df, object) {
53
-##     if (has.extraInfo(object)) {
54
-##         info <- object@extraInfo
55
-##         if ("parent" %in% colnames(info)) {
56
-##             res <- merge(df, info, by.x=c("node", "parent"), by.y=c("node", "parent"))
57
-##         } else {
58
-##             res <- merge(df, info, by.x="node", by.y="node")
59
-##         }
60
-##     } else {
61
-##         return(df)
62
-##     }
63
-
64
-##     i <- order(res$node, decreasing = FALSE)
65
-##     res <- res[i,]
66
-##     return(res)
67
-## }
68
-
69
-## get.fields.tree <- function(object) {
70
-##     if (is(object, "codeml")) {
71
-##         fields <- c(get.fields(object@rst),
72
-##                     get.fields(object@mlc))
73
-##         fields <- unique(fields)
74
-##     } else {
75
-##         fields <- object@fields
76
-##     }
77
-
78
-##     if (has.slot(object, "extraInfo")) {
79
-##         extraInfo <- object@extraInfo
80
-##         if (nrow(extraInfo) > 0) {
81
-##             cn <- colnames(extraInfo)
82
-##             i <- match(c("x", "y", "isTip", "node", "parent", "label", "branch", "branch.length"), cn)
83
-##             i <- i[!is.na(i)]
84
-##             fields %<>% c(cn[-i])
85
-##         }
86
-##     }
87
-##     return(fields)
88
-## }
89
-
90
-## print_fields <- function(object, len=5) {
91
-##     fields <- get.fields(object)
92
-##     n <- length(fields)
93
-##     i <- floor(n/len)
94
-##     for (j in 0:i) {
95
-##         ii <- 1:len + len * j
96
-##         if (j == i) {
97
-##             x <- n %% len
98
-##             if (x == 0) {
99
-##                 ii <- NULL
100
-##             } else {
101
-##                 ii <- ii[1:x]
102
-##             }
103
-##         }
104
-
105
-##         if (!is.null(ii)) {
106
-##             cat("\t", paste0("'",
107
-##                              paste(fields[ii], collapse="',\t'"),
108
-##                              "'")
109
-##                 )
110
-##         }
111
-##         if ( j == i) {
112
-##             cat(".\n")
113
-##         } else {
114
-##             cat(",\n")
115
-##         }
116
-##     }
117
-## }
118
-
119
-## plot.subs <- function(x, layout, show.tip.label,
120
-##                       tip.label.size,
121
-##                       tip.label.hjust,
122
-##                       position, annotation,
123
-##                       annotation.color = "black",
124
-##                       annotation.size=3, ...) {
125
-
126
-##     p <- ggtree(x, layout=layout, ...)
127
-##     if (show.tip.label) {
128
-##         p <- p + geom_tiplab(hjust = tip.label.hjust,
129
-##                              size  = tip.label.size)
130
-##     }
131
-##     if (!is.null(annotation) && !is.na(annotation)) {
132
-##         p <- p + geom_text(aes_string(x=position, label=annotation),
133
-##                            size=annotation.size,
134
-##                            color=annotation.color, vjust=-.5)
135
-##     }
136
-##     p + theme_tree2()
137
-## }
138
-
139
-## .add_new_line <- function(res) {
140
-##     ## res <- paste0(strwrap(res, 50), collapse="\n")
141
-##     ## res %<>% gsub("\\s/\n", "\n", .) %>% gsub("\n/\\s", "\n", .)
142
-##     if (nchar(res) > 50) {
143
-##         idx <- gregexpr("/", res)[[1]]
144
-##         i <- idx[floor(length(idx)/2)]
145
-##         res <- paste0(substring(res, 1, i-1), "\n", substring(res, i+1))
146
-##     }
147
-##     return(res)
148
-## }
149
-
150
-## get.subs_ <- function(tree, fasta, translate=TRUE, removeGap=TRUE) {
151
-##     N <- getNodeNum(tree)
152
-##     node <- 1:N
153
-##     parent <- sapply(node, getParent, tr=tree)
154
-##     label <- getNodeName(tree)
155
-##     subs <- sapply(seq_along(node), function(i) {
156
-##         if (i == getRoot(tree)) {
157
-##             return(NA)
158
-##         }
159
-##         res <- getSubsLabel(fasta, label[parent[i]], label[i], translate, removeGap)
160
-##         if (is.null(res)) {
161
-##             return('')
162
-##         }
163
-##         .add_new_line(res)
164
-##     })
165
-
166
-##     dd <- data.frame(node=node, parent=parent, label=label, subs=subs)
167
-##     dd <- dd[dd$parent != 0,]
168
-##     dd <- dd[, -c(1,2)]
169
-##     dd[,1] <- as.character(dd[,1])
170
-##     dd[,2] <- as.character(dd[,2])
171
-##     return(dd)
172
-## }
173
-
174
-## getSubsLabel <- function(seqs, A, B, translate, removeGap) {
175
-##     seqA <- seqs[A]
176
-##     seqB <- seqs[B]
177
-
178
-##     if (nchar(seqA) != nchar(seqB)) {
179
-##         stop("seqA should have equal length to seqB")
180
-##     }
181
-
182
-##     if (translate == TRUE) {
183
-##         AA <- seqA %>% seq2codon %>% codon2AA
184
-##         BB <- seqB %>% seq2codon %>% codon2AA
185
-##     } else {
186
-##         ## strsplit is faster than substring
187
-##         ##
188
-##         ## n <- nchar(seqA) ## should equals to nchar(seqB)
189
-##         ## AA <- substring(seqA, 1:n, 1:n)
190
-##         ## BB <- substring(seqB, 1:n, 1:n)
191
-##         AA <- strsplit(seqA, split="") %>% unlist
192
-##         BB <- strsplit(seqB, split="") %>% unlist
193
-##     }
194
-
195
-##     ii <- which(AA != BB)
196
-
197
-##     if (removeGap == TRUE) {
198
-##         if (length(ii) > 0 && translate == TRUE) {
199
-##             ii <- ii[AA[ii] != "X" & BB[ii] != "X"]
200
-##         }
201
-
202
-##         if (length(ii) > 0 && translate == FALSE) {
203
-##             ii <- ii[AA[ii] != "-" & BB[ii] != "-"]
204
-##         }
205
-##     }
206
-
207
-##     if (length(ii) == 0) {
208
-##         return(NULL)
209
-##     }
210
-
211
-##     res <- paste(AA[ii], ii, BB[ii], sep="", collapse=" / ")
212
-##     return(res)
213
-## }
214
-
215
-## seq2codon <- function(x) {
216
-##     substring(x, first=seq(1, nchar(x)-2, 3), last=seq(3, nchar(x), 3))
217
-## }
218
-
219
-## ## @importFrom Biostrings GENETIC_CODE
220
-## codon2AA <- function(codon) {
221
-##     ## a genetic code name vector
222
-##     GENETIC_CODE <- get_fun_from_pkg("Biostrings", "GENETIC_CODE")
223
-##     aa <- GENETIC_CODE[codon]
224
-##     aa[is.na(aa)] <- "X"
225
-##     return(aa)
226
-## }
227
-
228
-
229
-## getPhyInfo <- function(phy) {
230
-##     line1 <- readLines(phy, n=1)
231
-##     res <- strsplit(line1, split="\\s")[[1]]
232
-##     res <- res[res != ""]
233
-
234
-##     return(list(num=as.numeric(res[1]), width=as.numeric(res[2])))
235
-## }
236
-
237
-## get_seqtype <- function(seq) {
238
-##     if (length(grep("[^-ACGT]+", seq[1])) == 0) {
239
-##         seq_type = "NT" ## NucleoTide
240
-##     } else {
241
-##         seq_type = "AA" ## Amino Acid
242
-##     }
243
-##     return(seq_type)
244
-## }
245
-
246 12
 reverse.treeview <- function(tv) {
247 13
     tv$data <- reverse.treeview.data(tv$data)
248 14
     return(tv)
... ...
@@ -256,91 +22,6 @@ reverse.treeview.data <- function(df) {
256 22
 }
257 23
 
258 24
 
259
-## jplace_treetext_to_phylo <- function(tree.text) {
260
-##     ## move edge label to node label separate by @
261
-##     tr <- gsub('(:[0-9\\.eE\\+\\-]+)\\{(\\d+)\\}', '\\@\\2\\1', tree.text)
262
-##     phylo <- read.tree(text=tr)
263
-##     if (length(grep('@', phylo$tip.label)) > 0) {
264
-##         phylo$node.label[1] %<>% gsub("(.*)\\{(\\d+)\\}", "\\1@\\2", .)
265
-##         tip.edgeNum <- as.numeric(gsub("[^@]*@(\\d*)", "\\1",phylo$tip.label))
266
-##         node.edgeNum <- as.numeric(gsub("[^@]*@(\\d*)", "\\1",phylo$node.label))
267
-##         phylo$tip.label %<>% gsub("@\\d+", "", .)
268
-##         phylo$node.label %<>% gsub("@\\d+", "", .)
269
-##         if (all(phylo$node.label == "")) {
270
-##             phylo$node.label <- NULL
271
-##         }
272
-
273
-##         N <- getNodeNum(phylo)
274
-##         edgeNum.df <- data.frame(node=1:N, edgeNum=c(tip.edgeNum, node.edgeNum))
275
-##         ## root node is not encoded with edge number
276
-##         edgeNum.df <- edgeNum.df[!is.na(edgeNum.df[,2]),]
277
-##         attr(phylo, "edgeNum") <- edgeNum.df
278
-##     }
279
-
280
-##     ## using :edge_length{edge_num} to match edge_num to node_num
281
-##     ## this is not a good idea since there may exists identical edge_length.
282
-##     ## but we can use it to verify our method.
283
-##     ##
284
-##     ## en.matches <- gregexpr(":[0-9\\.eE\\+\\-]+\\{\\d+\\}", tree.text)
285
-##     ## matches <- en.matches[[1]]
286
-##     ## match.pos <- as.numeric(matches)
287
-##     ## match.len <- attr(matches, 'match.length')
288
-
289
-##     ## edgeLN <- substring(tree.text, match.pos+1, match.pos+match.len-2)
290
-##     ## edgeLN.df <- data.frame(length=as.numeric(gsub("\\{.+", "", edgeLN)),
291
-##     ##                         edgeNum = as.numeric(gsub(".+\\{", "", edgeLN)))
292
-
293
-##     ## xx <- merge(edgeLN.df, edgeNum.df, by.x="node", by.y="node")
294
-
295
-##     return(phylo)
296
-## }
297
-
298
-extract.treeinfo.jplace <- function(object, layout="rectangular", ladderize=TRUE, right=FALSE, ...) {
299
-
300
-    tree <- get.tree(object)
301
-
302
-    df <- fortify.phylo(tree, layout=layout, ladderize=ladderize, right=right, ...)
303
-
304
-    edgeNum.df <- attr(tree, "edgeNum")
305
-    if (!is.null(edgeNum.df)) {
306
-        df2 <- merge(df, edgeNum.df, by.x="node", by.y="node", all.x=TRUE)
307
-        df <- df2[match(df[, "node"], df2[, "node"]),]
308
-    }
309
-
310
-    attr(df, "ladderize") <- ladderize
311
-    attr(df, "right") <- right
312
-    return(df)
313
-}
314
-
315
-## ## convert edge number to node number for EPA/pplacer output
316
-## edgeNum2nodeNum <- function(jp, edgeNum) {
317
-##     edges <- attr(jp@phylo, "edgeNum")
318
-
319
-##     idx <- which(edges$edgeNum == edgeNum)
320
-##     if (length(idx) == 0) {
321
-##         return(NA)
322
-##     }
323
-
324
-##     edges[idx, "node"]
325
-## }
326
-
327
-## is.character_beast <- function(stats3, cn) {
328
-##     for (i in 1:nrow(stats3)) {
329
-##         if ( is.na(stats3[i,cn]) ) {
330
-##             next
331
-##         } else {
332
-##             ## res <- grepl("[a-df-zA-DF-Z]+", unlist(stats3[i, cn]))
333
-##             ## return(all(res == TRUE))
334
-##             res <- grepl("^[0-9\\.eE-]+$", unlist(stats3[i, cn]))
335
-##             return(all(res == FALSE))
336
-##         }
337
-##     }
338
-##     return(FALSE)
339
-## }
340
-
341
-
342
-
343
-
344 25
 color_scale <- function(c1="grey", c2="red", n=100) {
345 26
     pal <- colorRampPalette(c(c1, c2))
346 27
     colors <- pal(n)
... ...
@@ -384,22 +65,6 @@ is.tree_attribute_ <- function(p, var) {
384 65
 
385 66
 
386 67
 
387
-
388
-## `%IN%` <- function(x, table) {
389
-##     ii <- NULL ## satisify codetools
390
-##     idx <- match(x, table, nomatch=NA)
391
-##     ii <<- idx[!is.na(idx)]
392
-##     res <- as.logical(idx)
393
-##     res[is.na(res)] <- FALSE
394
-##     return(res)
395
-## }
396
-## geom_nplace <- function(data, map, place, ...) {
397
-##     label <- NULL
398
-##     ii <- 1:nrow(data)
399
-##     geom_text(subset=.(label %IN% data[[map]]), label = data[ii, place], ...)
400
-## }
401
-
402
-
403 68
 roundDigit <- function(d) {
404 69
     i <- 0
405 70
     while(d < 1) {
... ...
@@ -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
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.10.0-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.11.3-green.svg?style=flat)](https://github.com/guangchuangyu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-22199/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1218/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
7
+[![releaseVersion](https://img.shields.io/badge/release%20version-1.10.0-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.11.3-green.svg?style=flat)](https://github.com/guangchuangyu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-22348/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1218/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
8 8
 
9
-[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--12--11-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
9
+[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--12--13-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
10 10
 
11 11
 [![platform](http://www.bioconductor.org/shields/availability/devel/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [![Build Status](http://www.bioconductor.org/shields/build/devel/bioc/ggtree.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [![Linux/Mac Travis Build Status](https://img.shields.io/travis/GuangchuangYu/ggtree/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/GuangchuangYu/ggtree) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/Guangchuangyu/ggtree/master.svg?label=Windows)](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [![Backers on Open Collective](https://opencollective.com/ggtree/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/ggtree/sponsors/badge.svg)](#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
-[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![Altmetric](https://img.shields.io/badge/Altmetric-334-green.svg?style=flat)](https://www.altmetric.com/details/10533079) [![citation](https://img.shields.io/badge/cited%20by-53-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627)
30
+[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![Altmetric](https://img.shields.io/badge/Altmetric-325-green.svg?style=flat)](https://www.altmetric.com/details/10533079) [![citation](https://img.shields.io/badge/cited%20by-54-green.svg?style=flat)](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
-[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-22199/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1218/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
40
+[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-22348/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1218/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
41 41
 
42 42
 <img src="docs/images/dlstats.png" width="890"/>
43 43
 
44 44
Binary files a/docs/images/citation.png and b/docs/images/citation.png differ
... ...
@@ -4,7 +4,7 @@ test_that('groupOTU', {
4 4
     nwk <- system.file("extdata", "sample.nwk", package="treeio")
5 5
     tree <- read.tree(nwk)
6 6
     focus <- c("D", "E", "F", "G")
7
-    df <- fortify(groupOTU(tree, focus=focus))
7
+    df <- fortify(groupOTU(tree, focus))
8 8
     expect_true(all(df$group[df$label %in% focus] == 1))
9 9
 
10 10
     cls <- list(c1=c("A", "B", "C", "D", "E"),
... ...
@@ -25,7 +25,7 @@ test_that('groupClade', {
25 25
     tree <- read.tree(nwk)
26 26
     focus <- c("D", "E", "F", "G")
27 27
     nodes <- c(21, 17)
28
-    df <- fortify(groupClade(tree, node=nodes))
28
+    df <- fortify(groupClade(tree, nodes))
29 29
 
30 30
     for (i in seq_along(nodes)) {
31 31
         expect_true(all(df$group[df$node %in% ggtree:::get.offspring.df(df, nodes[i])] == i))