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

时间:2015-02-26 21:48:17

标签: python alignment biopython consensus

我尝试时看起来有个错误:

>>> 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'
希望有人可以帮助我。

干杯,

1 个答案:

答案 0 :(得分:2)

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

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

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