Question: pairwise alignment for multiple sequences in a file
gravatar for biobudhan
2.3 years ago by
biobudhan20 wrote:

I have about 10 protein/DNA sequences in a file in FASTA format and would like to do a pairwise alignment for all possible combinations in this file.


 Seq1 vs Seq2
 Seq1 vs Seq3
 Seq1 vs Seq4 and so on.

Are there tools that can perform this?

alignment fasta pairwise • 1.8k views
ADD COMMENTlink modified 2.3 years ago by • written 2.3 years ago by biobudhan20
gravatar for
2.3 years ago by
Philadelphia, PA wrote:

You can use itertools in python, and pairwise2 from BioPython. Itertools.combinations will create the combinations of sequences you need for each alignment.

#!/usr/bin/env python
import itertools, sys
from Bio import SeqIO, pairwise2

fasta = sys.argv[1]
with open(fasta, 'r') as f:
    seqs = []
    for line in f:
        if not line.startswith('>'):

combos = itertools.combinations(seqs, 2)

for k,v in combos:
    aln = pairwise2.align.localxx(k,v)
    print pairwise2.format_alignment(*aln[0])

Save as; run as python your_fasta_file.fasta

ADD COMMENTlink modified 2.3 years ago • written 2.3 years ago by
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: 2107 users visited in the last hour