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

import os
file_path=r'C:UsersaklasimDesktopLAB序列分割程序+结果姬蠊pypart'
pathDir = os.listdir(file_path)

#folder=r'C:UsersaklasimDesktopLAB序列分割程序+结果姬蠊pyapartAnaplecta corneola'
#filename = r'C:UsersaklasimDesktopLAB序列分割程序+结果姬蠊pyapartAnaplecta corneolaJFL1.seq'

all=r'C:UsersaklasimDesktopLAB序列分割程序+结果姬蠊pypart.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+'
')
            fas.write(coi+'
')
原文地址:https://www.cnblogs.com/impw/p/15227263.html