您正在分配一个字符串,其中需要一个Bio.Seq
对象。对我来说,这有效:
from Bio import Seq
from Bio import SeqIO
my_entries = list(SeqIO.parse('my_file.gb', 'genbank'))
my_entry = my_entries[0]
# Make a new Seq object and assing to my_entry.seq. 'TTT' is just an example sequence
my_entry.seq = Seq.Seq('TTT', my_entry.seq.alphabet)
# Write back to file
SeqIO.write(my_entries, 'my_updated_file.gb', 'genbank')
如果您的 Genbank 文件只有一个条目,您可以考虑使用SeqIO.read
:
my_entry = SeqIO.read('my_file.gb', 'genbank')
my_entry.seq = Seq.Seq('TTT', my_entry.seq.alphabet)
SeqIO.write(my_entry, 'my_updated_file.gb', 'genbank')
或者,您可以直接将序列转换为可变序列并直接对其进行操作:
from Bio import SeqIO
my_entry = list(SeqIO.parse('my_file.gb', 'genbank'))[0]
my_entry.seq = my_entry.seq.tomutable()
my_entry.seq[0] = 'T' # Remember that Genbank position 1 is 0 in seq
my_entry.seq[1] = 'C'
....
SeqIO.write(my_entry, 'my_updated_file.gb', 'genbank')