使用biopython来提取带有注释文件的指定gene长度的gene

使用biopython来提取带有注释文件的指定gene长度的gene

from Bio import SeqIO
import re

def get_gene(file_path):#"GCF_904848185.1_fAcaLat1.1_genomic.gbff"
    '''
        本函数主要应用于从带有注释的gbff文件里面提取基因
        file_path 为 输入的gbff文件
        seq_record.features[1].location 主要是为了获取gene的位置,然后转换成字符串
        再使用re匹配数字,转换成相对应的整型,
        通过if来判断两次基因位置的差值,来获取指定长度的gene
        
        返回为gene以及gene的Id
        gbff 文件 中的  feature  会有时出现 assembly ,gene 会向下移动,所以 做了个比较
    '''
    return_gene=[]
    gene_id = []
    for seq_record in SeqIO.parse(file_path, "genbank"):
        #print (seq_record.id)
        #print (repr(seq_record.seq))
        #print (seq_record.features.gene_location)
        j=0
        while j < len(seq_record.features):
            #print(seq_record.features[j].type)
            try:
                if seq_record.features[j].type == 'gene':
                    #print(seq_record.features[j].type)
                    gene_location = [int(s) for s in re.findall(r'-?\d+\.?\d*', str(seq_record.features[j].location))]
                    #gene_location = str(seq_record.features[j].location)
                    if gene_location[1]-gene_location[0] < 30000:
                        #print(gene_location)
                        gene_id.append([str(seq_record.features[j].qualifiers['gene']),str(seq_record.features[j].qualifiers['db_xref']),str(seq_record.features[j].location)])
                        return_gene.append(str(seq_record.seq[gene_location[0]:gene_location[1]]))
                j=j+1
            except:
                print("over")
                #print(seq_record.features[j].location)
                #print(dd)
    return return_gene,gene_id
    print('over')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值