Re: [Biopython] How to only extract the best alignment without looping with Bio.Align
Peter Cock <[email protected]> Wed, 14 Aug 2024 13:55:55 +0100
| Newsgroups | gmane.comp.python.bio.general |
|---|---|
| Message-ID | <CAKVJ-_7g7tT5e1qt5yUjfrVPiVG9dTn8pxLyk1BEhB38iJMK-Q@mail.gmail.com> |
--===============0847370696558973119== Content-Type: multipart/alternative; boundary="000000000000d45fdb061fa43f2a" --000000000000d45fdb061fa43f2a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Oh good. We can probably add a line to the new pairwise aligner docstring saying that then - e.g. "All the alignments returned will have the same score, but differ in the number of gaps, matches and mismatches, and are listed in an unspecified order." Peter On Wed, Aug 14, 2024 at 1:48=E2=80=AFPM Michiel de Hoon <[email protected]= m> wrote: > 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 =3D 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 < > [email protected]> wrote: > > > Hello Slowat, > > Are you clear that there can be multiple equally scoring "best" alignment= s? > This means the details of how you sort or rank pairwise alignments is > important (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_only > simply returns the first alignment - it wasn't immediately obvious to me = if > that would automatically be one of the top scoring alignments or not. > > As far as I could see, the new PairwiseAligner docstring doesn't explicit= ly > comment on how the alignments returned are sorted either: > > > https://github.com/biopython/biopython/blob/biopython-184/Bio/Align/__ini= t__.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]> w= rote: > > 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=3DTrue' > 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 th= e > best alignment. > > I don't want to loop through all the possible alignments, as this would b= e > prohibitively time-consuming for me. Also, since the .score of the best > alignment can be returned, it makes me think that the best alignment shou= ld > 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? > > Thanks > Slowat > _______________________________________________ > Biopython mailing list - [email protected] > https://mailman.open-bio.org/mailman/listinfo/biopython > > _______________________________________________ > Biopython mailing list - [email protected] > https://mailman.open-bio.org/mailman/listinfo/biopython > --000000000000d45fdb061fa43f2a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Oh good. We can probably add a line to the new pairwi= se aligner docstring</div><div>saying that then - e.g.</div><div><br></div>= <div>"All the alignments returned will have the same score, but differ= in the number</div><div>of gaps, matches and mismatches, and are listed in= an unspecified order."<br></div><div><br></div><div>Peter<br></div></= div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On= Wed, Aug 14, 2024 at 1:48=E2=80=AFPM Michiel de Hoon <<a href=3D"mailto= :[email protected]">[email protected]</a>> wrote:<br></div><blockquo= te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px = solid rgb(204,204,204);padding-left:1ex"><div><div style=3D"font-family:Hel= vetica Neue,Helvetica,Arial,sans-serif;font-size:10px"><div></div> <div dir=3D"ltr">All alignments returned by the PairwiseAligner hav= e the same score, and they are all equally good. Same is true for the align= ments returned by pairwise2.</div><div dir=3D"ltr">So you just pick one of = the alignments randomly, e.g. the first one:<br></div><div dir=3D"ltr">alig= nment =3D alignments[0]</div><div dir=3D"ltr">and then get whatever informa= tion you want from that alignment. This is essentially the same as what you= would get from pairwise2.<br></div><div dir=3D"ltr">Note that the alignmen= ts, although they all have the same score, can have different number of gap= s, matches, mismatches, so your problem may not be well-defined.</div><div = dir=3D"ltr"><br></div><div dir=3D"ltr">Best,</div><div dir=3D"ltr">-Michiel= <br></div><div><br></div> =20 </div><div id=3D"m_1025144524552420169yahoo_quoted_4216137685"> <div style=3D"font-family:"Helvetica Neue",Helvetica,= Arial,sans-serif;font-size:13px;color:rgb(38,40,42)"> =20 <div> On Wednesday, August 14, 2024 at 08:36:39 PM GMT+9,= Peter Cock <<a href=3D"mailto:[email protected]" target=3D"_bla= nk">[email protected]</a>> wrote: </div> <div><br></div> <div><br></div> =20 =20 <div><div id=3D"m_1025144524552420169yiv7283132551"><div><d= iv dir=3D"ltr"><div>Hello Slowat,</div><div><br clear=3D"none"></div><div>A= re you clear that there can be multiple equally scoring "best" al= ignments?</div><div>This means the details of how you sort or rank pairwise= alignments is</div><div>important (i.e. how to tie-break alignments of the= same score) and the</div><div>"best" alignment may differ with u= sage context.<br clear=3D"none"></div><div><br clear=3D"none"></div><div>Lo= oking at the code in the old pairwise2 module, using one_alignment_only</di= v><div>simply returns the first alignment - it wasn't immediately obvio= us to me if</div><div>that would automatically be one of the=C2=A0 top scor= ing alignments or not.<br clear=3D"none"></div><div><br clear=3D"none"></di= v><div>As far as I could see, the new PairwiseAligner docstring doesn't= explicitly</div><div>comment on how the alignments returned are sorted eit= her:<br clear=3D"none"></div><div><br clear=3D"none"></div><div><a rel=3D"n= ofollow noopener noreferrer" shape=3D"rect" href=3D"https://github.com/biop= ython/biopython/blob/biopython-184/Bio/Align/__init__.py#L3759" target=3D"_= blank">https://github.com/biopython/biopython/blob/biopython-184/Bio/Align/= __init__.py#L3759</a></div><div><br clear=3D"none"></div><div>This does nee= d 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 clea= r=3D"none"><div><div id=3D"m_1025144524552420169yiv7283132551yqt76453"><div= dir=3D"ltr">On Wed, Aug 14, 2024 at 11:46=E2=80=AFAM Slowat <<a rel=3D"= nofollow noopener noreferrer" shape=3D"rect" href=3D"mailto:slowat0kela@gma= il.com" target=3D"_blank">[email protected]</a>> wrote:<br clear=3D"= none"></div><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s= olid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Hello -=C2=A0<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, m= ismatches, gaps etc.</div><div><br clear=3D"none"></div><div>I can see that= this is possible by using the 'one_alignment_only=3DTrue' paramete= r in the pairwise2 module, however when I load 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 b= est alignment, but not how to obtain the other information I require about = the best alignment.</div><div><br clear=3D"none"></div><div>I don't wan= t to loop through all the possible alignments, as this would be prohibitive= ly 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 some= where and I should be able to see it (even to calculate the gaps, identitie= s and mismatches myself).</div><div><br clear=3D"none"></div><div>Could som= eone explain how to go about this, without using the deprecated pairwise2 m= odule?</div><div><br clear=3D"none"></div><div>Thanks</div><div>Slowat</div= ></div> _______________________________________________<br clear=3D"none"> Biopython mailing list=C2=A0 -=C2=A0 <a rel=3D"nofollow noopener noreferrer= " shape=3D"rect" href=3D"mailto:[email protected]" target=3D"_blank">= [email protected]</a><br clear=3D"none"> <a rel=3D"nofollow noopener noreferrer" shape=3D"rect" href=3D"https://mail= man.open-bio.org/mailman/listinfo/biopython" target=3D"_blank">https://mail= man.open-bio.org/mailman/listinfo/biopython</a><br clear=3D"none"> </blockquote></div></div> </div></div><div id=3D"m_1025144524552420169yqt10873">_____________________= __________________________<br clear=3D"none">Biopython mailing list=C2=A0 -= =C2=A0 <a shape=3D"rect" href=3D"mailto:[email protected]" target=3D"= _blank">[email protected]</a><br clear=3D"none"><a shape=3D"rect" hre= f=3D"https://mailman.open-bio.org/mailman/listinfo/biopython" target=3D"_bl= ank">https://mailman.open-bio.org/mailman/listinfo/biopython</a><br clear= =3D"none"></div></div> </div> </div></div></blockquote></div> --000000000000d45fdb061fa43f2a-- --===============0847370696558973119== 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 --===============0847370696558973119==--