Biopython+File IO operation - TypeError: expected a character buffer object

Biopython+File IO operation - TypeError: expected a character buffer object

我尝试使用 Biopython 读取一个 FASTA 文件,然后在对序列进行实际处理之前将其再次写入另一个文件。

w.write('Length of the Ref Seq: '+ ref_seq + ' is '+ str(len(ref_seq))+'\n')

类型错误:需要一个字符缓冲区对象

我遇到了上面提到的错误。有人可以帮助我理解错误吗?

谢谢。

下面的代码解决了问题

from Bio import SeqIO
in_file = open("input.fasta")
records = SeqIO.parse(in_file, format="fasta")
out_file = open("output.txt", "w")
for mySeq in records:
  out_file.write('Length of the Ref Seq: '+ str(mySeq.seq) + 
                 ' is '+ str(len(mySeq.seq))+'\n')

out_file.close()

input.fasta:

>165613

TAACTGCAGTGTTTTGTGTCGAGC

>165875

GGGATCTTCGGACCTCGT

你得到以下输出

Length of the Ref Seq: TAACTGCAGTGTTTTGTGTCGAGC is 24

Length of the Ref Seq: GGGATCTTCGGACCTCGT is 18