本文主要工作:
對(duì)SBT基因家族的基因結(jié)構(gòu)進(jìn)行可視化呈現(xiàn)
4.2 基因結(jié)構(gòu)可視化
可視化基因結(jié)構(gòu)绩脆,無(wú)非就是展示基因區(qū)域的組成:3’,5’-UTR,exon或展示CDS古涧,intro n等等洪碳,有關(guān)它們的詳細(xì)定義可以參考文章。在這里我們想要可視化展示3’,5’-UTR拟淮,exon和基因的關(guān)系。需要的原始文件是基因組注釋gff3文件侈贷,我們想要的信息只有SBT家族基因長(zhǎng)度惩歉,基因id等脂,exon的長(zhǎng)度,在基因上的起始和終止位置撑蚌,它屬于哪個(gè)基因等信息上遥。因此,要對(duì)gff3文件進(jìn)行一定的處理争涌,處理思路如下:import re
gene_dict = {"gene_start":""}
output = ""
output_type = ["exon", "five_prime_UTR", "three_prime_UTR"]
with open("./stat_input.txt", "r") as f:
while True:
line = f.readline()
if not line:
break
else:
line_list = re.split("\t|\n", line)
if line_list[1] == "gene":
gene_dict["gene_start"] = line_list[2]
elif line_list[1] in output_type:
region_start = str(int(line_list[2]) - int(gene_dict["gene_start"]))
region_end = str(int(line_list[3]) - int(gene_dict["gene_start"]))
output += line_list[0] + "\t" + line_list[1] + "\t" + region_start + "\t" + region_end + "\n"
file_output = open("gene_structure_temp.txt", "w")
file_output.write(output)
file_output.close()
處理后的文件如下所示:除此之外,我們還需要記錄基因長(zhǎng)度的文件作為繪圖的輸入文件饮潦,這個(gè)比較好解決燃异,在之前的腳本中就已經(jīng)直接生成了,現(xiàn)在我們按照繪制蛋白質(zhì)模體的思路繪制相同的圖:
library(data.table)
library(tidyverse)
# 載入文本
cds_length <- fread("./DATA/aco.sbt.gene.length.txt", header = F)
cds_length <- mutate(cds_length, V3=0)
gene_structure <- fread("./DATA/gene_structure_temp.txt", header = F)
# 畫(huà)圖
ggplot() +
geom_segment(data = gene_structure,
aes(x = as.numeric(V3),
y = V1,
xend = as.numeric(V4),
yend = V1,
color = V2),
linewidth = 2.5,
position = position_nudge(y = 0.2)) +
scale_color_brewer(palette = "Set2") +
geom_segment(data = cds_length,
aes(x = as.numeric(V3),
y = V1,
xend = as.numeric(V2),
yend = V1),
color = "grey",
linewidth = 1) +
scale_x_continuous(expand = c(0,0)) +
labs(y = "Family",
x = "Length",
color = "Structure") +
theme_classic()
由于存在一個(gè)含有較大內(nèi)含子的基因存在继蜡,這顯得整體比例很不協(xié)調(diào)回俐,但是從整體上來(lái)講,呈現(xiàn)以及繪圖思路是沒(méi)問(wèn)題的| 基因家族分析系列(持續(xù)更新)
0.基因家族分析(0):概念明晰
1.基因家族分析(1):數(shù)據(jù)下載與處理
2.基因家族分析(2):基因家族鑒定與蛋白質(zhì)性質(zhì)簡(jiǎn)單分析
3.基因家族分析(3):序列比對(duì)與進(jìn)化樹(shù)構(gòu)建
4.基因家族分析(4):基因家族蛋白質(zhì)模體鑒定與可視化