zoukankan      html  css  js  c++  java
  • 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+'
    ')
    
  • 相关阅读:
    Python_反射
    Python_面向对象_类2
    Python_面向对象_类1
    Python_logging模块
    Python_子进程管理subprocess模块
    Python_python内置加密模块
    Python_configparser模块
    Python_xml
    Python_shelve模块
    Python_shutil模块
  • 原文地址:https://www.cnblogs.com/impw/p/15227263.html
Copyright © 2011-2022 走看看