Custom substitution matrix in biopython pairwise2 aligner
1
1
Entering edit mode
4.0 years ago

Is there a way to use custom matrix for nucleotide aligner in Biopython pairwise2 module? I want to decrease penalties for A->G, C->T substitutions.

import Bio
from Bio import pairwise2

seq1='AGTCGATCATCGGA'
seq2='ATTAGATCATCGGGGA'

alignment = pairwise2.align.localms(seq1, seq2, 2,-1,-2,-1,one_alignment_only=True)
print(format_alignment(*alignment[0]))

AGTCGATCATCGGA--
|.|.|||||||||
ATTAGATCATCGGGGA
  Score=20
Biopython pairwise2 alignment • 2.2k views
ADD COMMENT
3
Entering edit mode
4.0 years ago
tamerg ▴ 100

how about trying somethig like this

import Bio
from Bio import pairwise2
from Bio.pairwise2 import format_alignment

seq1 = 'AGTCGATCATCGGA'
seq2 = 'ATTAGATCATCGGGGA'


match_dic = {}
match_dic[('A', 'A')] = 2
match_dic[('A', 'C')] = -1
match_dic[('A', 'T')] = -1
match_dic[('A', 'G')] = 1
match_dic[('C', 'A')] = -1
match_dic[('C', 'C')] = 2
match_dic[('C', 'T')] = 1
match_dic[('C', 'G')] = -1
match_dic[('G', 'A')] = -1
match_dic[('G', 'C')] = -1
match_dic[('G', 'T')] = -1
match_dic[('G', 'G')] = 2
match_dic[('T', 'A')] = -1
match_dic[('T', 'C')] = -1
match_dic[('T', 'T')] = 2
match_dic[('T', 'G')] = -1

alignment = pairwise2.align.localds(
    seq1, seq2, match_dic, -2, -1, one_alignment_only=True)
print(alignment[0])
print(format_alignment(*alignment[0]))
ADD COMMENT
0
Entering edit mode

Yes! Thank you very much!

ADD REPLY

Login before adding your answer.

Traffic: 1705 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6