我正在尝试使用 Bio 和 SeqIO 打开包含多个序列的 FASTA 文件,编辑序列名称以删除所有名称末尾的“.seq”(>SeqID20.seq 应变为>SeqID20),然后将所有序列写入新的 FASTA 文件,但出现以下错误
AttributeError: 'str' object has no attribute 'id'
这就是我开始的:
with open ('lots_of_fasta_in_file.fasta') as f:
for seq_record in SeqIO.parse(f, 'fasta'):
name, sequence = seq_record.id, str(seq_record.seq)
pair = [name.replace('.seq',''), sequence]
SeqIO.write(pair, "new.fasta", "fasta")
但我也尝试过这个并得到同样的错误:
file_in ='lots_of_fasta_in_file.fasta'
file_out='new.fasta'
with open(file_out, 'w') as f_out:
with open(file_in, 'r') as f_in:
for seq_record in SeqIO.parse(f_in, 'fasta'):
name, sequence = seq_record.id, str(seq_record.seq)
# remove .seq from ID and add features
pair = [name.replace('.seq',''), sequence]
SeqIO.write(pair, file_out, 'fasta')
我假设我在从列表“对”写入新文件时犯了一些错误,但我不确定要更改什么。任何帮助,将不胜感激!