栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

利用python将gbk格式转换为fasta && 从多个fasta序列中抽取特定序列

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用python将gbk格式转换为fasta && 从多个fasta序列中抽取特定序列

将gbk格式文件转换成fasta格式文件

flag=0fasta = open ('/mnt/f/biopython/AY810830.fasta','w')with open ('/mnt/f/biopython/AY810830.gbk','r') as f:    for line in f:        if line[0:9] =='ACCESSION':
            fasta.writelines('>'+line.split()[1]+'n')        elif line[0:6] =='ORIGIN':
            flag = 1
        elif flag == 1:
            s = line.split()            if s != []:
                print(s)
                seq=''.join(s[1:])
                fasta.writelines(seq.upper()+'n')
fasta.close()

将多个fasta序列中提取含有'Homo sapiens'的序列

fasta_file=open('multi.fasta','r')
out_file=open('human.fasta','w')
seq = ''for line in fasta_file:    if line[0]=='>' and seq =='':
        header = line    elif line[0] != '>':
        seq=seq+line    elif line[0] =='>' and seq !='':        if "Homo sapiens" in header:
            out_file.write(header+seq)
        seq = ''
        header = lineif "Homo sapiens" in header :
    out_file.write(header+seq)
out_file.close()



作者:tianzhanlan
链接:https://www.jianshu.com/p/492a6e4a1b19



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/221451.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号