We have thus far worked with local alignments with a linear gap penalty and global alignments with affine gap penalties (see "Local alignment with scoring matrix1" and "Global alignment with scoring matrix and affine gap penalty2").
It is only natural to take the intersection of these two problems and
find an optimal local alignment given an affine gap penalty.
Write a function localAlignmentScore that takes two protein strings $$s$$ and $$t$$. The function must return the maximum local alignment score of $$s$$ and $$t$$. To align the two given DNA strings, the function must use the BLOSUM62 scoring matrix, a gap open penalty equal to 11 and a gap extension penalty equal to 1.
Write a function localAlignment that takes two protein strings $$s$$ and $$t$$. The function must return a tuple containing two substrings $$r$$ and $$u$$ of $$s$$ and $$t$$, respectively, that correspond to an optimal local alignment of $$s$$ and $$t$$. To align the two given DNA strings, the function must use the BLOSUM62 scoring matrix, a gap open penalty equal to 11 and a gap extension penalty equal to 1. If multiple optimal alignments exist, the function may return any one.
In the following interactive session, we assume the FASTA file data.faa3 to be located in the current directory.
>>> from Bio import SeqIO >>> localAlignmentScore('PLEASANTLY', 'MEANLY') 12 >>> localAlignmentScore(*SeqIO.parse('data.faa', 'fasta')) 230 >>> localAlignment('PLEASANTLY', 'MEANLY') ('LEAS', 'MEAN') >>> localAlignment(*SeqIO.parse('data.faa', 'fasta')) ('IGSWGACF-------IH-SFRNRG---CILY-----HIGY------SAIQCT-----AFFMGP-------YKDSLNN---------GISDTWD-----RMSRQY--TC--PAHKFG-------MF---AQEDG---FSNHG---HLVY----NSKL---QLDHQELT---IYMH-PC-HN---TFRNLNIIV-------ERFALIQNFNI---------KC-QGID-PN-YPHEA', 'IGSWGACSDKNFILQIHASFIRRGNQNCSIWLDYYCHIGYLGSDAASPIQCKWSTTIAFFMGKPQGSNIYYKDSLNECSNMSGILISVCDTWDMRMQSRAARQYYTECLGPAHKHDKAEFPGCMFICCAQEDYDYYFSNHGPIFHLVEYVLNQSKLHKRQLDHQEMSLTQIYMHFPCMHNDTYTFRNLRNVISIHVYDNERFALDLNFNICITINLVHVKCVQGIDHPNIYPHEA')