[Biopython] How to only extract the best alignment without looping with Bio.Align
Michiel de Hoon
mjldehoon at yahoo.com
Wed Aug 14 08:48:14 EDT 2024
All alignments returned by the PairwiseAligner have the same score, and they are all equally good. Same is true for the alignments returned by pairwise2.So you just pick one of the alignments randomly, e.g. the first one:
alignment = alignments[0]and then get whatever information you want from that alignment. This is essentially the same as what you would get from pairwise2.
Note that the alignments, although they all have the same score, can have different number of gaps, matches, mismatches, so your problem may not be well-defined.
Best,-Michiel
On Wednesday, August 14, 2024 at 08:36:39 PM GMT+9, Peter Cock <p.j.a.cock at googlemail.com> wrote:
Hello Slowat,
Are you clear that there can be multiple equally scoring "best" alignments?This means the details of how you sort or rank pairwise alignments isimportant (i.e. how to tie-break alignments of the same score) and the"best" alignment may differ with usage context.
Looking at the code in the old pairwise2 module, using one_alignment_onlysimply returns the first alignment - it wasn't immediately obvious to me ifthat would automatically be one of the top scoring alignments or not.
As far as I could see, the new PairwiseAligner docstring doesn't explicitlycomment on how the alignments returned are sorted either:
https://github.com/biopython/biopython/blob/biopython-184/Bio/Align/__init__.py#L3759
This does need clarification, hopefully Markus or Michiel can comment.
Peter
On Wed, Aug 14, 2024 at 11:46 AM Slowat <slowat0kela at gmail.com> wrote:
Hello -
May I ask. I want to align two sequences, and return, for the optimal alignment only, the score, number of identities, mismatches, gaps etc.
I can see that this is possible by using the 'one_alignment_only=True' parameter in the pairwise2 module, however when I load the pairwise2 module, I get the message that this module is deprecated.
Using Bio.Align, I can see how you can obtain the .score for the best alignment, but not how to obtain the other information I require about the best alignment.
I don't want to loop through all the possible alignments, as this would be prohibitively time-consuming for me. Also, since the .score of the best alignment can be returned, it makes me think that the best alignment should be saved somewhere and I should be able to see it (even to calculate the gaps, identities and mismatches myself).
Could someone explain how to go about this, without using the deprecated pairwise2 module?
ThanksSlowat_______________________________________________
Biopython mailing list - Biopython at biopython.org
https://mailman.open-bio.org/mailman/listinfo/biopython
_______________________________________________
Biopython mailing list - Biopython at biopython.org
https://mailman.open-bio.org/mailman/listinfo/biopython
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20240814/f8873430/attachment-0001.htm>
More information about the Biopython
mailing list