日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python绘制基因结构图_从 gff 到 gggenes 绘制基因结构图

發布時間:2025/3/20 python 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python绘制基因结构图_从 gff 到 gggenes 绘制基因结构图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

gffutils 是一個用來解析 gff 文件的 Python 包,可以十分方便地獲取 gff 文件中的相關信息。gggenes 是 ggplot2 的擴展包,用于繪制基因結構圖、多物種基因比較圖的很好玩的工具。兩個工具聯用可以實現從 gff 數據獲取到基因結構圖繪制的全過程。

對 gff 原始數據進行處理

安裝 gffutils

使用 conda 或者 pip 進行安裝。

conda install gffutils

pip install gffutils

gff 文件預處理

對 gff 文件進行預處理,截取包含所需基因的 gff 內容。建議在 Linux 中使用 sed 命令完成。如果進行比較基因組工作,需要將各基因組數據合并到一個 gff 文件中。

程序調用

下載 gff2gggenes.py 到本地。

Windows 中利用 powershell 調用程序:

python .\gff2gggenes.py example.gff

python .\gff2gggenes.py example.gff sub

Linux 中利用 console 調用程序:

python ./gff2gggenes.py example.gff

python ./gff2gggenes.py example.gff sub

根據安裝 Python 的版本不同,可能需要將“python”替換為“python3”。

不添加 sub 參數,表示只將各基因的情況進行輸出;添加 sub 參數,表示同時輸出各基因子區域(例如:mRNA、CDS等,與 gff 文件內容有關)。

結果輸出

界面顯示“完成”表示程序運行成功。csv 文件輸出到工作路徑中,文件名結尾是“_Gene.csv”或者“_SubGene.csv”。

利用 R 包 gggenes 進行可視化

gggene 安裝

直接從 CRAN 安裝:

install.packages("gggenes")

如果使用 rstudio 進行 R 工作,也可以在 package 中安裝。

啟用 ggplot2 和 gggene

可以在 rstudio 的包管理工具中開啟,也可以使用以下代碼:

library(ggplot2)

library(gggenes)

導入 python 程序生成的 csv 數據

geneData = read.csv('gene.csv')

用geom_gene_arrow()畫基因箭頭

ggplot(geneData, 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 美化圖形

默認的圖形不太美觀,可以使用自帶的 theme_genes() 進行美化。

ggplot(geneData, 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()

使用 make_alignment_dummies() 跨面對齊基因

可以選擇一個基因將所有數據進行對齊,在比較基因組時會用到。

dummies

geneData,

aes(xmin = start, xmax = end, y = molecule, id = gene),

on = "geneX"

)

ggplot(geneData, 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()

用 geom_gene_label() 標記基因

geom_gene_label() 可以將標簽文本放入基因箭頭內,需要把基因名字所在的列名字映射到 label 屬性。依賴于 ggfittext 包。

ggplot(

geneData,

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()

查看基因子片段(subgene)

可以使用 geom_subgene_arrow() 突出顯示子基因片段。此時,需要多調用另一個 csv 文件。

subGeneData = read.csv('subGene.csv')

ggplot(geneData, aes(xmin = start, xmax = end, y = molecule)) +

facet_wrap(~ molecule, scales = "free", ncol = 1) +

geom_gene_arrow(fill = "white") +

geom_subgene_arrow(data = subGeneData,

aes(xmin = start, xmax = end, y = molecule, fill = gene,

xsubmin = from, xsubmax = to), color="black", alpha=.7) +

theme_genes()

同時,也可以為基因子片段添加標簽。

ggplot(geneData, aes(xmin = start, xmax = end, y = strand)

) +

geom_gene_arrow() +

geom_gene_label(aes(label = gene)) +

geom_subgene_arrow(

data = subGeneData, aes(xsubmin = from, xsubmax = to, fill = subgene)

) +

geom_subgene_label(

data = subGeneData, aes(xsubmin = from, xsubmax = to, label = subgene),

min.size = 0

)

總結

以上是生活随笔為你收集整理的python绘制基因结构图_从 gff 到 gggenes 绘制基因结构图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。