Ivan Castro
Ivan Castro

Reputation: 615

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

Looks like I got a bug when I try:

>>> 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'

Hope somebody can help me.

Cheers,

Upvotes: 0

Views: 3295

Answers (1)

Malonge
Malonge

Reputation: 2040

You instantiated the SummaryInfo class with a string not an Alignment object.

You are trying to call .dumb_consensus() on a string, but this method will only work if you instantiate the SummaryInfo class with an Alignment, not a string.

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

try this:

# 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()

Just as a note, it looks like the Alignment object is becoming depreciated so you may look into using MultipleSeqAlignment.

Upvotes: 2

Related Questions