系统发生树的绘制

写在前面

今天写一写聚类图的绘制,因为作者这是个对生信感兴趣的非生物学本科生;再加上我一直认为像我这种靠兴趣学习的小白,从分析过程入手进行学习会有趣些,所以这次内容可能会偏向于操作,具体的原理可以看看其他大佬的。

系统发生数数据的获取

系统发生数的构建主要是基于SNP进行,其具有距离矩阵法、最大似然法、最大简约法和贝叶斯法,其中距离矩阵法中的邻接法为一种常见的方法(各方法具体的原理可见其他大佬的推文,或者等我学完来写写)。
为了省时又便于理解,我们通过tassel5进行获取数据

  • 将SNP数据导入tassel5软件
  • analysis-relatedness-creat tree 进行构建系统发生树
  • 在返回的文件上选择results-archaeopteryx tree可以康一康构建出来的树
    tassel5 create tree

但是,这图明显不好看啊,和我在文章里面看的完全不一样啊

系统发生树数据的导出

在analysis-relatedness-creat tree结果文件导出为newwick格式

系统发生树的美化

方式一:通过iTOL平台

网址如下:https://itol.embl.de/
是这个样子的
自己玩泥巴去吧(自己摸索摸索,很简单来着)

方式二:通过R package-ggtree

ggtree 是Guangchuang Yu(人称Y叔)构建的系统发生树构建的R package,这是ggtree的主页https://bioconductor.org/packages/devel/bioc/vignettes/ggtree/inst/doc/ggtree.html

1、安装package-ggtree
#the first way
install.packages("ggtree")
#一般情况下rstudio默认的源里面是找不到ggtree
#因此可以通过BiocManager下载
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("ggtree")

下载完成后library()一下看一下安装完成否

2、读取.new数据
library(stringr)
library(ggtree)
library(treeio)
tree<-read.tree("tree.nwk")
ggtree(tree,branch.length = 'none',layout = 'circular')+
  geom_tiplab(size=1)

可以看到ggtree的绘制格式类似于ggplot2

3、具体参数介绍
#颜色大小类型等设置类似于ggplot2
ggtree(tree, color="firebrick", size=2, linetype="dotted")
#发生树默认以阶梯状排列,可以自行控制
ggtree(tree, ladderize=FALSE)
系统发生树的类型可以自定义
ggtree(tree, layout="roundrect")
ggtree(tree, layout="slanted")
ggtree(tree, layout="ellipse")
ggtree(tree, layout="circular")
ggtree(tree, layout="fan", open.angle=120)
ggtree(tree, layout="equal_angle")
ggtree(tree, layout="daylight")
ggtree(tree, branch.length='none')
ggtree(tree, layout="ellipse", branch.length="none")
ggtree(tree, branch.length='none', layout='circular')
ggtree(tree, layout="daylight", branch.length = 'none')
#具体效果见下图,更多的效果可以通过设置坐标等进行更改

进化树的组件
#通过geom_treescale()控制
ggtree(tree)+geom_treescale()
#其中参数为
ggtree(tree) + geom_treescale(x=0, y=45, width=1, color='red')
ggtree(tree) + geom_treescale(fontsize=6, linesize=2, offset=1)
#xy控制数的比例位置
#width控制树宽度
#fontsize控制文本大小
#linesize控制线大小
#offset控制文本偏移量
#color控制文本颜色
#通过theme_tree2()添加树的X轴
ggtree(tree) + theme_tree2()
#通过geom_nodepoint()显示内部节点
#通过geom_tippoint()显示外部节点
ggtree(tree) + geom_point(aes(shape=isTip, color=isTip), size=3)

#geom_text()控制显示节点和提示标签
#geom_label()控制显示节点和提示标签
#geom_tiplab()控制显示提示标签
ggtree(tree, layout="circular") + geom_tiplab(aes(angle=angle), color='blue')
#见下图B

#geom_rootedge()控制显示根边
ggtree(tree1) + geom_tiplab() + geom_rootedge()
#通过aes(color=)控制颜色
系统发育树注释
#具体参数如下
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 selected clade with rectanglar or round shape
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   Linking related taxa
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

因内容过多,具体内容可见 Data Integration, Manipulation and Visualization of Phylogenetic Trees,反正我直接偷跑先开始学了~