下面是将文件 split__1.fasta中选取一段序列,如下421至480. 存于selected_split_1.fasta文件中__。
如何写一个循环,可以从split__1.fasta 至 split__68.fasta,中分别选取421至480. 并存于selected_split_1.fasta至selected_split_68.fasta文件中文件中
from Bio import SeqIO
fin = open('split_1.fasta', 'r')
fout = open('selected_split_1.fasta', 'w')
with open("selected_split_1.fasta","w") as f:
for seq_record in SeqIO.parse("split_1.fasta", "fasta"):
f.write(">")
f.write(str(seq_record.id) + "\n")
f.write(str(seq_record.seq[421:480]) + "\n") #start 421 to end 480 base positions
fin.close()
fout.close()