美文网首页
change ID for fasta

change ID for fasta

作者: 生信小白2018 | 来源:发表于2019-08-02 10:30 被阅读0次
    #!/usr/bin/evn python3
    # -*- coding: utf-8 -*-
    __author__='xxx'
    
    import sys, os
    
    def changeID(infile,ID, outfile):
        ini = open(infile, 'r')
        inID = open(ID,'r')
        out = open(outfile, 'w')
    
        rename_db = {}
        for line in inID:
            data = line.strip().split()
            rename_db[data[0]] = data[1]
        
        for i in ini:
            i = i.strip()
            if i.startswith('>'):
                oldID = i[1:]
                #print('>'+newID, file=out)   ##for python3
                print >> out, '>'+rename_db[oldID]       ##for python2
                
            else:
                #print(i, file=out)           ##for python3
                print >> out, i               ##for python2 
    
    if __name__ == '__main__':
        infile = sys.argv[1]
        ID = sys.argv[2]
        outfile = sys.argv[3]
        changeID(infile,ID,outfile)
    
    

    ID 的格式:

    oldID1  newID0001
    oldID2  newID0002
    oldID3  newID0003
    oldID4  newID0004
    oldID5  newID0005
    oldID6  newID0006
    oldID7  newID0007
    

    可以利用rjust格式化字符串的占位

    print str(i).rjust(3,'0')
    

    相关文章

      网友评论

          本文标题:change ID for fasta

          本文链接:https://www.haomeiwen.com/subject/plvkdctx.html