This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error with biopython pairwise aligner

I try to use the pairwise aligner provided by biopython. But I fail to get the examples working. When I execute the following code:

>>> from Bio import Align
>>> aligner = Align.PairwiseAligner()

The second lines returns the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PairwiseAligner'

I run with Python 2.7.15 and Biopython 1.71

Thank you

biopython

Python 2.7.15

Why? You should move to Python3. I'm facing the same problem with both py2.7.15 and py3+, so I don't know what the problem is.

a = Align.PairwiseAlignment()

doesn't work either.

it has not the same functionality

1 answer

The Align submodule doesn't appear to contain any such class/function (testing with Py2.7 and Py3) with BioPython 1.70/1.71, though it does appear that there should be such an object according to the docs: https://biopython.org/DIST/docs/api/Bio.Align.PairwiseAlignment-class.html

>>> from Bio import Align
>>> Align.
Align.Alphabet               Align.__delattr__(           Align.__getattribute__(      Align.__package__            Align.__setattr__(
Align.MultipleSeqAlignment(  Align.__dict__               Align.__hash__(              Align.__path__               Align.__sizeof__(
Align.Seq(                   Align.__doc__                Align.__init__(              Align.__reduce__(            Align.__str__(
Align.SeqRecord(             Align.__file__               Align.__name__               Align.__reduce_ex__(         Align.__subclasshook__(
Align.__class__(             Align.__format__(            Align.__new__(               Align.__repr__(              Align.print_function

As Eric suggested, what you might want is Bio.pairwise2.

Under biopython 1.72, the very latest version in conda, the objects exist. I at least get an error that appears sensible!

>>> import Bio
>>> from Bio import Align
>>> Bio.__version__
'1.72'
>>> Align.
Align.Alphabet               Align.SeqRecord(             Align.__file__               Align.__new__(               Align.__setattr__(           Align.sys
Align.MultipleSeqAlignment(  Align._RestrictedDict(       Align.__format__(            Align.__package__            Align.__sizeof__(
Align.PairwiseAligner(       Align.__class__(             Align.__getattribute__(      Align.__path__               Align.__str__(
Align.PairwiseAlignment(     Align.__delattr__(           Align.__hash__(              Align.__reduce__(            Align.__subclasshook__(
Align.PairwiseAlignments(    Align.__dict__               Align.__init__(              Align.__reduce_ex__(         Align._aligners
Align.Seq(                   Align.__doc__                Align.__name__               Align.__repr__(              Align.print_function
>>> a = Align.PairwiseAlignment()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes exactly 5 arguments (1 given)

And PairwiseAligner doen't throw any errors when assigned to variable:

>>> aligner = Align.PairwiseAligner()
>>> aligner
Pairwise aligner, implementing the Needleman-Wunsch, Smith-Waterman, Gotoh, and Waterman-Smith-Beyer global and local alignment algorithms
>>>

In short, I would suggest updating to the bleeding edge version, 1.72. If you're using conda this is fairly straightforward:

conda install -c anaconda biopython

Log in to answer this question.