直接上代码:
import re
fr=open("test2.fasta",'r')
fw=open("out.fasta",'a+')
count=0
for line in fr:
count=count+1
if count<1001:
if line.startswith(">"):
line=line.strip('\n')# 读文件不换行
seq=line+'|training'
print(seq)
fw.write(seq+"\n")# 写文件换行
else:
fw.write(line)
else:
if line.startswith(">"):
line=line.strip('\n')
seq=line+'|testing'
print(seq)
fw.write(seq+"\n")
else:
fw.write(line)
fr.close()
fw.close()