Re: [Biopython] How to only extract the best alignment without looping with Bio.Align
Michiel de Hoon <[email protected]> Wed, 14 Aug 2024 12:48:14 +0000 (UTC)
| Newsgroups | gmane.comp.python.bio.general |
|---|---|
| Message-ID | <[email protected]> |
--===============6669561176475457925==
Content-Type: multipart/alternative;
boundary="----=_Part_7633003_1983355846.1723639694851"
------=_Part_7633003_1983355846.1723639694851
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
All alignments returned by the PairwiseAligner have the same score, and th=
ey are all equally good. Same is true for the alignments returned by pairwi=
se2.So you just pick one of the alignments randomly, e.g. the first one:
alignment =3D alignments[0]and then get whatever information you want from =
that alignment. This is essentially the same as what you would get from pai=
rwise2.
Note that the alignments, although they all have the same score, can have d=
ifferent number of gaps, matches, mismatches, so your problem may not be we=
ll-defined.
Best,-Michiel
On Wednesday, August 14, 2024 at 08:36:39 PM GMT+9, Peter Cock <p.j.a.c=
[email protected]> wrote: =20
=20
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 isimport=
ant (i.e. how to tie-break alignments of the same score) and the"best" alig=
nment may differ with usage context.
Looking at the code in the old pairwise2 module, using one_alignment_onlysi=
mply returns the first alignment - it wasn't immediately obvious to me ifth=
at would automatically be one of the=C2=A0 top scoring alignments or not.
As far as I could see, the new PairwiseAligner docstring doesn't explicitly=
comment 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=E2=80=AFAM Slowat <[email protected]> wro=
te:
Hello -=C2=A0
May I ask. I want to align two sequences, and return, for the optimal align=
ment only, the score, number of identities, mismatches, gaps etc.
I can see that this is possible by using the 'one_alignment_only=3DTrue' pa=
rameter 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 align=
ment, 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 ali=
gnment 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 pa=
irwise2 module?
ThanksSlowat_______________________________________________
Biopython mailing list=C2=A0 -=C2=A0 [email protected]
https://mailman.open-bio.org/mailman/listinfo/biopython
_______________________________________________
Biopython mailing list=C2=A0 -=C2=A0 [email protected]
https://mailman.open-bio.org/mailman/listinfo/biopython
=20
------=_Part_7633003_1983355846.1723639694851
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"ydpfc7427deyahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:10px=
;"><div></div>
<div dir=3D"ltr" data-setdir=3D"false">All alignments returned by t=
he PairwiseAligner have the same score, and they are all equally good. Same=
is true for the alignments returned by pairwise2.</div><div dir=3D"ltr" da=
ta-setdir=3D"false">So you just pick one of the alignments randomly, e.g. t=
he first one:<br></div><div dir=3D"ltr" data-setdir=3D"false">alignment =3D=
alignments[0]</div><div dir=3D"ltr" data-setdir=3D"false">and then get wha=
tever information you want from that alignment. This is essentially the sam=
e as what you would get from pairwise2.<br></div><div dir=3D"ltr" data-setd=
ir=3D"false">Note that the alignments, although they all have the same scor=
e, can have different number of gaps, matches, mismatches, so your problem =
may not be well-defined.</div><div dir=3D"ltr" data-setdir=3D"false"><br></=
div><div dir=3D"ltr" data-setdir=3D"false">Best,</div><div dir=3D"ltr" data=
-setdir=3D"false">-Michiel<br></div><div><br></div>
=20
</div><div id=3D"yahoo_quoted_4216137685" class=3D"yahoo_quoted">
<div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
=20
<div>
On Wednesday, August 14, 2024 at 08:36:39 PM GMT+9,=
Peter Cock <[email protected]> wrote:
</div>
<div><br></div>
<div><br></div>
=20
=20
<div><div id=3D"yiv7283132551"><div><div dir=3D"ltr"><div>H=
ello Slowat,</div><div><br clear=3D"none"></div><div>Are you clear that the=
re can be multiple equally scoring "best" alignments?</div><div>This means =
the details of how you sort or rank pairwise alignments is</div><div>import=
ant (i.e. how to tie-break alignments of the same score) and the</div><div>=
"best" alignment may differ with usage context.<br clear=3D"none"></div><di=
v><br clear=3D"none"></div><div>Looking at the code in the old pairwise2 mo=
dule, using one_alignment_only</div><div>simply returns the first alignment=
- it wasn't immediately obvious to me if</div><div>that would automaticall=
y be one of the top scoring alignments or not.<br clear=3D"none"></di=
v><div><br clear=3D"none"></div><div>As far as I could see, the new Pairwis=
eAligner docstring doesn't explicitly</div><div>comment on how the alignmen=
ts returned are sorted either:<br clear=3D"none"></div><div><br clear=3D"no=
ne"></div><div><a rel=3D"nofollow noopener noreferrer" shape=3D"rect" targe=
t=3D"_blank" href=3D"https://github.com/biopython/biopython/blob/biopython-=
184/Bio/Align/__init__.py#L3759">https://github.com/biopython/biopython/blo=
b/biopython-184/Bio/Align/__init__.py#L3759</a></div><div><br clear=3D"none=
"></div><div>This does need clarification, hopefully Markus or Michiel can =
comment.<br clear=3D"none"></div><br clear=3D"none"><div>Peter<br clear=3D"=
none"></div></div><br clear=3D"none"><div class=3D"yiv7283132551gmail_quote=
"><div id=3D"yiv7283132551yqt76453" class=3D"yiv7283132551yqt1714083257"><d=
iv dir=3D"ltr" class=3D"yiv7283132551gmail_attr">On Wed, Aug 14, 2024 at 11=
:46=E2=80=AFAM Slowat <<a rel=3D"nofollow noopener noreferrer" shape=3D"=
rect" ymailto=3D"mailto:[email protected]" target=3D"_blank" href=3D"ma=
ilto:[email protected]">[email protected]</a>> wrote:<br clear=
=3D"none"></div><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1=
px solid rgb(204,204,204);padding-left:1ex;" class=3D"yiv7283132551gmail_qu=
ote"><div dir=3D"ltr">Hello - <div><br clear=3D"none"></div><div>May I=
ask. I want to align two sequences, and return, for the optimal alignment =
only, the score, number of identities, mismatches, gaps etc.</div><div><br =
clear=3D"none"></div><div>I can see that this is possible by using the 'one=
_alignment_only=3DTrue' parameter in the pairwise2 module, however when I l=
oad the pairwise2 module, I get the message that this module is deprecated.=
</div><div><br clear=3D"none"></div><div>Using Bio.Align, I can see how you=
can obtain the .score for the best alignment, but not how to obtain the ot=
her information I require about the best alignment.</div><div><br clear=3D"=
none"></div><div>I don't want to loop through all the possible alignments, =
as this would be prohibitively time-consuming for me. Also, since the .scor=
e of the best alignment can be returned, it makes me think that the best al=
ignment should be saved somewhere and I should be able to see it (even to c=
alculate the gaps, identities and mismatches myself).</div><div><br clear=
=3D"none"></div><div>Could someone explain how to go about this, without us=
ing the deprecated pairwise2 module?</div><div><br clear=3D"none"></div><di=
v>Thanks</div><div>Slowat</div></div>
_______________________________________________<br clear=3D"none">
Biopython mailing list - <a rel=3D"nofollow noopener noreferrer=
" shape=3D"rect" ymailto=3D"mailto:[email protected]" target=3D"_blan=
k" href=3D"mailto:[email protected]">[email protected]</a><br c=
lear=3D"none">
<a rel=3D"nofollow noopener noreferrer" shape=3D"rect" target=3D"_blank" hr=
ef=3D"https://mailman.open-bio.org/mailman/listinfo/biopython">https://mail=
man.open-bio.org/mailman/listinfo/biopython</a><br clear=3D"none">
</blockquote></div></div>
</div></div><div class=3D"yqt1714083257" id=3D"yqt10873">__________________=
_____________________________<br clear=3D"none">Biopython mailing list =
; - <a shape=3D"rect" ymailto=3D"mailto:[email protected]" href=
=3D"mailto:[email protected]">[email protected]</a><br clear=3D=
"none"><a shape=3D"rect" href=3D"https://mailman.open-bio.org/mailman/listi=
nfo/biopython" target=3D"_blank">https://mailman.open-bio.org/mailman/listi=
nfo/biopython</a><br clear=3D"none"></div></div>
</div>
</div></body></html>
------=_Part_7633003_1983355846.1723639694851--
--===============6669561176475457925==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Biopython mailing list - [email protected]
https://mailman.open-bio.org/mailman/listinfo/biopython
--===============6669561176475457925==--