使用Biopython从gff文件提取gene的位置以及gene的id,再从fna文件提取gene序列
需要注意的是 Biopython存储到parse里面的并不是和文件的 染色体的顺序一致,在这里对字典嵌套列表,保存基因的位置以及其他信息,biopython读取的序列切片是从0开始的,这里它读取的基因的位置整体偏移1位

头部几个和NcBI里面的对比一下

对比一下尾部几个碱基
from Bio import SeqIO
from BCBio import GFF
import re
def get_geneLocation_geneId(in_file,gene_len):
"""
本函数主要应用于从gff文件提取gene的location以及gene的id
in_file 为 输入的 gff文件
gene_len 为 需要提取的基因长度
"""
in_handle = open(in_file)
gene_information =dict()
for rec in GFF.parse(in_handle):
j=0
i=0
while j<len(rec.features):
if rec.features[j].type=='region':
tem = str(rec.features[j].id.split(':')[0])
gene_information[tem]=[]
if rec.features[j].type=='gene':
gene_location_t=[int(s) for s in re.findall(r'-?\d+\.?\d*', str(rec.features[j].location))]
if gene_location_t[1]-gene_location_t[0] < gene_len :
gene_information[tem].append([gene_location_t[0],gene_location_t[1],\
str

这段代码展示了如何利用Biopython的GFF和SeqIO模块从GFF文件中获取基因位置和ID,然后从FNA文件中提取相应的基因序列。由于Biopython的顺序问题,代码使用了字典嵌套列表来保存信息,并处理了位置偏移。最后,提取的基因序列被写入到.fasta文件中。
最低0.47元/天 解锁文章
736

被折叠的 条评论
为什么被折叠?



