我正在尝试应用biopython代码来分割大型fasta文件。代码如上:
def batch_iterator():
entry=True # to make sure the loop run once
while entry:
batch=[]
while len(batch) < batch_size:
try:
entry=iterator.next()
except StopIteration:
entry=None
if entry is None:
#end of file
break
batch.append(entry)
if batch:
yield batch
record_iter=SeqIO.parse(open('/home/to/file/sorted_sequence.fa', 'fasta')
for i, batch in enumerate (batch_iterator(record_iter, 93)):
filename='gene_%i.fasta' % (i + 1)
with open('/home/path/files/', filename, 'w') as ouput_handle:
count=SeqIO.write(batch, ouput_handle, 'fasta')
print ('Wrote %i records to %s' % (count, filename))
在这一行: 对于i,枚举中的批处理(batch_iterator(record_iter,93)):给了我 SyntaxError:语法无效。但我看不出错误,有人能帮我找到它吗,拜托? 我从这个http://biopython.org/wiki/Split_large_file中获取了代码 感谢。
答案 0 :(得分:2)
此行中缺少括号
record_iter = SeqIO.parse(open('/home/to/file/sorted_sequence.fa', 'fasta')
尝试添加一个
record_iter = SeqIO.parse(open('/home/to/file/sorted_sequence.fa'), 'fasta')