點擊藍字↑↑↑「微生態」,輕鬆關注不迷路
本文由阿童木根據實踐經驗而整理,希望對大家有幫助。
原創微文,歡迎轉發轉載。
舉例介紹如何用R語言gggenes函數包把基因預測得到的gff或gtf文件(含基因位置信息)中的基因類型、位置可視化到圖中。
注意:
R version >= 3.6
gggenes依賴的ggfittext需要R 3.6以上,導致我用R 3.4.1安裝gggenes失敗。後來改用R 3.6.1成功安裝。
Linux conda安裝R 3.6
conda install -c r r=3.6
一, 輸入數據
1. 基因組-基因-方向
library(ggplot2)
library(gggenes)
data(example_genes)
head(example_genes)
圖1
2 基因組-基因-亞基因
head(example_subgenes)
圖2
一、畫基因箭頭圖
1 基礎繪圖
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3")
圖3
2. 去掉背景
方法:theme_genes()
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
圖4
3. 按geneE對齊
方法:make_alignment_dummies()
dummies <- make_alignment_dummies(
example_genes,
aes(xmin = start, xmax = end, y = molecule, id = gene),
on = "genE"
)
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
圖5
4. 按設置箭頭形狀
方法:geom_gene_label()
ggplot(example_genes, aes(xmin = start, xmax = end, y =
molecule, fill = gene, label = gene)) +
geom_gene_arrow(arrowhead_height = unit(3, "mm"), arrowhead_width = unit(1, "mm")) +
geom_gene_label(align = "left") +
geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
圖6
5. 控制箭頭方向
example_genes$direction <- ifelse(example_genes$strand == "forward", 1, -1)
ggplot(
subset(example_genes, molecule == "Genome1"),
aes(xmin = start, xmax = end, y = strand, fill = gene, forward = direction)
) +
geom_gene_arrow() +
theme_genes()
圖7
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule, fill = gene, forward = direction)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
圖8
6. 標記亞基因位置
方法:geom_subgene_arrow()
ggplot(example_genes, aes(xmin = start, xmax = end, y = molecule)) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
geom_gene_arrow(fill = "white") +
geom_subgene_arrow(data = example_subgenes,
aes(xmin = start, xmax = end, y = molecule, fill = gene,
xsubmin = from, xsubmax = to), color="black", alpha=.7) +
theme_genes()
圖9
7. 標記某基因組中某基因的亞基因位置
方法:geom_subgene_label()
ggplot(subset(example_genes, molecule == "Genome4" & gene == "genA"),
aes(xmin = start, xmax = end, y = strand)
) +
geom_gene_arrow() +
geom_gene_label(aes(label = gene)) +
geom_subgene_arrow(
data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"),
aes(xsubmin = from, xsubmax = to, fill = subgene)
) +
geom_subgene_label(
data = subset(example_subgenes, molecule == "Genome4" & gene == "genA"),
aes(xsubmin = from, xsubmax = to, label = subgene),
min.size = 0
)
圖10
你可能還喜歡
1 技術貼 | 16S專題 | 簡單介紹如何用自己的筆記本處理高通量16S數據
2 技術貼 | 宏基因組專題 | 組裝工具盤點和比較
3 技術貼 | R語言菌群Alpha多樣性分析和繪圖
4 技術貼 | 宏轉錄組專題 | DDBJ資料庫:宏轉錄組測序數據下載
5 技術貼 | R語言pheatmap聚類分析和熱圖
微生態科研學術群期待與您交流更多微生態科研問題
(聯繫微生態老師即可申請入群)
了解更多菌群知識,請關注「微生態」。