Phylogenetic tree——系统发育树的构建

具体构建发育树的软件非常多,这里主要使用R软件中的tidytree, treeio和ggtree包来进行数据整合、操作和图像绘制(https:yulab-smu.github.io/treedata-book)。

一、数据导入

系统发育树的格式非常多,不同的软件输出格式不尽相同。常见的格式有Newick,NEXUS和Phylip。具体格式见treedata-book。
treeio包主要就是用来导入和导出不同格式树文件。主要函数有:
get.fields:获取树对象中的注释信息;
get.placements:获取系统发育树定位信息(phylogenetic placement results);
get.subs:获取从父节点到子节点的遗传替换信息;
get.tipseq:获取叶节点的序列。
同时as.phyloas.treedata能将phylo对象和treeio的S4对象相互转换。
read.beast():读取BEAST Nexus;
read.tree(), read.newick():读取Newick文件;
read.mega():读取MEGA文件,read.mega_tabular()读取MEGA表格纯文本格式文件。多数软件的输出格式均有支持,具体见包说明文档。

二、数据操作

数据操作主要是通过tidytree包来完成。
ape包是R里做系统发育分析的基础包,所以tidytree包提供了as_tibble函数来转换ape中的phylo对象。同时,full_join函数提供了将其他信息整合到tbl_tree的方法,最后,as.treedata函数将其转成treedata对象。

set.seed(2017)
tree <- rtree(4) #生成树
x <- as_tibble(tree) # 转成tibble
d <- tibble(label=past0('t', 1:4),trait=rnorm(4)) # 定义其他外部相关信息
y <- full_join(x, d, by="label") # 将其他信息整合到树中
as.treedata(y) # 转成treedata对象

获取树相关节点信息主要是在tbl_tree对象中:
y %>% as.treedata %>% as_tibble
主要函数有child, parent, offspring, ancestor, sibling and MRCA
merge_tree():融合树;
full_join():整合外部信息;
groupOTU, groupClade:对树进行分组,均可在tbl_tree, phylo, treedata对象上操作。

groupClade(as_tibble(tree), c(17, 21))
groupOTU(as_tibble(tree), c('t1','t4'), group_name="fake_group")

drop_tip(): 去除树中指定节点。
如果树很大,可以用tree_subset函数来提取部分结构展示。

三、树的绘制

ggtree包继承了ggplot2的图层概念,可以利用不同的图层来对信息进行注释。geom_treescale:添加树枝比例(遗传距离、分化时间等);
geom_range:显示树枝长度的置信区间;
geom_tiplab:添加叶节点标签;
geom_tippointgeom_nodepoint:分别为叶节点和内部节点添加符号;
geom_hilight:用矩形高亮显示分化枝;
geom_cladelabel:用条形和文字为选择的分化枝进行注释。

Layer Description
geom_balance highlights the two direct descendant clades of an internal node
geom_cladelabel annotate a clade with bar and text label
geom_facet plot associated data in specific panel (facet) and align the plot with the tree
geom_hilight highlight a clade with rectangle
geom_inset add insets (subplots) to tree nodes
geom_label2 modified version of geom_label, with subsetting supported
geom_nodepoint annotate internal nodes with symbolic points
geom_point2 modified version of geom_point, with subsetting supported
geom_range bar layer to present uncertainty of evolutionary inference
geom_rootpoint annotate root node with symbolic point
geom_rootedge add root edge to a tree
geom_segment2 modified version of geom_segment, with subsetting supported
geom_strip annotate associated taxa with bar and (optional) text label
geom_taxalink associate two related taxa by linking them with a curve
geom_text2 modified version of geom_text, with subsetting supported
geom_tiplab layer of tip labels
geom_tippoint annotate external nodes with symbolic points
geom_tree tree structure layer, with multiple layout supported
geom_treescale tree branch scale legend
set.seed(2019)
rm(list=ls())
tree <- rtree(50)
p1 <- ggtree(tree)
p2 <- ggtree(tree, layout = "slanted")
p3 <- ggtree(tree, layout = "circular")
p4 <- ggtree(tree, layout="fan", open.angle = 120)
p5 <- ggtree(tree, layout = "equal_angle")
p6 <- ggtree(tree, layout = "daylight")
p7 <- ggtree(tree, branch.length = "none")
p8 <- ggtree(tree, branch.length = "none", layout = "circular")
p9 <- ggtree(tree, layout = "daylight", branch.length = "none")
plot_grid(p1, p2, p3, p4, p5,p6, p7, p8,p9, ncol=3, labels=LETTERS[1:9])
tree_plot.jpeg

参考文献:

https://yulab-smu.github.io/treedata-book/index.html

你可能感兴趣的:(Phylogenetic tree——系统发育树的构建)