当我尝试使用 biopython 获取共识序列时,我得到一个 AttributeError

When I try to get the consensus sequences with biopython I get an AttributeError

看起来我在尝试时遇到了一个错误:

>>> from Bio.Align import AlignInfo
>>> summary_align = AlignInfo.SummaryInfo('/home/ivan/Elasmo only')
>>> consensus = summary_align.dumb_consensus()
Traceback (most recent call last):
  File "<pyshell#148>", line 1, in <module>
    consensus = summary_align.dumb_consensus()
  File "/usr/local/lib/python2.7/dist-packages/Bio/Align/AlignInfo.py", line 76, in dumb_consensus
    con_len = self.alignment.get_alignment_length()
AttributeError: 'str' object has no attribute 'get_alignment_length'

希望有人能帮助我。

干杯,

您使用字符串而不是 Alignment 实例化了 SummaryInfo class 对象。

您正尝试在字符串上调用 .dumb_consensus(),但此方法仅在您使用 Alignment 而非字符串实例化 SummaryInfo class 时才有效。

http://biopython.org/DIST/docs/api/Bio.Align.Generic.Alignment-class.html#get_alignment_length

试试这个:

# Make an example alignment object
>>> from Bio.Align.Generic import Alignment
>>> from Bio.Alphabet import IUPAC, Gapped
>>> align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))
>>> align.add_sequence("Alpha", "ACTGCTAGCTAG")
>>> align.add_sequence("Beta",  "ACT-CTAGCTAG")
>>> align.add_sequence("Gamma", "ACTGCTAGATAG")

# Instantiate SummaryInfo class and pass 'align' to it.

>>> from Bio.Align import AlignInfo
>>> summary_align = AlignInfo.SummaryInfo(align)
>>> consensus = summary_align.dumb_consensus()

请注意,Alignment 对象似乎正在贬值,因此您可以考虑使用 MultipleSeqAlignment