Biopython PairwiseAligner sorting on scores
1
0
Entering edit mode
4.2 years ago

Hi alll,

I am using the PairwiseAligner of the Biopython package to align two sequences. Now the aligner gives me multiple possible alignments if I understand this correctly (not sure about this though).

How do I sort these alignments based on their scoring (or are they already sorted automatically on their scoring)?

In the following example they use sorted(alignments) to sort the alignments on alphabetical order, why and when would sorting on alphabetical order be useful over sorting on scores? https://biopython.org/DIST/docs/api/Bio.Align.PairwiseAligner-class.html

Hope you can help me out with this question.

Cheers, Stefan

Biopython alignment sequence score • 4.4k views
ADD COMMENT
0
Entering edit mode

The reason sorted(alignments) is alphabetical, is because the result is an object containing the scores and alignment information, not just a numerical score.

If you were the computer and I gave you a list of (stringA, stringB, 235, 90) and (stringC, stringD, 264, 99). Which would you put first, given no instruction on which field to sort ;)

ADD REPLY
0
Entering edit mode
4.2 years ago
zorbax ▴ 610

There is only one score value per alignment with Align.PairwiseAligner() in this example.

from Bio import Align
aligner = Align.PairwiseAligner()

s = 'ATGGTCGGCTAGCTGGATGCGTA'
t = 'AGTCATCGGCTAGTCTGGATGCCCA'

score = aligner.score(s, t)

alignments = aligner.align(s, t)

# it's an unique value 
print(score)

aligner.match_score = 1.0 
aligner.mismatch_score = -2.0
aligner.gap_score = -2.5

# for all the alignments
print(*alignments, sep='\n')

for align in sorted(alignments):
    print("Score = %.1f:" % align.score)
    print(align)

Check the documentation about the 6.5.2.3 Substitution scores

ADD COMMENT
0
Entering edit mode

@zorbax,

Thanks! But then how does a single score represent/relate to all the possible alignments in for align in sorted(alignments):? I can image some alignments are worse compared to others...

ADD REPLY
0
Entering edit mode

Align.PairwiseAligner() implements the Needleman-Wunsch, Smith-Waterman, Gotoh, and Waterman-Smith-Beyer global and local pairwise alignment algorithms to find the best-scoring between two sequences. The PairwiseAligner object automatically chooses the appropriate alignment algorithm. You can try a different penalization score to get better results and different scores.

ADD REPLY

Login before adding your answer.

Traffic: 1672 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