Browse code

update vignette

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

Guangchuang Yu authored on 28/12/2015 11:35:22
Showing 9 changed files

... ...
@@ -71,30 +71,6 @@ setClass("r8s",
71 71
              )
72 72
          )
73 73
 
74
-##' Class "r8s"
75
-##' This class stores output info from r8s
76
-##'
77
-##'
78
-##' @name r8s-class
79
-##' @docType class
80
-##' @slot file input file
81
-##' @slot fields available feature
82
-##' @slot treetext tree text
83
-##' @slot phylo multiPhylo, time tree, rate tree and absolute substitution tree
84
-##' @slot extraInfo extra information
85
-##' @exportClass r8s
86
-##' @author Guangchuang Yu \url{http://ygc.name}
87
-##' @keywords classes
88
-setClass("r8s",
89
-         representation = representation(
90
-             file      = "character",
91
-             fields    = "character",
92
-             treetext  = "character",
93
-             phylo     = "multiPhylo",
94
-             extraInfo = "data.frame"
95
-         )
96
-         )
97
-
98 74
 ##' Class "nhx"
99 75
 ##' This class stores nhx tree
100 76
 ##'
... ...
@@ -31,16 +31,17 @@
31 31
 ##' tr <- rtree(10)
32 32
 ##' ggtree(tr)
33 33
 ggtree <- function(tr,
34
-                   mapping = NULL,
35
-                   showDistance=FALSE,
36
-                   layout="rectangular",
37
-                   mrsd = NULL,
38
-                   as.Date = FALSE,
39
-                   yscale="none",
34
+                   mapping        = NULL,
35
+                   layout         = "rectangular",
36
+                   mrsd           = NULL,
37
+                   as.Date        = FALSE,
38
+                   yscale         = "none",
40 39
                    yscale_mapping = NULL,
41
-                   ladderize = TRUE, right=FALSE,
42
-                   branch.length="branch.length",
43
-                   ndigits = NULL, ...) {
40
+                   ladderize      = TRUE,
41
+                   right          = FALSE,
42
+                   branch.length  = "branch.length",
43
+                   ndigits        = NULL,
44
+                   ...) {
44 45
 
45 46
     layout %<>% match.arg(c("rectangular", "slanted", "fan", "circular", "radial", "unrooted"))
46 47
 
... ...
@@ -48,7 +49,6 @@ ggtree <- function(tr,
48 49
         branch.length = "TREE"
49 50
     }
50 51
     
51
-    d <- x <- y <- NULL
52 52
     if(yscale != "none") {
53 53
         ## for 2d tree
54 54
         layout <- "slanted"
... ...
@@ -63,9 +63,9 @@ ggtree <- function(tr,
63 63
         type <- "none"
64 64
     }
65 65
     if (is.null(mapping)) {
66
-        mapping <- aes(x, y)
66
+        mapping <- aes_(~x, ~y)
67 67
     } else {
68
-        mapping <- modifyList(aes(x, y), mapping)
68
+        mapping <- modifyList(aes_(~x, ~y), mapping)
69 69
     }
70 70
     p <- ggplot(tr, mapping=mapping,
71 71
                 layout        = layout,
... ...
@@ -78,7 +78,7 @@ ggtree <- function(tr,
78 78
                 branch.length = branch.length,
79 79
                 ndigits       = ndigits, ...)
80 80
     
81
-    p <- p + geom_tree(layout, ...) + xlab("") + ylab("") + theme_tree2()
81
+    p <- p + geom_tree(layout, ...) + xlab(NULL) + ylab(NULL) + theme_tree()
82 82
     
83 83
     if (type == "circular" || type == "radial") {
84 84
         p <- p + coord_polar(theta = "y")
... ...
@@ -87,9 +87,6 @@ ggtree <- function(tr,
87 87
         p <- p + scale_y_continuous(limits=c(0, max(p$data$y)))
88 88
     } 
89 89
     
90
-    if (showDistance == FALSE) {
91
-        p <- p + theme_tree()
92
-    }
93 90
     attr(p, "mrsd") <- mrsd
94 91
     attr(p, "param") <- list(layout        = layout,
95 92
                              yscale        = yscale,
... ...
@@ -144,85 +141,7 @@ geom_tree <- function(layout="rectangular", ...) {
144 141
 
145 142
 
146 143
 
147
-##' tree theme
148
-##'
149
-##' 
150
-##' @title theme_tree
151
-##' @param bgcolor background color
152
-##' @param fgcolor foreground color
153
-##' @param ... additional parameter
154
-##' @importFrom ggplot2 theme_bw
155
-##' @importFrom ggplot2 theme
156
-##' @importFrom ggplot2 element_blank
157
-##' @importFrom ggplot2 %+replace%
158
-##' @export
159
-##' @return updated ggplot object with new theme
160
-##' @author Yu Guangchuang
161
-##' @examples
162
-##' require(ape)
163
-##' tr <- rtree(10)
164
-##' ggtree(tr) + theme_tree()
165
-theme_tree <- function(bgcolor="white", fgcolor="black", ...) {
166
-    theme_tree2() %+replace%
167
-    theme(panel.background=element_rect(fill=bgcolor, colour=bgcolor),
168
-          axis.line.x = element_blank(),
169
-          axis.text.x = element_blank(),
170
-          axis.ticks.x = element_blank(),
171
-          ...)
172
-}
173 144
 
174
-##' tree2 theme
175
-##'
176
-##' 
177
-##' @title theme_tree2
178
-##' @param bgcolor background color
179
-##' @param fgcolor foreground color
180
-##' @param ... additional parameter
181
-##' @importFrom ggplot2 theme_bw
182
-##' @importFrom ggplot2 theme
183
-##' @importFrom ggplot2 element_blank
184
-##' @importFrom ggplot2 element_line
185
-##' @importFrom ggplot2 %+replace%
186
-##' @importFrom ggplot2 element_rect
187
-##' @export
188
-##' @return updated ggplot object with new theme
189
-##' @author Yu Guangchuang
190
-##' @examples
191
-##' require(ape)
192
-##' tr <- rtree(10)
193
-##' ggtree(tr) + theme_tree2()
194
-theme_tree2 <- function(bgcolor="white", fgcolor="black", ...) {
195
-    theme_bw() %+replace%
196
-    theme(legend.position="none",
197
-          panel.grid.minor=element_blank(),
198
-          panel.grid.major=element_blank(),
199
-          panel.background=element_rect(fill=bgcolor, colour=bgcolor),
200
-          panel.border=element_blank(),
201
-          axis.line=element_line(color=fgcolor),
202
-          axis.line.y=element_blank(),
203
-          axis.ticks.y=element_blank(),
204
-          axis.text.y=element_blank(),
205
-          ...)
206
-}
207
-
208
-##' transparent background theme
209
-##'
210
-##' 
211
-##' @title theme_transparent
212
-##' @param ... additional parameter to tweak the theme
213
-##' @return ggplot object
214
-##' @importFrom ggplot2 theme
215
-##' @importFrom ggplot2 element_rect
216
-##' @export
217
-##' @author Guangchuang Yu
218
-theme_transparent <- function(...) {
219
-    theme(panel.background = element_rect(
220
-              fill = "transparent",
221
-              colour = NA),
222
-          plot.background = element_rect(
223
-              fill = "transparent",
224
-              colour = NA), ...)
225
-}
226 145
 
227 146
 
228 147
 ##' scale clade
229 148
new file mode 100644
... ...
@@ -0,0 +1,79 @@
1
+##' tree theme
2
+##'
3
+##' 
4
+##' @title theme_tree
5
+##' @param bgcolor background color
6
+##' @param fgcolor foreground color
7
+##' @param ... additional parameter
8
+##' @importFrom ggplot2 theme_bw
9
+##' @importFrom ggplot2 theme
10
+##' @importFrom ggplot2 element_blank
11
+##' @importFrom ggplot2 %+replace%
12
+##' @export
13
+##' @return updated ggplot object with new theme
14
+##' @author Yu Guangchuang
15
+##' @examples
16
+##' require(ape)
17
+##' tr <- rtree(10)
18
+##' ggtree(tr) + theme_tree()
19
+theme_tree <- function(bgcolor="white", fgcolor="black", ...) {
20
+    theme_tree2() %+replace%
21
+    theme(panel.background=element_rect(fill=bgcolor, colour=bgcolor),
22
+          axis.line.x = element_blank(),
23
+          axis.text.x = element_blank(),
24
+          axis.ticks.x = element_blank(),
25
+          ...)
26
+}
27
+
28
+##' tree2 theme
29
+##'
30
+##' 
31
+##' @title theme_tree2
32
+##' @param bgcolor background color
33
+##' @param fgcolor foreground color
34
+##' @param ... additional parameter
35
+##' @importFrom ggplot2 theme_bw
36
+##' @importFrom ggplot2 theme
37
+##' @importFrom ggplot2 element_blank
38
+##' @importFrom ggplot2 element_line
39
+##' @importFrom ggplot2 %+replace%
40
+##' @importFrom ggplot2 element_rect
41
+##' @export
42
+##' @return updated ggplot object with new theme
43
+##' @author Yu Guangchuang
44
+##' @examples
45
+##' require(ape)
46
+##' tr <- rtree(10)
47
+##' ggtree(tr) + theme_tree2()
48
+theme_tree2 <- function(bgcolor="white", fgcolor="black", ...) {
49
+    theme_bw() %+replace%
50
+    theme(legend.position="none",
51
+          panel.grid.minor=element_blank(),
52
+          panel.grid.major=element_blank(),
53
+          panel.background=element_rect(fill=bgcolor, colour=bgcolor),
54
+          panel.border=element_blank(),
55
+          axis.line=element_line(color=fgcolor),
56
+          axis.line.y=element_blank(),
57
+          axis.ticks.y=element_blank(),
58
+          axis.text.y=element_blank(),
59
+          ...)
60
+}
61
+
62
+##' transparent background theme
63
+##'
64
+##' 
65
+##' @title theme_transparent
66
+##' @param ... additional parameter to tweak the theme
67
+##' @return ggplot object
68
+##' @importFrom ggplot2 theme
69
+##' @importFrom ggplot2 element_rect
70
+##' @export
71
+##' @author Guangchuang Yu
72
+theme_transparent <- function(...) {
73
+    theme(panel.background = element_rect(
74
+              fill = "transparent",
75
+              colour = NA),
76
+          plot.background = element_rect(
77
+              fill = "transparent",
78
+              colour = NA), ...)
79
+}
0 80
new file mode 100644
1 81
Binary files /dev/null and b/vignettes/figures/ggtree_objects.png differ
2 82
deleted file mode 100644
... ...
@@ -1,907 +0,0 @@
1
-title: "ggtree: a phylogenetic tree viewer for different types of tree annotations"
2
-author: "\\
3
-
4
-	Guangchuang Yu (<guangchuangyu@gmail.com>) and Tommy Tsan-Yuk Lam (<ttylam@hku.hk>)\\
5
-
6
-        School of Public Health, The University of Hong Kong"
7
-date: "`r Sys.Date()`"
8
-bibliography: ggtree.bib
9
-csl: nature.csl
10
-output: 
11
-  BiocStyle::html_document:
12
-    toc: true
13
-    css: toc.css
14
-  BiocStyle::pdf_document:
15
-    toc: true
16
-vignette: >
17
-  %\VignetteIndexEntry{ggtree: phylogenetic tree viewer and annotator}
18
-  %\VignetteEngine{knitr::rmarkdown}
19
-  %\VignetteDepends{phangorn}
20
-  %\usepackage[utf8]{inputenc}
21
-
22
-```{r style, echo=FALSE, results="asis", message=FALSE}
23
-BiocStyle::markdown()
24
-knitr::opts_chunk$set(tidy = FALSE,
25
-		   message = FALSE)
26
-```
27
-
28
-
29
-```{r echo=FALSE, results="hide", message=FALSE}
30
-library("colorspace")
31
-library("Biostrings")
32
-library("ape")
33
-library("ggplot2")
34
-library("gridExtra")
35
-library("ggtree")
36
-library("phangorn")
37
-```
38
-
39
-
40
-
41
-> You can't even begin to understand biology, you can't understand life, unless you understand what it's all there for, how it arose - and that means evolution.
42
-> --- Richard Dawkins
43
-
44
-
45
-# Citation
46
-If you use `r Biocpkg("ggtree")` in published research, please cite:
47
-
48
-```
49
-G Yu, D Smith, H Zhu, Y Guan, TTY Lam,
50
-ggtree: an R package for visualization and annotation of phylogenetic tree with different types of meta-data.
51
-submitted.
52
-```
53
-
54
-# Introduction
55
-This project arose from our needs to annotate nucleotide substitutions in the phylogenetic tree, and we found that there is no tree visualization software can do this easily. Existing tree viewers are designed for displaying phylogenetic tree, but not annotating it. Although some tree viewers can displaying bootstrap values in the tree, it is hard/impossible to display other information in the tree. Our first solution for displaying nucleotide substituitions in the tree is to add this information in the node/tip names and use traditional tree viewer to show it. We displayed the information in the tree successfully, but We believe this indirect approach is inefficient.
56
-
57
-In the old day, phylogenetic tree is often small. At that time, as we almost didn't have a need to annotate a tree; displaying the evolution relationships is mostly enough. Nowadays, we can obtain a lot of data from different experiments, and we want to associate our data, for instance antigenic change, with the evolution relationship. Visualizing these associations in the phylogenetic tree can help us to identify evolution patterns. We believe we need a next generation tree viewer that should be programmable and extensible. It can view a phylogenetic tree easily as we did with classical software and support adding annotation data in a layer above the tree. This is the objective of developing the `r Githubpkg("GuangchuangYu/ggtree")`. Common tasks of annotating a phylogenetic tree should be easy and complicated tasks can be possible to achieve by adding multiple layers of annotation.
58
-
59
-The `r Githubpkg("GuangchuangYu/ggtree")` is designed by extending the `r CRANpkg("ggplot2")`[@wickham_ggplot2_2009] package. It is based on the grammar of graphics and takes all the good parts of `r CRANpkg("ggplot2")`. There are other R packages that implement tree viewer using `r CRANpkg("ggplot2")`, including `r CRANpkg("OutbreakTools")`, `r Biocpkg("phyloseq")`[@mcmurdie_phyloseq_2013] and `r Githubpkg("gjuggler/ggphylo")`; they mostly create complex tree view functions for their specific needs. Internally, these packages interpret a phylogenetic as a collection of `lines`, which makes it hard to annotate diverse user input that are related to node (taxa). The `r Githubpkg("GuangchuangYu/ggtree")` is different to them by interpreting a tree as a collection of `taxa` and allowing general flexibilities of annotating phylogenetic tree with diverse types of user inputs. 
60
-
61
-# Tree visualization
62
-## viewing tree with `ggtree`
63
-`r Githubpkg("GuangchuangYu/ggtree")` extend _`ggplot`_ to support viewing phylogenetic tree. It implements _`geom_tree`_ layer for displaying phylogenetic trees, as shown below:
64
-```{r fig.width=3, fig.height=3, fig.align="center"}
65
-nwk <- system.file("extdata", "sample.nwk", package="ggtree")
66
-x <- readLines(nwk)
67
-cat(substring(x, 1, 56), "\n", substring(x, 57), "\n")
68
-
69
-library("ggplot2")
70
-library("ggtree")
71
-
72
-tree <- read.tree(nwk)
73
-ggplot(tree, aes(x, y)) + geom_tree() + theme_tree() + xlab("") + ylab("")
74
-```
75
-
76
-This example tree was obtained from Chapter 34 of _Inferring Phylogenies_[@felsenstein_inferring_2003 pp.573]. The function, _`ggtree`_, was implemented as a short cut to visualize a tree, and it works exactly the same as shown above.
77
-
78
-_`ggtree`_ takes all the advantages of _`ggplot2`_. For example, we can change the color, size and type of the lines as we do with _`ggplot2`_.
79
-```{r fig.width=3, fig.height=3, fig.align="center"}
80
-ggtree(tree, color="steelblue", size=0.5, linetype="dotted")
81
-```
82
-
83
-By default, the tree is viewing in ladderize form, user can set the parameter _`ladderize = FALSE`_ to disable it.
84
-```{r fig.width=3, fig.height=3, fig.align="center"}
85
-ggtree(tree, ladderize=FALSE)
86
-```
87
-
88
-The _`branch.length`_ is used to scale the edge, user can set the parameter _`branch.length = "none"`_ to only viewing the tree topology (cladogram) or other numerical variable to scale the tree (e.g. dN/dS).
89
-
90
-```{r fig.width=3, fig.height=3, fig.align="center"}
91
-ggtree(tree, branch.length="none")
92
-```
93
-
94
-## support multiple phylogenetic classes
95
-
96
-`r Githubpkg("GuangchuangYu/ggtree")` defined several S4 classes to store phylogenetic object and its associated annotation, including:
97
-
98
-+ `apeBootstrap`
99
-+ `beast`
100
-+ `codeml_mlc`
101
-+ `codeml`
102
-+ `hyphy`
103
-+ `jplace`
104
-+ `nhx`
105
-+ `paml_rst`
106
-+ `phangorn`
107
-+ `raxml`
108
-+ `r8s`
109
-
110
-
111
-
112
-In addition, it also supports _`phylo`_ (defined by `r CRANpkg("ape")`[@paradis_ape_2004]) and _`phylo4`_ (defined by `r CRANpkg("phylobase")`)
113
-
114
-User can use _`ggtree(object)`_ command to view the phylogenetic tree directly, and annotation data stored in these objects can be added as demonstrated in __[`Tree annotation with output from evolution software`](#tree-annotation-with-output-from-evolution-software)__ session.
115
-
116
-
117
-## layout
118
-
119
-Currently, _`ggtree`_ supports several layout, including:
120
-
121
-+ `rectangular` (by default)
122
-+ `slanted`
123
-+ `fan` or `circular`
124
-
125
-for `Phylogram` (by default) and `Cladogram` if user explicitly setting `branch.length='none'`.
126
-
127
-And `unrooted` layout. 
128
-
129
-Unrooted layout was implemented by the _`equal-angle algorithm`_ that described in _Inferring Phylogenies_[@felsenstein_inferring_2003 pp.578-580].
130
-
131
-```{r fig.width=6, fig.height=9, fig.align="center"}
132
-library("gridExtra")
133
-grid.arrange(ggtree(tree) + ggtitle("(Phylogram) rectangular layout"),
134
-             ggtree(tree, branch.length='none') + ggtitle("(Cladogram) rectangular layout"),
135
-	     ggtree(tree, layout="slanted") + ggtitle("(Phylogram) slanted layout"),
136
-             ggtree(tree, layout="slanted", branch.length='none') + ggtitle("(Cladogram) slanted layout"),
137
-	     ggtree(tree, layout="circular") + ggtitle("(Phylogram) circular layout"),
138
-             ggtree(tree, layout="circular", branch.length="none") + ggtitle("(Cladogram) circular layout"),
139
-	     ggtree(tree, layout="unrooted") + ggtitle("unrooted layout"),
140
-	     ncol=2)
141
-```	
142
-
143
-### two dimensional tree
144
-
145
-`r Githubpkg("GuangchuangYu/ggtree")` implemented 2 dimensional tree. It accepts parameter _`yscale`_ to scale the y-axis based on the selected tree attribute. The attribute should be numerical variable. If it is character/category variable, user should provides a name vector of mapping the variable to numeric by passing it to parameter _`yscale_mapping`_.
146
-
147
-
148
-```{r fig.width=9, fig.height=4, fig.align="center"}
149
-tree2d <- read.beast(system.file("extdata", "twoD.tree", package="ggtree"))
150
-ggtree(tree2d, mrsd = "2014-05-01",
151
-       yscale="NGS", yscale_mapping=c(N2=2, N3=3, N4=4, N5=5, N6=6, N7=7)) +
152
-           theme_classic() + 
153
-               theme(panel.grid.major=element_line(color="grey20", linetype="dotted", size=.3),
154
-                     panel.grid.major.y=element_blank()) +
155
-                         scale_y_continuous(labels=paste0("N", 2:7))
156
-```	
157
-
158
-In this example, the figure demonstrates the quantity of y increase along the trunk. User can highlight the trunk with different line size or color using the functions we described below.
159
-
160
-
161
-## display evolution distance
162
-
163
-To show evolution distance, user can use `add_legend` function.
164
-
165
-```{r fig.width=3, fig.height=3, fig.align="center"}
166
-ggtree(tree) %>% add_legend()
167
-```
168
-
169
-We can also use `theme_tree2()` or `ggtree(showDistance=TRUE)`
170
-
171
-```{r fig.width=3, fig.height=3, fig.align="center"}
172
-ggtree(tree) + theme_tree2()
173
-```
174
-
175
-## display nodes/tips
176
-
177
-Show all the internal nodes and tips in the tree can be done by adding a layer of points using _`geom_nodepoint`_,  _`geom_tippoint`_ or _`geom_point`_.
178
-
179
-```{r fig.width=3, fig.height=3, fig.align="center"}
180
-ggtree(tree)+geom_point(aes(shape=isTip, color=isTip), size=3)
181
-```
182
- 
183
-```{r fig.width=3, fig.height=3, fig.align="center"}
184
-p <- ggtree(tree) + geom_nodepoint(color="#b5e521", alpha=1/4, size=10)
185
-p + geom_tippoint(color="#FDAC4F", shape=8, size=3)
186
-```
187
-
188
-## display labels
189
-
190
-Users can use _`geom_text`_ to display the node/tip labels:
191
-
192
-```{r fig.width=3, fig.height=3, warning=FALSE, fig.align="center"}
193
-p + geom_text(aes(label=label), size=3, color="purple", hjust=-0.3)
194
-```
195
-
196
-For _`circular`_ and _`unrooted`_ layout, `r Githubpkg("GuangchuangYu/ggtree")` supports rotating node labels according to the angles of the branches.
197
-```{r fig.width=6, fig.height=6, warning=FALSE, fig.align="center"}
198
-ggtree(tree, layout="circular") + geom_text(aes(label=label, angle=angle), size=3, color="purple", hjust=-0.3)
199
-```
200
-
201
-
202
-By default, the positions are based on the node positions, we can change them to based on the middle of the branch/edge.
203
-
204
-```{r fig.width=5, fig.height=3, warning=FALSE, fig.align="center"}
205
-p + geom_text(aes(x=branch, label=label), size=3, color="purple", vjust=-0.3)
206
-```
207
-
208
-Based on the middle of branches is very useful when annotating transition from parent node to child node.
209
-
210
-## theme
211
-`theme_tree()` defined a totally blank canvas, while _`theme_tree2()`_ add phylogenetic distance legend. These two themes all accept a parameter of _`bgcolor`_ that defined the background color.
212
-
213
-```{r fig.width=6, fig.height=3, fig.align="center"}
214
-grid.arrange(
215
-	ggtree(rtree(30), color="red") + theme_tree("steelblue"),
216
-	ggtree(rtree(20), color="white") + theme_tree("black"),
217
-	ncol=2)
218
-```
219
-
220
-## update tree viewing with a new tree
221
-In the [display nodes/tips](#display-nodestips) section, we have a _`p`_ object that stored the tree viewing of 13 tips and internal nodes highlighted with specific colored big dots. If you want to applied this pattern (we can imaging a more complex one) to a new tree, you don't need to build the tree step by step. `r Githubpkg("GuangchuangYu/ggtree")` provides an operator, _`%<%`_, for applying the visualization pattern to a new tree.
222
-
223
-For example, the pattern in the _`p`_ object will be applied to a new tree with 50 tips as shown below:
224
-```{r fig.width=3, fig.height=3, fig.align="center"}
225
-p %<% rtree(50)
226
-```
227
-
228
-Another example can be found in [`CODEML`](#codeml) session.
229
-
230
-# Tree annotation
231
-
232
-## zoom on a portion of tree
233
-
234
-`r Githubpkg("GuangchuangYu/ggtree")` provides _`gzoom`_ function that similar to _`zoom`_ function provided in `r CRANpkg("ape")`. This function plots simultaneously a whole phylogenetic tree and a portion of it. It aims at exploring very large trees.
235
-
236
-```{r fig.width=18, fig.height=10, fig.align="center"}
237
-library("ape")
238
-data(chiroptera)
239
-library("ggtree")
240
-gzoom(chiroptera, grep("Plecotus", chiroptera$tip.label))
241
-```
242
-
243
-## color tree
244
-
245
-In `r Githubpkg("GuangchuangYu/ggtree")`, coloring phylogenetic tree is easy, by using `aes(color=VAR)` to map the color of tree based on a specific variable (numeric and category are both supported).
246
-
247
-```{r fig.width=5, fig.height=5}
248
-ggtree(tree, aes(color=branch.length)) +
249
-    scale_color_continuous(low="green", high="red") +
250
-        theme(legend.position="bottom")
251
-```
252
-User can use any feature, including clade posterior and dN/dS _etc._, to scale the color of the tree.
253
-
254
-## annotate clade
255
-`r Githubpkg("GuangchuangYu/ggtree")` implements _`annotation_clade`_ and _`annotation_clade2`_ functions to annotate a selected clade with a bar indicating that clade with a corresponding label.
256
-
257
-The _`annotation_clade`_ function accepts a selected internal node number and annotates that selected clade, while _`annotation_clade2`_ functions accepts two tip labels (upper one and lower one) to annotate the clade.
258
-
259
-User can use _`geom_text`_ to display all the node numbers, and select interesting clade to annotate.
260
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
261
-ggtree(tree) + geom_text(aes(label=node))
262
-```
263
-
264
-```{r fig.width=5, fig.height=5}
265
-p <- ggtree(tree) + geom_tiplab()
266
-annotation_clade(p, node=17, "selected clade", offset.text=2)
267
-```
268
-
269
-```{r fig.width=5, fig.height=5}
270
-annotation_clade2(p, "B", "E", "Clade X", offset.text=2) %>%
271
-    annotation_clade2("G", "H", "Clade Y", bar.size=4, font.size=8, offset=5, offset.text=4, color="steelblue")
272
-```
273
-The parameter `bar.size` is used to control the width of the bar and the `font.size` parameter is to control the font size of the clade lable. The parameter `offset` is used to control the distance from the annotation to the tree, while `offset.text` to control the distance from clade label to bar.
274
-
275
-
276
-## highlight clades
277
-
278
-`r Githubpkg("GuangchuangYu/ggtree")` implements _`geom_hilight`_ layer, that an internal node number and add a layer of rectangle to highlight the selected clade.
279
-
280
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
281
-ggtree(tree) + geom_hilight(node=21, fill="steelblue", alpha=.6) +
282
-    geom_hilight(node=17, fill="darkgreen", alpha=.6)
283
-```
284
-
285
-
286
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
287
-ggtree(tree, layout="fan") + geom_hilight(node=21, fill="steelblue", alpha=.6) +
288
-    geom_hilight(node=23, fill="darkgreen", alpha=.6)
289
-```
290
-
291
-Another way to highlight selected clades is setting the clades with different colors and/or line types as demonstrated in __[`group clades`](#group-clades)__ section.
292
-
293
-## collapse clade
294
-
295
-With _`collapse`_ function, user can collapse a selected clade.
296
-
297
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
298
-cp <- ggtree(tree) %>% collapse(node=21)
299
-cp + geom_point2(aes(subset=(node == 21)), size=5, shape=23, fill="steelblue")
300
-```
301
-
302
-## expand collapsed clade
303
-
304
-The collapsed clade can be expanded via _`expand`_ function.
305
-
306
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
307
-cp %>% expand(node=21)
308
-```
309
-
310
-## flip clades
311
-
312
-The positions of two selected branches can be flip over using __*flip*__ function.
313
-
314
-```{r fig.width=20, fig.height=7, warning=FALSE}
315
-set.seed(2015-06-30)
316
-p1 <- ggtree(rtree(30)) + geom_text(aes(label=node))
317
-p2 <- flip(p1, node1=45, node2=33)
318
-p3 <- flip(p2, 32, 58)
319
-grid.arrange(p1, p2, p3, ncol=3)
320
-```
321
-
322
-## rotate clade
323
-
324
-A selected clade can be rotated by 180 degree using __*rotate*__ function.
325
-
326
-```{r fig.width=16, fig.height=8, warning=FALSE}
327
-set.seed(2015-07-01)
328
-p1 <- ggtree(rtree(30)) + geom_text(aes(label=node))
329
-p1 <- hilight(p1, 33)
330
-p2 <- rotate(p1, 33)
331
-grid.arrange(p1, p2, ncol=2)
332
-```
333
-
334
-## group OTUs
335
-
336
-`r Githubpkg("GuangchuangYu/ggtree")` provides _`groupOTU`_ function to group tips and all their related ancestors. 
337
-
338
-```{r}
339
-tree <- groupOTU(tree, focus=c("A", "B", "C", "D", "E"))
340
-```
341
-
342
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
343
-ggtree(tree, aes(color=group)) + geom_tiplab()
344
-```
345
-
346
-_`groupOTU`_ can also input a list of tip groups.
347
-
348
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
349
-cls <- list(c1=c("A", "B", "C", "D", "E"),
350
-            c2=c("F", "G", "H"),
351
-            c3=c("L", "K", "I", "J"),
352
-            c4="M")
353
-
354
-tree <- groupOTU(tree, cls)
355
-library("colorspace")
356
-ggtree(tree, aes(color=group, linetype=group)) + geom_text(aes(label=label),  hjust=-.25) +
357
-     scale_color_manual(values=c("black", rainbow_hcl(4))) + theme(legend.position="right")
358
-```
359
-
360
-_`groupOTU`_ also work with tree view (ggplot2 object).
361
-
362
-
363
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
364
-p <- ggtree(tree)
365
-groupOTU(p, LETTERS[1:5]) + aes(color=group) + geom_tiplab() + scale_color_manual(values=c("black", "firebrick"))
366
-```
367
-
368
-### iris example
369
-
370
-In this example, we first build a tree based on the iris data, then grouping the tree based on different spacies.
371
-```{r fig.width=20, fig.height=20, fig.align="center", warning=FALSE}
372
-data(iris)
373
-rn <- paste0(iris[,5], "_", 1:150)
374
-rownames(iris) <- rn
375
-d_iris <- dist(iris[,-5], method="man")
376
-
377
-tree_iris <- bionj(d_iris)
378
-tree_iris <- groupOTU(tree_iris, list(setosa    = rn[1:50],
379
-				versicolor    = rn[51:100],
380
-				virginica_145 = rn[101:150]))
381
-cols <- rainbow_hcl(4)
382
-ggtree(tree_iris, aes(color=group)) +
383
-    geom_text(aes(label=label), hjust=-.1) +
384
-        scale_color_manual(values=cols, breaks=1:3,
385
-                           labels=c("Setosa", "Versicolor", "Virginica")) +
386
-                               theme(legend.position="right")
387
-```
388
-
389
-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.
390
-
391
-## group clades
392
-
393
-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 to cluster clade/clades that works similar to _`groupOTU`_. User can also use _`hilight`_ function demonstrated in __[`hilight clades`](#hilight-clades)__ section for highlighting selected clades.
394
-
395
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
396
-tree <- groupClade(tree, node=21)
397
-ggtree(tree, aes(color=group, linetype=group))
398
-```
399
-
400
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
401
-tree <- groupClade(tree, node=c(21, 17))
402
-ggtree(tree, aes(color=group, linetype=group))
403
-```
404
-
405
-It also works with tree view, just like _`groupOTU`_.
406
-
407
-With _`groupOTU`_ and _`groupClade`_, it's easy to highlight selected taxa and easy to selecte taxa to display related feature.
408
-
409
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE}
410
-ggtree(tree, aes(color=group, linetype=group)) +
411
-    geom_text2(aes(label=label, subset=(group==2)), hjust = -.5) +
412
-        geom_text2(aes(label=label, subset=(group==1)), hjust = -.5, color="blue")
413
-```
414
-
415
-
416
-## scale clade
417
-In __[`collapse clade`](#collapse-clade)__, we have illustrated how to collapse selected clades. Another approach is to zoom out clade to a small scale.
418
-
419
-```{r fig.width=12, fig.height=6, warning=F}
420
-grid.arrange(ggtree(tree) %>% hilight(21, "steelblue"),
421
-             ggtree(tree) %>% scaleClade(21, scale=0.3) %>% hilight(21, "steelblue"),
422
-             ncol=2)
423
-```
424
-
425
-Of course, _`scaleClade`_ can accept `scale` larger than 1 and zoom in the selected portion.
426
-
427
-```{r fig.width=12, fig.height=6, warning=F}
428
-grid.arrange(ggtree(tree) %>% hilight(17, fill="steelblue") %>%
429
-                 hilight(21, fill="darkgreen"),
430
-             ggtree(tree) %>% scaleClade(17, scale=2) %>% scaleClade(21, scale=0.3) %>%
431
-                 hilight(17, "steelblue") %>% hilight(21, fill="darkgreen"),
432
-             ncol=2)
433
-```
434
-
435
-# Tree annotation with phylopic
436
-
437
-[PhyloPic](http://phylopic.org/) is a database that stores reusable silhouette images of organisms. `r Githubpkg("GuangchuangYu/ggtree")` supports downloading images from [PhyloPic](http://phylopic.org/) and annotating phylogenetic tree with the downloaded images.
438
-
439
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE, eval=FALSE}
440
-pp <- ggtree(tree) %>% phylopic("79ad5f09-cf21-4c89-8e7d-0c82a00ce728", color="steelblue", alpha = .3)
441
-print(pp)
442
-```
443
-![](../inst/extdata/phylopic1.png)
444
-
445
-```{r fig.width=5, fig.height=5, fig.align="center", warning=FALSE, eval=FALSE}
446
-pp %>% phylopic("67382184-5135-4faa-8e98-eadff02c3e8a", color="#86B875", alpha=.8, node=4) %>%
447
-     phylopic("d3563b54-780f-4711-a49a-7ea051e9dacc", color="darkcyan", alpha=.8, node=17, width=.2)
448
-```
449
-![](../inst/extdata/phylopic2.png)
450
-
451
-# Tree annotation with output from evolution software
452
-In `r Githubpkg("GuangchuangYu/ggtree")`, we implemented several functions to parse the output from `r CRANpkg("ape")`, `r CRANpkg("phangorn")`, [r8s](http://loco.biosci.arizona.edu/r8s/), [RAxML](http://sco.h-its.org/exelixis/web/software/raxml/), [PAML](http://abacus.gene.ucl.ac.uk/software/paml.html)[@yang_paml_2007], [HYPHY](http://hyphy.org/w/index.php/Main_Page)[@pond_hyphy_2005], [EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011], [PPLACER](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010], [PHYLDOG](http://pbil.univ-lyon1.fr/software/phyldog/)[@boussau_genome-scale_2013], [RevBayes](http://revbayes.github.io/intro.html)[@hohna_probabilistic_2014] and [BEAST](http://beast2.org/)[@bouckaert_beast_2014] and defined several classes to store phylogenetic object and associated annotation. 
453
-
454
-Classes include:
455
-
456
-+ _`apeBootstrap`_ for bootstrap analysis of `ape::boot.phylo()`.
457
-+ _`raxml`_ for bootstrap analysis obtained from [RAxML](http://sco.h-its.org/exelixis/web/software/raxml/).
458
-+ _`paml_rst`_ for _`rst`_ file obtained by [PAML](http://abacus.gene.ucl.ac.uk/software/paml.html)[@yang_paml_2007], including _`BASEML`_ and _`CODEML`_.
459
-+ _`codeml_mlc`_ for _`mlc`_ file obtained by _`CODEML`_.
460
-+ _`codeml`_ for interpreting _`rst`_ and _`mlc`_ files obtained by _`CODEML`_.
461
-+ _`hyphy`_ for [HYPHY](http://hyphy.org/w/index.php/Main_Page)[@pond_hyphy_2005] output.
462
-+ _`jplace`_ for [EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011] and [PPLACER](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010] output.
463
-+ _`beast`_ for [BEAST](http://beast2.org/)[@bouckaert_beast_2014].
464
-+ _`r8s`_ for [r8s](loco.biosci.arizona.edu/r8s/).
465
-+ _`nhx`_ for NHX (New Hampshire eXtended format) file that is commonly used in phylogenetics software (e.g. [PHYLDOG](http://pbil.univ-lyon1.fr/software/phyldog/)[@boussau_genome-scale_2013], [RevBayes](http://revbayes.github.io/intro.html)[@hohna_probabilistic_2014], *etc*.)
466
-
467
-
468
-_`jplace`_ class is also designed to store user specific annotation data, and serves as a standard format for tree annotation within the `r Githubpkg("GuangchuangYu/ggtree")` package. Please refer to the __[`jplace file format`](#jplace-file-format)__ session.
469
-
470
-For each classes, we defined _`read.className`_ to parse input file and output a corresponding object, _`get.fields`_ method to get the annotation features available in the object, access methods to get these features, and _`plot`_ methods for quickly viewing these annotation features.
471
-
472
-
473
-## annotating tree with BEAST output
474
-```{r}
475
-file <- system.file("extdata/BEAST", "beast_mcc.tree", package="ggtree")
476
-beast <- read.beast(file)
477
-beast
478
-```
479
-Since _`%`_ is not a valid character in _`names`_, all the feature names that contain _`x%`_ will convert to _`0.x`_. For example, _`length_95%_HPD`_ will be changed to _`length_0.95_HPD`_.
480
-
481
-```{r fig.width=8, width=60, warning=FALSE, fig.align="center"}
482
-plot(beast, annotation="length_0.95_HPD", branch.length="none") + theme_tree()
483
-```
484
-
485
-User can round the digits by setting the parameter _`ndigits`_. The default value is 2.
486
-
487
-```{r fig.width=8, width=60, warning=FALSE, fig.align="center"}
488
-plot(beast, annotation="height", ndigits=3, annotation.color="red")
489
-```
490
-
491
-
492
-## annotating tree with phangorn output
493
-
494
-```{r results='hide', message=FALSE}
495
-library(phangorn)
496
-treefile <- system.file("extdata", "pa.nwk", package="ggtree")
497
-tre <- read.tree(treefile)
498
-tipseqfile <- system.file("extdata", "pa.fas", package="ggtree")
499
-tipseq <- read.phyDat(tipseqfile,format="fasta")
500
-fit <- pml(tre, tipseq, k=4)
501
-fit <- optim.pml(fit, optNni=FALSE, optBf=T, optQ=T,
502
-                 optInv=T, optGamma=T, optEdge=TRUE,
503
-                 optRooted=FALSE, model = "GTR")
504
-```
505
-
506
-```{r fig.width=12, fig.height=10, width=60, warning=FALSE, fig.align="center"}
507
-phangorn <- phyPML(fit, type="ml")
508
-ggtree(phangorn) + geom_text(aes(label=AA_subs))
509
-```
510
-
511
-## annotating tree with PAML output
512
-
513
-### BASEML
514
-
515
-#### _`rst`_ file\
516
-
517
-
518
-_`rst`_ file from _`baseml`_ is similar to _`codeml`_ output. The only difference is the space in the sequences. For _`baseml`_, each ten bases are separated by one space, while for _`codeml`_, each three bases (triplet) are separated by one space. We defined a _`read.paml_rst`_ to parse _`rst`_ file. It supports _`baseml`_ and _`codeml`_ output. The information will be stored in _`paml_rst`_ S4 object.
519
-
520
-```{r}
521
-rstfile <- system.file("extdata/PAML_Baseml", "rst", package="ggtree")
522
-rst <- read.paml_rst(rstfile)
523
-rst
524
-```
525
-
526
-The function _`read.paml_rst`_ can accept only one parameter, _`rstfile`_, and the output can be used to view the phylogeny and the substitution annotation.
527
-
528
-```{r fig.width=10, fig.height=8, width=60, warning=FALSE}
529
-p <- plot(rst, annotation="marginal_AA_subs", annotation.color="steelblue")
530
-print(p)
531
-```
532
-
533
-### CODEML
534
-
535
-#### rst file\
536
-
537
-
538
-_`rst`_ file from _`CODEML`_ is similar to _`BASEML`_, and also parsed by _`read.paml_rst`_ function. The _`plot`_ method works also in the same way.
539
-
540
-If you remember the _`%<%`_ operator introduced in [`update tree viewing with a new tree`](#update-tree-viewing-with-a-new-tree) session, you can use it to update a tree view with a new object.
541
-
542
-In last session, we use _`rstfile`_ of _`BASEML`_ to build a tree view with amino acid substitution annotated. The following example use another _`rstfile`_ from _`CODEML`_ to update the tree view.
543
-```{r fig.width=8, width=60, warning=FALSE, fig.align="center"}
544
-rstfile <- system.file("extdata/PAML_Codeml", "rst", package="ggtree")
545
-rst <- read.paml_rst(rstfile)
546
-p %<% rst
547
-```
548
-
549
-You can found that these two figures have different evolution distances, and substitutions inferred from _`BASEML`_ and _`CODEML`_ are slightly different.
550
-
551
-
552
-#### mlc file\
553
-
554
-
555
-_`mlcfile`_ contains _`dN/dS`_ estimation.
556
-
557
-```{r}
558
-mlcfile <- system.file("extdata/PAML_Codeml", "mlc", package="ggtree")
559
-mlc <- read.codeml_mlc(mlcfile)
560
-mlc
561
-```
562
-
563
-Please aware that _`/`_ and _`*`_ are not valid characters in _`names`_, they were changed to _`_vs_`_ and _`_x_`_ respectively.
564
-
565
-So _`dN_vs_dS`_ is _`dN/dS`_, _`N_x_dN`_ is _`N*dN`_, and _`S_x_dS`_ is _`S*dS`_.
566
-
567
-
568
-```{r fig.width=8, width=60, warning=FALSE, fig.align="center"}
569
-plot(mlc, branch.length="branch.length", annotation="dN_vs_dS", annotation.color="blue", ndigits=3)
570
-```
571
-
572
-The paramter _`branch.length`_ can be one of available annotations:
573
-```{r}
574
-get.fields(mlc)
575
-```
576
-
577
-For example, if we set _`branch.length`_ to _`dN_vs_dS`_, it will plot the $\omega$ (_`dN/dS`_) tree:
578
-```{r fig.width=8, width=60, warning=FALSE, fig.align="center"}
579
-plot(mlc, branch.length="dN_vs_dS", annotation="dN_vs_dS", ndigits=3)
580
-```
581
-
582
-We can also plot the _`dN`_ or _`dS`_ tree and others. The parameter _`annotation`_ can also be one of the available annotations.
583
-
584
-
585
-#### _`CODEML`_ output: rst and mlc files\
586
-
587
-
588
-We annotate the tree with information presented in _`rstfile`_ and _`mlcfile`_ separately as demonstrated in previous sessions.
589
-
590
-We can also use both of them and it's highly recommended. All the features in both files are available for annotation.
591
-
592
-
593
-```{r}
594
-ml <- read.codeml(rstfile, mlcfile)
595
-ml
596
-```
597
-
598
-So we can annotate _`dN/dS`_ with the tree in _`rstfile`_ and amino acid substitutions with the tree in _`mlcfile`_.
599
-
600
-```{r fig.width=12, fig.height=8, width=60, warning=FALSE, fig.align="center"}
601
-plot(ml, branch.length="rst.branch.length", annotation="dN_vs_dS")
602
-plot(ml, branch.length="mlc.branch.length", annotation="marginal_AA_subs")
603
-plot(ml, branch.length="dN", annotation="joint_AA_subs", annotation.color="darkgreen")
604
-```
605
-
606
-
607
-## annotating tree with HYPHY output
608
-```{r}
609
-nwk <- system.file("extdata/HYPHY", "labelledtree.tree", package="ggtree")
610
-ancseq <- system.file("extdata/HYPHY", "ancseq.nex", package="ggtree")
611
-tipfas <- system.file("extdata", "pa.fas", package="ggtree")
612
-hy <- read.hyphy(nwk, ancseq, tipfas)
613
-hy
614
-```
615
-
616
-```{r fig.width=12, fig.height=10, width=60, warning=FALSE, fig.align="center"}
617
-plot(hy, annotation="AA_subs")
618
-```
619
-
620
-
621
-## annotating tree with ape bootstraping analysis
622
-
623
-```{r results='hide', message=FALSE}
624
-library(ape)
625
-data(woodmouse)
626
-d <- dist.dna(woodmouse)
627
-tr <- nj(d)
628
-bp <- boot.phylo(tr, woodmouse, function(xx) nj(dist.dna(xx)))
629
-```
630
-
631
-```{r fig.width=6, fig.height=6, warning=FALSE, fig.align="center"}
632
-tree <- apeBoot(tr, bp)
633
-ggtree(tree) + geom_label(aes(label=bootstrap)) + geom_tiplab()
634
-```
635
-
636
-
637
-## annotating tree with RAxML bootstraping analysis
638
-
639
-```{r fig.width=12, fig.height=10, width=60, warning=FALSE, fig.align="center"}
640
-raxml_file <- system.file("extdata/RAxML", "RAxML_bipartitionsBranchLabels.H3", package="ggtree")
641
-raxml <- read.raxml(raxml_file)
642
-## plot(raxml)
643
-ggtree(raxml) + geom_label(aes(label=bootstrap)) + geom_tiplab()
644
-```
645
-
646
-
647
-## annotating tree with r8s output
648
-
649
-[r8s](http://loco.biosci.arizona.edu/r8s/) output contains 3 trees, namely `TREE`, `RATO` and `PHYLO` for time tree, rate tree and absolute substitution tree respectively.
650
-
651
-
652
-```{r fig.width=4, fig.height=6, width=60, warning=FALSE, fig.align="center")
653
-r8s <- read.r8s(system.file("extdata/r8s", "H3_r8s_output.log", package="ggtree"))
654
-ggtree(r8s, branch.length="TREE", mrsd="2014-01-01")
655
-```
656
-
657
-
658
-`branch.length` should be one of `TREE`, `RATO` or `PHYLO` for selecting the corresponding tree.
659
-
660
-User can also view 3 trees simultaneously.
661
-
662
-
663
-```{r fig.width=16, fig.height=10, width=60, warning=FALSE, fig.align="center")
664
-ggtree(get.tree(r8s)) + facet_wrap(~.id, scales="free_x")
665
-```
666
-
667
-## annotating NHX tree
668
-
669
-NHX (New Hampshire eXtended) format is commonly used in phylogenetics software (e.g. [PHYLDOG](http://pbil.univ-lyon1.fr/software/phyldog/)[@boussau_genome-scale_2013], [RevBayes](http://revbayes.github.io/intro.html)[@hohna_probabilistic_2014], *etc*.)
670
-
671
-```{r}
672
-nhxfile = system.file("extdata", "ADH.nhx", package="ggtree")
673
-nhx <- read.nhx(nhxfile)
674
-ggtree(nhx) + geom_tiplab() + geom_point(aes(color=S)) + 
675
-    theme(legend.position="right") +
676
-    geom_text(aes(label=branch.length, x=branch), vjust=-.5) + 
677
-    xlim(NA, 0.3)
678
-```
679
-
680
-
681
-## annotating tree with EPA and PPLACER output
682
-[EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011] and [PPLACER](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010] have common output file format, `jplace`. 
683
-
684
-```{r}
685
-jpf <- system.file("extdata/sample.jplace",  package="ggtree")
686
-jp <- read.jplace(jpf)
687
-print(jp)
688
-```
689
-
690
-In `r Githubpkg("GuangchuangYu/ggtree")`, we provide _`get.placements`_ method to access the placement.
691
-
692
-```{r}
693
-## get only best hit
694
-get.placements(jp, by="best")
695
-## get all placement
696
-get.placements(jp, by="all")
697
-```
698
-
699
-This is only a tiny sample file. In reality, [EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html) and [PPLACER](http://matsen.fhcrc.org/pplacer/) may place thousands of short reads on a reference tree.
700
-
701
-
702
-We may, for example, count the number of placement and annotate this information in the tree. We do not provide a _`plot`_ method for _`jplace`_ object, since we use this file format as a standard annotation format in `r Githubpkg("GuangchuangYu/ggtree")` package and have no assumption of information it may stored. Please refer to [jplace file format](#jplace-file-format) session.
703
-
704
-
705
-## mergine tree objects
706
-
707
-
708
-In ggtree, objects can be merged and evidences inferred from different phylogenetic analyses can be combined or compared and visualized.
709
-
710
-User can use the command like:
711
-```r
712
-tree <- merge_tree(tree_object_1, tree_object_2)
713
-## it's chainable, and serveral tree objects can be merged into one tree object
714
-tree <- merge_tree(tree_object_1, tree_object_2) %>% merge_tree(tree_object_3) %>% merge_tree(tree_object_4)
715
-```
716
-
717
-Here we use a tree analyzed by BEAST and CodeML and merge them into one.
718
-
719
-```{r}
720
-beast_file <- system.file("examples/MCC_FluA_H3.tree", package="ggtree")
721
-beast_tree <- read.beast(beast_file)
722
-
723
-rst_file <- system.file("examples/rst", package="ggtree")
724
-mlc_file <- system.file("examples/mlc", package="ggtree")
725
-codeml_tree <- read.codeml(rst_file, mlc_file)
726
-
727
-merged_tree <- merge_tree(beast_tree, codeml_tree)
728
-
729
-merged_tree
730
-```
731
-
732
-After merging, all evidences inferred from different tools can be used to annotate the tree simultaneously. In this example, we used 'dN' inferred by CodeML to color the tree and annotate the tree with 'posterior' inferred by BEAST.
733
-
734
-```{r fig.width=20, fig.height=26, warning=FALSE}
735
-ggtree(merged_tree, aes(color=dN), mrsd="2013-01-01", ndigits = 3) +
736
-    geom_text(aes(label=posterior), vjust=.1, hjust=-.1, size=5) + theme_tree2() +
737
-        scale_color_continuous(low="green", high="red") + theme(legend.position="right")
738
-```
739
-
740
-
741
-## annotating tree using _`ggplot2`_ layers
742
-We implemented several _`plot`_ methods for easily viewing annotation data. Users are not restricted to _`plot`_ methods provided. They can use _`geom_text`_ to add annotation layer. All annotation data are visible to _`ggplot2`_.
743
-
744
-In the following example, we use the _`codeml`_ object to visualize the $\omega$ (_`dN/dS`_) tree, and annotate the tree with _`dN`_ and _`dS`_.
745
-```{r fig.width=12, fig.height=10, width=60, warning=FALSE, fig.align="center"}
746
-ggtree(ml, branch.length="dN_vs_dS") + 
747
-    geom_text(aes(x=branch, label=dN), 
748
-              size=3, vjust=-0.5, color="red") +
749
-                  geom_text(aes(x=branch, label=dS),
750
-                            size=3, vjust=1.2, color="darkgreen")
751
-```	
752
-
753
-
754
-# Tree annotation with user specific annotation
755
-
756
-## the `%<+%` operator
757
-We provides several functions to parse and store information from common software output, and corresponding _`plot`_ methods for visualizing annotation in the tree.
758
-
759
-Here, we would like to demonstrate how to inject user specific annotation data in a tree.
760
-
761
-Suppose we have the following data that associated with the tree and would like to attach the data in the tree.
762
-
763
-```{r}
764
-nwk <- system.file("extdata", "sample.nwk", package="ggtree")
765
-tree <- read.tree(nwk)
766
-p <- ggtree(tree)
767
-
768
-dd <- data.frame(taxa  = LETTERS[1:13], 
769
-      		 place = c(rep("GZ", 5), rep("HK", 3), rep("CZ", 4), NA),
770
-                 value = round(abs(rnorm(13, mean=70, sd=10)), digits=1))
771
-## you don't need to order the data
772
-## data was reshuffled just for demonstration
773
-dd <- dd[sample(1:13, 13), ]
774
-row.names(dd) <- NULL
775
-```
776
-```{r eval=FALSE}
777
-print(dd)
778
-```
779
-
780
-```{r echo=FALSE, results='asis'}
781
-knitr::kable(dd)
782
-```
783
-
784
-We can imaging that the _`place`_ column is the place we isolated the species and _`value`_ column stored numerical values for example bootstrap values.
785
-
786
-We have shown using the operator, _`%<%`_, to update a tree view with a new tree. Here, we will introduce another operator, _`%<+%`_, that attaches annotation data to a tree view. The only requirement of the input data is that its first column should be matched with the node/tip labels of the tree.
787
-
788
-After attaching the annotation data to the tree by _`%<+%`_, all the columns in the data are visible to _`ggplot2`_. As an example, here we attach the above annotation data to the tree view, _`p`_, and add a layer that showing the tip labels and colored them by the isolation site stored in _`place`_ column.
789
-
790
-```{r fig.width=6, fig.height=5, warning=FALSE, fig.align="center"}
791
-p <- p %<+% dd + geom_text(aes(color=place, label=label), hjust=-0.5) + 
792
-       geom_tippoint(aes(size=value, shape=place, color=place), alpha=0.25)
793
-p+theme(legend.position="right")
794
-```
795
-
796
-Once the data was attached, it is always attached. So we can add another layer to display the isolation sites easily.
797
-```{r fig.width=6, fig.height=5, warning=FALSE, fig.align="center"}
798
-p <- p + geom_text(aes(color=place, label=place), hjust=1, vjust=-0.4, size=3)
799
-print(p)
800
-```
801
-
802
-And another layer showing numerical values:
803
-```{r fig.width=6, fig.height=5, warning=FALSE, fig.align="center"}
804
-p <- p + geom_text(aes(color=place, label=value), hjust=1, vjust=1.4, size=3)
805
-print(p)
806
-```
807
-
808
-## `jplace` file format
809
-The _`jplace`_ file format was defined by Masten[@matsen_format_2012] for phylogenetic placements. We employed this file format to store phylogenetic tree and user specific annotation data. Suppose we have a tree, and the associated data as shown below:
810
-```{r}
811
-tree <- system.file("extdata", "pa.nwk", package="ggtree")
812
-data <- read.csv(system.file("extdata", "pa_subs.csv", package="ggtree"), stringsAsFactor=FALSE)
813
-print(tree)
814
-head(data)
815
-```
816
-
817
-The _`data`_ contains amino acid substitutions from parent node to child node and GC contents of each node. We can annotate the tree as demonstrated in [user specific annotation](#user-specific-annotation) session.
818
-
819
-`r Githubpkg("GuangchuangYu/ggtree")` provides a function, _`write.jplace`_, to combine a tree and an associated data and store them to a single _`jplace`_ file.
820
-```{r}
821
-outfile <- tempfile()
822
-write.jplace(tree, data, outfile)
823
-```
824
-
825
-Then _`read.jplace`_ function was designed to read the _`jplace`_ file and store the information to a _`jplace`_ object.
826
-```{r}
827
-jp <- read.jplace(outfile)
828
-print(jp)
829
-```
830
-
831
-Now we know the _`jp`_ object stored the tree and the associated amino acid substitution and GC content information, we can view the tree and display the associated annotation data on it directly by _`ggtree`_.
832
-
833
-```{r fig.width=12, fig.height=12, warning=FALSE, fig.align="center"}
834
-ggtree(jp, showDistance=TRUE) + 
835
-	   geom_text(aes(x=branch, label=subs), color="purple", vjust=-1, size=3) + 
836
-	   geom_text(aes(label=gc), color="steelblue", hjust=-.6, size=3) +
837
-	   geom_text(aes(label=label), hjust=-.5)
838
-```
839
-
840
-
841
-## visualize tree with associated matrix
842
-
843
-At first we implemented `gplot` function to visualize tree with heatmap but it has [an issue](https://github.com/GuangchuangYu/ggtree/issues/3) that it can't always guarantee the heatmap aligning to the tree properly, since the line up is between two figures and it's currently not supported internally by ggplot2. I have implemented another function `gheatmap` that can do the line up properly by creating a new layer above the tree.
844
-
845
-
846
-In the following example, we visualized a tree of H3 influenza viruses with their associated genotype.
847
-
848
-```{r fig.width=20, fig.height=16, fig.align="center"}
849
-genotype_file <- system.file("examples/Genotype.txt", package="ggtree")
850
-genotype <- read.table(genotype_file, sep="\t", stringsAsFactor=F)
851
-p <- ggtree(beast_tree, mrsd="2013-01-01") %>% add_legend(x=2008, y=5)
852
-p <- p + geom_tiplab(size=3)
853
-gheatmap(p, genotype, offset = 2, width=0.5)
854
-```
855
-
856
-The _width_ parameter is to control the width of the heatmap. It supports another parameter _offset_ for controling the distance between the tree and the heatmap, for instance left space for tip labels.
857
-
858
-
859
-For time scaled tree, as in this example, it's more often to use x axis by using `theme_tree2`. But with this solution, the heatmap is just another layer and will change the `x` axis. To overcome this issue, we implemented `scale_x_ggtree` to set the x axis more reasonable. User can also use `gplot` and tweak the positions of two plot to align properly.
860
-
861
-```{r fig.width=20, fig.height=16, fig.align="center"}
862
-p <- ggtree(beast_tree, mrsd="2013-01-01") + geom_tiplab(size=3, align=TRUE) + theme_tree2()
863
-pp <- (p + scale_y_continuous(expand=c(0, 0.3))) %>%
864
-    gheatmap(genotype, offset=4, width=0.5, colnames=FALSE) %>%
865
-        scale_x_ggtree()
866
-pp + theme(legend.position="right")
867
-```
868
-
869
-## visualize tree with multiple sequence alignment
870
-
871
-With `msaplot` function, user can visualizes multiple sequence alignment with phylogenetic tree, as demonstrated below:
872
-```{r fig.width=8, fig.height=12, fig.align='center'}
873
-fasta <- system.file("examples/FluA_H3_AA.fas", package="ggtree")
874
-msaplot(ggtree(beast_tree), fasta) 
875
-```
876
-
877
-A specific slice of the alignment can also be displayed by specific _window_ parameter.
878
-
879
-# External documents
880
-
881
-+ [viewing and annotating phylogenetic tree with ggtree](http://guangchuangyu.github.io/2014/12/viewing-and-annotating-phylogenetic-tree-with-ggtree/)
882
-+ [updating a tree view using %<% operator](http://guangchuangyu.github.io/2015/02/ggtree-updating-a-tree-view-using--operator/)
883
-+ [an example of drawing beast tree using ggtree](http://guangchuangyu.github.io/2015/04/an-example-of-drawing-beast-tree-using-ggtree/)
884
-+ [flip and rotate branches in ggtree](http://guangchuangyu.github.io/2015/07/flip-and-rotate-branches-in-ggtree/)
885
-+ [subsetting data in ggtree](http://guangchuangyu.github.io/2015/09/subsetting-data-in-ggtree/)
886
-+ [ggtree with funny fonts](http://guangchuangyu.github.io/2015/06/ggtree-with-funny-fonts/)
887
-+ [comic phylogenetic tree with ggtree and comicR](http://guangchuangyu.github.io/2015/09/comic-phylogenetic-tree-with-ggtree-and-comicr/)
888
-+ [embeding a subplot in ggplot via subview](http://guangchuangyu.github.io/2015/08/subview/)
889
-+ [annotate phylogenetic tree with local images](http://guangchuangyu.github.io/2015/08/ggtree-annotate-phylogenetic-tree-with-local-images/)
890
-+ [phylomoji with ggtree](http://guangchuangyu.github.io/2015/12/use-emoji-font-in-r/)
891
-
892
-
893
-# Bugs/Feature requests
894
-
895
-If you have any, [let me know](https://github.com/GuangchuangYu/ggtree/issues). Thx!
896
-
897
-
898
-# Session info
899
-Here is the output of `sessionInfo()` on the system on which this document was compiled:
900
-```{r echo=FALSE}
901
-sessionInfo()
902
-```
903
-
904
-
905
-# References
... ...
@@ -1,4 +1,19 @@
1 1
 
2
+@article{schliep_phangorn_2011,
3
+	title = {phangorn: phylogenetic analysis in R},
4
+	volume = {27},
5
+	url = {http://bioinformatics.oxfordjournals.org/content/27/4/592.abstract},
6
+	doi = {10.1093/bioinformatics/btq706},
7
+	shorttitle = {phangorn},
8
+	abstract = {Summary: phangorn is a package for phylogenetic reconstruction and analysis in the R language. Previously it was only possible to estimate phylogenetic trees with distance methods in R. phangorn, now offers the possibility of reconstructing phylogenies with distance based methods, maximum parsimony or maximum likelihood ({ML}) and performing Hadamard conjugation. Extending the general {ML} framework, this package provides the possibility of estimating mixture and partition models. Furthermore, phangorn offers several functions for comparing trees, phylogenetic models or splits, simulating character data and performing congruence analyses.Availability: phangorn can be obtained through the {CRAN} homepage http://cran.r-project.org/web/packages/phangorn/index.html. phangorn is licensed under {GPL} 2.Contact: klaus.kschliep@snv.jussieu.{frSupplementary} information: Supplementary data are available at Bioinformatics online.},
9
+	pages = {592--593},
10
+	number = {4},
11
+	journaltitle = {Bioinformatics},
12
+	author = {Schliep, Klaus Peter},
13
+	urldate = {2011-03-05},
14
+	date = {2011-02-15}
15
+}
16
+
2 17
 @article{hohna_probabilistic_2014,
3 18
 	title = {Probabilistic Graphical Model Representation in Phylogenetics},
4 19
 	volume = {63},
... ...
@@ -14,8 +29,7 @@
14 29
 	urldate = {2015-11-17},
15 30
 	date = {2014-09-01},
16 31
 	langid = {english},
17
-	pmid = {24951559},
18
-	file = {Full Text PDF:/Users/guangchuangyu/baiduYun/Zotero/storage/9ZKI33MX/Höhna et al. - 2014 - Probabilistic Graphical Model Representation in Ph.pdf:application/pdf;Snapshot:/Users/guangchuangyu/baiduYun/Zotero/storage/ZQ5W55MX/753.html:text/html}
32
+	pmid = {24951559}
19 33
 }
20 34
 
21 35
 @article{boussau_genome-scale_2013,
... ...
@@ -33,8 +47,7 @@
33 47
 	urldate = {2015-11-17},
34 48
 	date = {2013-02-01},
35 49
 	langid = {english},
36
-	pmid = {23132911},
37
-	file = {Full Text PDF:/Users/guangchuangyu/baiduYun/Zotero/storage/BTM73AG4/Boussau et al. - 2013 - Genome-scale coestimation of species and gene tree.pdf:application/pdf;Snapshot:/Users/guangchuangyu/baiduYun/Zotero/storage/KF3UWMH5/323.html:text/html}
50
+	pmid = {23132911}
38 51
 }
39 52
 
40 53
 @book{felsenstein_inferring_2003,
... ...
@@ -58,8 +71,7 @@
58 71
 	publisher = {Springer},
59 72
 	author = {Wickham, Hadley},
60 73
 	month = aug,
61
-	year = {2009},
62
-	file = {ggplot2-book.pdf:/home/ygc/baiduYun/Zotero/storage/DUV88796/ggplot2-book.pdf:application/pdf}
74
+	year = {2009}
63 75
 }
64 76
 
65 77
 @article{paradis_ape_2004,
... ...
@@ -75,8 +87,7 @@
75 87
 	author = {Paradis, Emmanuel and Claude, Julien and Strimmer, Korbinian},
76 88
 	month = jan,
77 89
 	year = {2004},
78
-	pages = {289--290},
79
-	file = {Full Text PDF:/home/ygc/baiduYun/Zotero/storage/ZTF3MA9A/Paradis et al. - 2004 - APE Analyses of Phylogenetics and Evolution in R .pdf:application/pdf;Snapshot:/home/ygc/baiduYun/Zotero/storage/9A2BT63C/289.html:text/html}
90
+	pages = {289--290}
80 91
 }
81 92
 
82 93
 @article{matsen_pplacer_2010,
... ...
@@ -92,8 +103,7 @@
92 103
 	journal = {{BMC} Bioinformatics},
93 104
 	author = {Matsen, Frederick A and Kodner, Robin B and Armbrust, E Virginia},
94 105
 	year = {2010},
95
-	pages = {538},
96
-	file = {BMC Bioinformatics | Full text | pplacer\: linear time maximum-likelihood and Bayesian phylogenetic placement of sequences onto a fixed reference tree:/home/ygc/baiduYun/Zotero/storage/4VVB5PDX/538.html:text/html}
106
+	pages = {538}
97 107
 }
98 108
 
99 109
 @article{matsen_format_2012,
... ...
@@ -108,8 +118,7 @@
108 118
 	author = {Matsen, Frederick A. and Hoffman, Noah G. and Gallagher, Aaron and Stamatakis, Alexandros},
109 119
 	month = feb,
110 120
 	year = {2012},
111
-	pages = {e31009},
112
-	file = {PLoS Full Text PDF:/home/ygc/baiduYun/Zotero/storage/7ZV87Q9V/Matsen et al. - 2012 - A Format for Phylogenetic Placements.pdf:application/pdf;PLoS Snapshot:/home/ygc/baiduYun/Zotero/storage/FPECIVJK/infodoi10.1371journal.pone.html:text/html}
121
+	pages = {e31009}
113 122
 }
114 123
 
115 124
 @article{berger_EPA_2011,
... ...
@@ -130,6 +139,25 @@
130 139
 	pages = {291--302}
131 140
 }
132 141
 
142
+@article{stamatakis_raxml_2014,
143
+	title = {{RAxML} Version 8: A tool for Phylogenetic Analysis and Post-Analysis of Large Phylogenies},
144
+	issn = {1367-4803, 1460-2059},
145
+	url = {http://bioinformatics.oxfordjournals.org.eproxy2.lib.hku.hk/content/early/2014/01/21/bioinformatics.btu033},
146
+	doi = {10.1093/bioinformatics/btu033},
147
+	shorttitle = {{RAxML} Version 8},
148
+	abstract = {Motivation: Phylogenies are increasingly used in all fields of medical and biological research. Moreover, because of the next generation sequencing revolution, datasets used for conducting phylogenetic analyses grow at an unprecedented pace. {RAxML} (Randomized Axelerated Maximum Likelihood) is a popular program for phylogenetic analyses of large datasets under maximum likelihood. Since the last {RAxML} paper in 2006, it has been continuously maintained and extended to accommodate the increasingly growing input datasets and to serve the needs of the user community.
149
+Results: I present some of the most notable new features and extensions of {RAxML}, such as, a substantial extension of substitution models and supported data types, the introduction of {SSE}3, {AVX}, and {AVX}2 vector intrinsics, techniques for reducing the memory requirements of the code and a plethora of operations for conducting post-analyses on sets of trees. In addition, an up-to-date, 50 page user manual covering all new {RAxML} options is available.
150
+Availability: The code is available under {GNU} {GPL} at https://github.com/stamatak/standard-{RAxML}.
151
+Contact: Alexandros.Stamatakis@h-its.org},
152
+	pages = {btu033},
153
+	journaltitle = {Bioinformatics},
154
+	shortjournal = {Bioinformatics},
155
+	author = {Stamatakis, Alexandros},
156
+	urldate = {2015-12-28},
157
+	date = {2014-01-21},
158
+	langid = {english},
159
+	pmid = {24451623}
160
+}
133 161
 
134 162
 @article{mcmurdie_phyloseq_2013,
135 163
 	title = {phyloseq: An R Package for Reproducible Interactive Analysis and Graphics of Microbiome Census Data},
... ...
@@ -144,8 +172,25 @@
144 172
 	author = {McMurdie, Paul J. and Holmes, Susan},
145 173
 	month = apr,
146 174
 	year = {2013},
147
-	pages = {e61217},
148
-	file = {PLoS Full Text PDF:/home/ygc/baiduYun/Zotero/storage/CZK5PHWV/McMurdie and Holmes - 2013 - phyloseq An R Package for Reproducible Interactiv.pdf:application/pdf;PLoS Snapshot:/home/ygc/baiduYun/Zotero/storage/EBBEPQDD/infodoi10.1371journal.pone.html:text/html}
175
+	pages = {e61217}
176
+}
177
+
178
+@article{marazzi_locating_2012,
179
+	title = {Locating Evolutionary Precursors on a Phylogenetic Tree},
180
+	volume = {66},
181
+	rights = {© 2012 The Author(s). Evolution© 2012 The Society for the Study of Evolution.},
182
+	issn = {1558-5646},
183
+	url = {http://onlinelibrary.wiley.com.eproxy2.lib.hku.hk/doi/10.1111/j.1558-5646.2012.01720.x/abstract},
184
+	doi = {10.1111/j.1558-5646.2012.01720.x},
185
+	abstract = {Conspicuous innovations in the history of life are often preceded by more cryptic genetic and developmental precursors. In many cases, these appear to be associated with recurring origins of very similar traits in close relatives (parallelisms) or striking convergences separated by deep time (deep homologies). Although the phylogenetic distribution of gain and loss of traits hints strongly at the existence of such precursors, no models of trait evolution currently permit inference about their location on a tree. Here we develop a new stochastic model, which explicitly captures the dependency implied by a precursor and permits estimation of precursor locations. We apply it to the evolution of extrafloral nectaries ({EFNs}), an ecologically significant trait mediating a widespread mutualism between plants and ants. In legumes, a species-rich clade with morphologically diverse {EFNs}, the precursor model fits the data on {EFN} occurrences significantly better than conventional models. The model generates explicit hypotheses about the phylogenetic location of hypothetical precursors, which may help guide future studies of molecular genetic pathways underlying nectary position, development, and function.},
186
+	pages = {3918--3930},
187
+	number = {12},
188
+	journaltitle = {Evolution},
189
+	author = {Marazzi, Brigitte and Ané, Cécile and Simon, Marcelo F. and Delgado-Salinas, Alfonso and Luckow, Melissa and Sanderson, Michael J.},
190
+	urldate = {2015-12-28},
191
+	date = {2012-12-01},
192
+	langid = {english},
193
+	keywords = {Deep homology, extra-floral nectary, homoplasy, trait evolution}
149 194
 }
150 195
 
151 196
 @article{yang_paml_2007,
... ...
@@ -188,8 +233,7 @@ Supplementary information: {HyPhydocumentation} and tutorials are available at h
188 233
 	month = mar,
189 234
 	year = {2005},
190 235
 	pmid = {15509596},
191
-	pages = {676--679},
192
-	file = {Full Text PDF:/home/ygc/baiduYun/Zotero/storage/QQQHIQ53/Pond et al. - 2005 - HyPhy hypothesis testing using phylogenies.pdf:application/pdf;Snapshot:/home/ygc/baiduYun/Zotero/storage/6Z2RZ39K/676.html:text/html}
236
+	pages = {676--679}
193 237
 }
194 238
 
195 239
 @article{bouckaert_beast_2014,
... ...
@@ -205,6 +249,5 @@ Supplementary information: {HyPhydocumentation} and tutorials are available at h
205 249
 	author = {Bouckaert, Remco and Heled, Joseph and Kühnert, Denise and Vaughan, Tim and Wu, Chieh-Hsi and Xie, Dong and Suchard, Marc A. and Rambaut, Andrew and Drummond, Alexei J.},
206 250
 	month = apr,
207 251
 	year = {2014},
208
-	pages = {e1003537},
209
-	file = {PLoS Full Text PDF:/home/ygc/baiduYun/Zotero/storage/MT4B9N27/Bouckaert et al. - 2014 - BEAST 2 A Software Platform for Bayesian Evolutio.pdf:application/pdf;PLoS Snapshot:/home/ygc/baiduYun/Zotero/storage/M2BPZAM3/infodoi10.1371journal.pcbi.html:text/html}
252
+	pages = {e1003537}
210 253
 }
211 254
new file mode 100644
... ...
@@ -0,0 +1,251 @@
1
+---
2
+title: "Tree Data Import"
3
+author: "\\
4
+
5
+	Guangchuang Yu (<guangchuangyu@gmail.com>) and Tommy Tsan-Yuk Lam (<ttylam@hku.hk>)\\
6
+
7
+        School of Public Health, The University of Hong Kong"
8
+date: "`r Sys.Date()`"
9
+bibliography: ggtree.bib
10
+csl: nature.csl
11
+output: 
12
+  BiocStyle::html_document:
13
+    toc: true
14
+  BiocStyle::pdf_document:
15
+    toc: true
16
+vignette: >
17
+  %\VignetteIndexEntry{01 Tree Data Import}
18
+  %\VignetteEngine{knitr::rmarkdown}
19
+  %\usepackage[utf8]{inputenc}
20
+---
21
+
22
+```{r style, echo=FALSE, results="asis", message=FALSE}
23
+BiocStyle::markdown()
24
+knitr::opts_chunk$set(tidy = FALSE,
25
+		   message = FALSE)
26
+```
27
+
28
+
29
+```{r echo=FALSE, results="hide", message=FALSE}
30
+library("ape")
31
+library("ggplot2")
32
+library("ggtree")
33
+```
34
+
35
+
36
+The `r Githubpkg("GuangchuangYu/ggtree")` package should not be viewed solely as a standalone software. While it is useful for viewing, annotating and manipulating phylogenetic trees, it is also an infrastructure that enables evolutionary evidences that inferred by commonly used software packages in the field to be used in `R`. For instance, *dN/dS* values or ancestral sequences inferred by [CODEML](http://abacus.gene.ucl.ac.uk/software/paml.html)[@yang_paml_2007], *clade support values (posterior)* inferred by [BEAST](http://beast2.org/)[@bouckaert_beast_2014] and short read placement by [EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011] and [pplacer](http://matsen.fhcrc.org/pplacer/)[@matsen_pplacer_2010]. These evolutionary evidences are not only used in annotating phylogenetic tree in  `r Githubpkg("GuangchuangYu/ggtree")` but can also be further analyzed in `R`.
37
+
38
+# Supported File Formats
39
+
40
+Most of the tree viewer software (including `R` packages) focus on `Newick` and `Nexus` file format, while there are file formats from different evolution analysis software that contain supporting evidences within the file that are ready for annotating a phylogenetic tree.
41
+The `r Githubpkg("GuangchuangYu/ggtree")` package define several parser functions and `S4` classes to store statistical evidences inferred by commonly used software packages. It supports several file format, including:
42
+
43
++ Newick (via `ape`)
44
++ Nexus (via `ape`)
45
++ New Hampshire eXtended format (NHX)
46
++ Jplace
47
+
48
+and software output from:
49
+
50
++ [BEAST](http://beast2.org/)[@bouckaert_beast_2014] 
51
++ [EPA](http://sco.h-its.org/exelixis/web/software/epa/index.html)[@berger_EPA_2011]
52
++ [HYPHY](http://hyphy.org/w/index.php/Main_Page)[@pond_hyphy_2005]
53
++ [PAML](http://abacus.gene.ucl.ac.uk/software/paml.html)[@yang_paml_2007]
54
++ [PHYLDOG](http://pbil.univ-lyon1.fr/software/phyldog/)[@boussau_genome-scale_2013]
55