最初,我将fasta序列转换为带有Bio.SeqIO.to_dict语句的字典。我想把一本副词字典写回fasta文件。
Test是一个python字典,其中fasta头作为键,序列作为索引。
我的代码试图利用SeqIO.write:
with open("example.fasta", "w") as handle:
SeqIO.write(test, handle, "fasta")
AttributeError: 'str' object has no attribute 'id'
我担心,通过将SeqIO生成器对象转换为字典,我无法轻松返回到其他SeqIO函数所期望的输入。
发布于 2017-10-27 12:58:32
我解决了这个问题。即使使用SeqIO.to_dict转换,字典的值也是原始生成器类。要将此字典写回Fasta,只需调用字典的值即可。
with open("example.fasta", "w") as handle:
SeqIO.write(test.values(), handle, "fasta")
https://stackoverflow.com/questions/46982713
复制