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)?
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 ;)
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)
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...
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.
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 ;)