Question: using python for pairwise alignment
gravatar for jellevandewege
6.5 years ago by
jellevandewege90 wrote:


I'm writing a Python program and I have to do a pairwise alignment on several thousand DNA sequences. I looked at Biopython but I couldn't fine a function to do a pairwise alignment, this may be my mistake. The function should have gap penalty, gap open, gap extension and Smith Waterman or Needleman Wunsch. Can anyone tell me where I can find a good Python package for doing this kind of alignment? 

thanks in advance

pairwise alignment python • 17k views
ADD COMMENTlink modified 6.5 years ago by João Rodrigues2.5k • written 6.5 years ago by jellevandewege90 may be of some help

ADD REPLYlink modified 10 months ago by _r_am31k • written 6.5 years ago by ancient_learner630
gravatar for João Rodrigues
6.5 years ago by
João Rodrigues2.5k
Stanford University, U
João Rodrigues2.5k wrote:


BioPython does exactly what you are asking, you probably looked in the wrong place :) You should look at the Bio.pairwise2 module. See the following example for global pairwise alignment:

from Bio import pairwise2
from Bio.SubsMat import MatrixInfo as matlist

matrix = matlist.blosum62

gap_open = -10
gap_extend = -0.5

# Only using the first 60 aas for visualization reasons..


alns = pairwise2.align.globalds(p53_human, p53_mouse, matrix, gap_open, gap_extend)
top_aln = alns[0]
aln_human, aln_mouse, score, begin, end = top_aln
print aln_human+'\n'+aln_mouse


# Comparing with EBI NEEDLE output
ADD COMMENTlink modified 10 months ago by _r_am31k • written 6.5 years ago by João Rodrigues2.5k
gravatar for Mahmoud Mabrouk
6.5 years ago by
Germany / Berlin / Technische Universitaet Berlin
Mahmoud Mabrouk0 wrote:

Hi jellevandewege,

You can use the Bio.Emboss python package for Needleman Wunsch alignment (It is essentially a wrapper around the program).

Here is a short example copied from my code base:

from Bio.Emboss.Applications import NeedleCommandline
from Bio import AlignIO

needle_cli = NeedleCommandline(asequence=seq_fname1, \
                               bsequence=seq_fname2, \
                               gapopen=10, \
                               gapextend=0.5, \

"""This generates the needle file"""
"""That parses the needle file, aln[0] and aln[1] contain the aligned
first and second sequence in the usual format (e.g. - for a gap)"""
aln =, "emboss")


ADD COMMENTlink modified 10 months ago by _r_am31k • written 6.5 years ago by Mahmoud Mabrouk0

is it possible to perform pairwise sequence alignment sequence 1:target sequence sequence 2: sequence extract from NCBI PDB based on PDB id like 1mkp

ADD REPLYlink written 7 months ago by geethus20090
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 951 users visited in the last hour