如何解决Biopython SeqIO:AttributeError:'str'对象没有属性'id'
我正在尝试使用 SeqIO 过滤掉序列,但出现此错误。
Traceback (most recent call last):
File "paralog_warning_filter.py",line 61,in <module>
.
.
.
SeqIO.write(desired_proteins,"filtered.fasta","fasta")
AttributeError: 'str' object has no attribute 'id'
我检查了其他类似的问题,但仍然无法理解我的脚本有什么问题。
这是我正在尝试的脚本的相关部分:
fh=open('lineageV_paralog_warning_genes.fasta')
for s_record in SeqIO.parse(fh,'fasta'):
name = s_record.id
seq = s_record.seq
for i in paralogs_in_all:
if name.endswith(i):
desired_proteins=seq
output_file=SeqIO.write(desired_proteins,"fasta")
output_file
fh.close()
我有一个单独的 paralagos_in_all
列表,那就是 ID 源。当我尝试打印 name
时,它返回一个正确的字符串 ID 名称,格式为 >coronopifolia_tair_real-AT2G35040.1@10
。
你能帮我理解我的问题吗?提前致谢。
解决方法
尝试告诉我们(无法测试您的代码):
from Bio.SeqRecord import SeqRecord
from Bio import SeqIO
......
.......
desired_proteins = []
fh=open('lineageV_paralog_warning_genes.fasta')
for s_record in SeqIO.parse(fh,'fasta'):
name = s_record.id
seq = s_record.seq
for i in paralogs_in_all:
if name.endswith(i):
# desired_proteins=SeqRecord( Seq(seq),id=name) ### here seq is already a Seq object see below
desired_proteins.append(SeqRecord( seq,id=name,description="")) # description='' removes the <unknown description> that otherwise would be present
output_file=SeqIO.write(desired_proteins,"filtered.fasta","fasta") ## don't know how to have SeqIO.write to append to file instead of re-writing all of it
fh.close()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。