Record the first python script in your life

Function: Change the line starting with ">" in A_pep.fa to ">sp._id@sequence_id"

#!/usr/bin/python
# -*- coding: UTF-8 -*-

list=['A','B','C','D','E','F']
for name in list:
    filename = name+"_pep.fa"
    outname = name+"_pep_shroten.fa"
    infile = open(filename,"r")
    outfile = open(outname,"w")
    for line in infile:
            if line[0] == ">":
                newid = (line.split(" ")[0]).split(">")[1]
                outfile.write(">"+name+"@"+newid)
            else: outfile.write(line)
    infile.close()
    outfile.close()

Guess you like

Origin blog.csdn.net/mushroom234/article/details/113102604
Recommended