首页 > 编程语言 > 详细

Python .seq文件批量转.fas 并根据文件夹与文件名重命名

时间:2021-09-06 06:40:02      阅读:26      评论:0      收藏:0      [点我收藏+]
import os
file_path=r‘C:\Users\aklasim\Desktop\LAB\序列分割程序+结果\姬蠊py\part‘
pathDir = os.listdir(file_path)

#folder=r‘C:\Users\aklasim\Desktop\LAB\序列分割程序+结果\姬蠊py\apart\Anaplecta corneola‘
#filename = r‘C:\Users\aklasim\Desktop\LAB\序列分割程序+结果\姬蠊py\apart\Anaplecta corneola\JFL1.seq‘

all=r‘C:\Users\aklasim\Desktop\LAB\序列分割程序+结果\姬蠊py\part.fas‘
a=open(all,‘w‘)
a.close()


for filename in pathDir:  # 遍历pathDir下的所有文件filename
    t2=filename
    for file in os.listdir(file_path+‘\\‘+filename):
        title = file.strip(‘.seq‘)
        seqpath=file_path+‘\\‘+filename+‘\\‘+file

以下为seq转fas并依次写入

        with open(seqpath, ‘r‘) as f:
            counts = 1
            line = f.readline()
            while line:
                if counts >= 3:
                    break
                line = f.readline()
                counts += 1
            coi=line

        with open(all,‘a‘) as fas:
            fas.write(‘>‘+title+‘_‘+t2+‘\n‘)
            fas.write(coi+‘\n‘)

Python .seq文件批量转.fas 并根据文件夹与文件名重命名

原文:https://www.cnblogs.com/impw/p/15227263.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!