ggmotif的使用

激发我开发这个R包的原因是在许做基因家族分析中的motif分析的时候总是找不到趁手的工具去可视化相关的结果,要么是在线网站,要么是别人开发的工具,网页版工具怕哪天就跑路了,别人的工具想要个性化比较困难。那,就自己写一个吧。

R包下载安装:

1
2
3
4
install.packages("ggmotif")

# 或者
devtools::install_github("lixiang117423/ggmotif")

meme输出的结果主要是XML格式和txt格式的文件,需要的结果就在这两个文件里面。

从XML文件提取结果并绘图

motif在序列上的位置结果存放在XML格式的文件中,运行下面的代码便可以将结果转换成数据框格式并进行可视化。

1
2
3
4
filepath <- system.file("examples", "meme.xml", package="ggmotif")
motif_extract <- getMotifFromXML(XMLfile = filepath)
motif_plot <- motif_location(data = motif_extract)
motif_plot

从txt文件提取结果并进行可视化

每个motif的序列是存放在txt文件中的,运行下方的代码便能结果转换成数据框格式并进行绘图。

1
2
3
4
5
6
7
8
9
10
11
library(tidyverse)

filepath <- system.file("examples", "meme.txt", package = "ggmotif")
motif_extract <- getMotifFromTxt(data = filepath)

motif_extract %>%
dplyr::filter(motif.num == 'Motif.1') %>%
dplyr::select(input.seq.motif) %>%
ggseqlogo::ggseqlogo() +
theme_classic()

ggtree联用

有时候会对序列构建进化树展示进化关系,ggmotif中的函数能够以输入的进化树文件为基础,把输出的motif在序列上的位置与进化树上的位置进行匹配,便能够与ggtree联用在一个图上展示进化树和motif在序列上的位置。

1
2
3
4
5
6
7
8
9
10
11
filepath <- system.file("examples", "meme.xml", package="ggmotif")
treepath <- system.file("examples", "tree.nwk", package="ggmotif")
motif_extract <- getMotifFromXML(XMLfile = filepath)
motif_plot_with_tree <- motif_with_tree(data = motif_extract, tree = treepath)

p.tree = ape::read.tree(treepath) %>%
ggtree::ggtree() +
ggtree::geom_tiplab()

p.tree %>%
aplot::insert_right(motif_plot_with_tree, width = 0.8)

💌lixiang117423@foxmail.com
💌lixiang117423@gmail.com


ggmotif的使用
https://lixiang117423.github.io/article/ggmotif/
作者
小蓝哥
发布于
2021年11月25日
许可协议