Question: Count how many gaps and mismatches using pairwise2 alignment
gravatar for bethpearson98
10 months ago by
bethpearson980 wrote:

I am doing a local alignment using pairwise2. I currently have some code that will count how many matches there are but I am trying to also count how many gaps and mismatches there are in the alignment too. Is there any way to do this? If possible I'd like the gaps and mismatches counted separately form each other and the position of the gaps/mismatches in the sequence would be super helpful.

sequence alignment • 578 views
ADD COMMENTlink modified 8 months ago by Biostar ♦♦ 20 • written 10 months ago by bethpearson980

Could you please share what you've tried and what is your code ?

I assume you took python module pairwise2

You can take a look at the format_alignment function and rewrite your own, something like this

def my_format_alignment(align1, align2, score, begin, end): 
    s = [] 
    s.append("%s\n" % align1) 
    s.append(" " * begin) 
    for a, b in zip(align1[begin:end], align2[begin:end]): 
        if a == b: 
            s.append("|")  # match 
        elif a == "-" or b == "-": 
            s.append(" ")  # gap
            s.append(".")  # mismatch 
    s.append("%s\n" % align2) 
    s.append("  Score=%g\n" % score)
    s.append("  Gap=%g\n" % gap)
    s.append("  Mismatch=%g\n" % mismatch)
    return ''.join(s) 

from Bio import pairwise2
alignments = pairwise2.align.globalxx("ACCGT", "ACG")
from Bio.pairwise2 import format_alignment
#| || 
#  Score=3
#| || 
#  Score=3
#  Gap=2
#  Mismatch=0
ADD REPLYlink modified 10 months ago • written 10 months ago by Bastien HervĂ©4.5k
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: 924 users visited in the last hour