【问题标题】:Write SeqIO Dictionary as Fasta File将 SeqIO 字典写为 Fasta 文件
【发布时间】:2017-10-27 20:11:49
【问题描述】:

我最初将我的 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 函数所期望的输入。

【问题讨论】:

    标签: python dictionary biopython fasta


    【解决方案1】:

    我解决了这个问题。即使使用 SeqIO.to_dict 转换,字典的值也是原始生成器类。要将此字典写回 Fasta,只需调用字典的值即可。

    with open("example.fasta", "w") as handle:
        SeqIO.write(test.values(), handle, "fasta") 
    

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 2014-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 2016-08-26
      • 1970-01-01
      相关资源
      最近更新 更多