<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">You can use a key function which returns a tuple value instead of a scalar, and just ensure the values in the key tuple meet your needs for breaking ties. Tuples are ordered sequentially by their first element. If the first elements between two cases are equal, they compare the second, then the third, and so on.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-python" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;background:rgb(241,239,238);color:rgb(104,97,94);padding:0.5em">
feature_priority_map = {
    <span class="hljs-string" style="color:rgb(90,183,56)">"gene"</span>: <span class="hljs-number" style="color:rgb(223,83,32)">1</span>,
    <span class="hljs-string" style="color:rgb(90,183,56)">"regulatory"</span>: <span class="hljs-number" style="color:rgb(223,83,32)">2</span>,
    <span class="hljs-string" style="color:rgb(90,183,56)">"mRNA"</span>: <span class="hljs-number" style="color:rgb(223,83,32)">3</span>,
    <span class="hljs-comment" style="color:rgb(118,110,107)"># fill in the rest here</span>
}

<span class="hljs-function" style="color:rgb(64,126,231)"><span class="hljs-keyword" style="color:rgb(102,102,234)">def</span> <span class="hljs-title" style="color:rgb(118,110,107)">comparison_key</span><span class="hljs-params" style="color:rgb(223,83,32)">(feature)</span>:</span>
    <span class="hljs-keyword" style="color:rgb(102,102,234)">return</span> (feature.start, feature_priority_map[feature.type], )
</code></pre>
<p style="margin:0px 0px 1.2em!important">This key function will return a tuple containing the start position of the feature, and a priority number mapped from your list of feature types and the order they should appear in, since it sounds like lexicographic sorting is not what you want. You could add a third value to the tuple to address your third requirement, if it is concrete enough.</p>
<p style="margin:0px 0px 1.2em!important">The resulting tuple for a gene at position x is (x, 1). The tuple for an mRNA at position x is (x, 3). (x, 1) < (x, 3), so (x, 1) will come before (x, 3). This maps to the gene feature coming before the mRNA feature despite their starting at the same position in the genome.</p>
<p style="margin:0px 0px 1.2em!important">Just pass the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">comparison_key</code> function as the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">key</code> parameter to sort with these criteria.</p>
<div title="MDH:WW91IGNhbiB1c2UgYSBrZXkgZnVuY3Rpb24gd2hpY2ggcmV0dXJucyBhIHR1cGxlIHZhbHVlIGlu
c3RlYWQgb2YgYSBzY2FsYXIsIGFuZCBqdXN0IGVuc3VyZSB0aGUgdmFsdWVzIGluIHRoZSBrZXkg
dHVwbGUgbWVldCB5b3VyIG5lZWRzIGZvciBicmVha2luZyB0aWVzLiBUdXBsZXMgYXJlIG9yZGVy
ZWQgc2VxdWVudGlhbGx5IGJ5IHRoZWlyIGZpcnN0IGVsZW1lbnQuIElmIHRoZSBmaXJzdCBlbGVt
ZW50cyBiZXR3ZWVuIHR3byBjYXNlcyBhcmUgZXF1YWwsIHRoZXkgY29tcGFyZSB0aGUgc2Vjb25k
LCB0aGVuIHRoZSB0aGlyZCwgYW5kIHNvIG9uLjxkaXY+PGJyPjwvZGl2PjxkaXY+YGBgcHl0aG9u
PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5mZWF0dXJlX3ByaW9yaXR5X21hcCA9IHs8L2Rpdj48
ZGl2PiZuYnNwOyAmbmJzcDsgImdlbmUiOiAxLDwvZGl2PjxkaXY+Jm5ic3A7ICZuYnNwOyAicmVn
dWxhdG9yeSI6IDIsPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7ICJtUk5BIjogMyw8L2Rpdj48ZGl2
PiZuYnNwOyAmbmJzcDsgIyBmaWxsIGluIHRoZSByZXN0IGhlcmU8L2Rpdj48ZGl2Pn08L2Rpdj48
ZGl2Pjxicj48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PmRlZiBjb21wYXJpc29uX2tleShmZWF0
dXJlKTo8L2Rpdj48ZGl2PiZuYnNwOyAmbmJzcDsgcmV0dXJuIChmZWF0dXJlLnN0YXJ0LCBmZWF0
dXJlX3ByaW9yaXR5X21hcFtmZWF0dXJlLnR5cGVdLCApPC9kaXY+PGRpdj5gYGA8L2Rpdj48ZGl2
Pjxicj48L2Rpdj48ZGl2PlRoaXMga2V5IGZ1bmN0aW9uIHdpbGwgcmV0dXJuIGEgdHVwbGUgY29u
dGFpbmluZyB0aGUgc3RhcnQgcG9zaXRpb24gb2YgdGhlIGZlYXR1cmUsIGFuZCBhIHByaW9yaXR5
IG51bWJlciBtYXBwZWQgZnJvbSB5b3VyIGxpc3Qgb2YgZmVhdHVyZSB0eXBlcyBhbmQgdGhlIG9y
ZGVyIHRoZXkgc2hvdWxkIGFwcGVhciBpbiwgc2luY2UgaXQgc291bmRzIGxpa2UgbGV4aWNvZ3Jh
cGhpYyBzb3J0aW5nIGlzIG5vdCB3aGF0IHlvdSB3YW50LiBZb3UgY291bGQgYWRkIGEgdGhpcmQg
dmFsdWUgdG8gdGhlIHR1cGxlIHRvIGFkZHJlc3MgeW91ciB0aGlyZCByZXF1aXJlbWVudCwgaWYg
aXQgaXMgY29uY3JldGUgZW5vdWdoLjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+VGhlIHJlc3Vs
dGluZyB0dXBsZSBmb3IgYSBnZW5lIGF0IHBvc2l0aW9uIHggaXMgKHgsIDEpLiBUaGUgdHVwbGUg
Zm9yIGFuIG1STkEgYXQgcG9zaXRpb24geCBpcyAoeCwgMykuICh4LCAxKSAmbHQ7ICh4LCAzKSwg
c28gKHgsIDEpIHdpbGwgY29tZSBiZWZvcmUgKHgsIDMpLiBUaGlzIG1hcHMgdG8gdGhlIGdlbmUg
ZmVhdHVyZSBjb21pbmcgYmVmb3JlIHRoZSBtUk5BIGZlYXR1cmUgZGVzcGl0ZSB0aGVpciBzdGFy
dGluZyBhdCB0aGUgc2FtZSBwb3NpdGlvbiBpbiB0aGUgZ2Vub21lLjwvZGl2PjxkaXY+PGJyPjwv
ZGl2PjxkaXY+SnVzdCBwYXNzIHRoZSBgY29tcGFyaXNvbl9rZXlgJm5ic3A7ZnVuY3Rpb24gYXMg
dGhlIGBrZXlgIHBhcmFtZXRlciB0byBzb3J0IHdpdGggdGhlc2UgY3JpdGVyaWEuPC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 31, 2017 at 2:43 PM, Chevreux, Bastien <span dir="ltr"><<a href="mailto:bastien.chevreux@dsm.com" target="_blank">bastien.chevreux@dsm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple">
<div class="m_8581699893649892967WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Which leaves me no option than to explain the whole sorting logic and not just the subset I did to keep my basic problem easily solvable on this list :-)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I want/need, for GenBank output, have the usual “interleaved” sorting of features, i.e.,
<u></u><u></u></span></p>
<p class="m_8581699893649892967MsoListParagraph"><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><span>1.<span style="font:7.0pt "Times New Roman"">      
</span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">First by start position<u></u><u></u></span></p>
<p class="m_8581699893649892967MsoListParagraph"><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><span>2.<span style="font:7.0pt "Times New Roman"">      
</span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">On equal start, sort by type (first “gene”, then “regulatory”, then “mRNA”, “CDS”, etc.pp)<u></u><u></u></span></p>
<p class="m_8581699893649892967MsoListParagraph"><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><span>3.<span style="font:7.0pt "Times New Roman"">      
</span></span></span><u></u><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Maybe on equal start and type, sort by feature attributes (locus_tag, name etc.)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">(Maybe 2 & 3 need to be inversed in sorting logic, but that question is for another day)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I had considered using key and attrgetter, but these are not flexible enough for the above I think, are they?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Currently I do not see a way other than temporary monkey patching for this but would be happy to hear about one.<u></u><u></u></span></p><span class="">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Best,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">  Bastien<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Calibri",sans-serif;color:#008fd5">--
<br>
DSM Nutritional Products Microbia Inc | Bioinformatics<br>
60 Westview Street | Lexington, MA 02421 | United States<br>
Phone <a href="tel:(781)%20259-7613" value="+17812597613" target="_blank">+1 781 259 7613</a> | Fax <a href="tel:(781)%20259-0615" value="+17812590615" target="_blank">+1 781 259 0615</a></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
</span><div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <a href="mailto:lenna.peterson@gmail.com" target="_blank">lenna.peterson@gmail.com</a> [mailto:<a href="mailto:lenna.peterson@gmail.com" target="_blank">lenna.peterson@gmail.<wbr>com</a>]
<b>On Behalf Of </b>Lenna Peterson<br>
<b>Sent:</b> Tuesday, January 31, 2017 2:13 PM<br>
<b>To:</b> Chevreux, Bastien <<a href="mailto:bastien.chevreux@dsm.com" target="_blank">bastien.chevreux@dsm.com</a>><br>
<b>Cc:</b> Joshua Klein <<a href="mailto:mobiusklein@gmail.com" target="_blank">mobiusklein@gmail.com</a>>; Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>>; <a href="mailto:biopython@biopython.org" target="_blank">biopython@biopython.org</a></span></p><div><div class="h5"><br>
<b>Subject:</b> Re: [Biopython] Cannot make SeqFeature() comparable?<u></u><u></u></div></div><p></p>
</div>
</div><div><div class="h5">
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">--- This mail has been sent from an external source ---
<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">re: Joshua's post about the key argument, here is an example of sorting SeqFeatures by location start without (potentially error-prone) monkey patching:
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">import operator<u></u><u></u></p>
<div>
<p class="MsoNormal">sorted_features = sorted([f1, f2], key=operator.attrgetter("<wbr>location.start"))<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="https://docs.python.org/2/library/operator.html#operator.attrgetter" target="_blank">https://docs.python.org/2/<wbr>library/operator.html#<wbr>operator.attrgetter</a> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Lenna<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Jan 31, 2017 at 9:31 AM, Chevreux, Bastien <<a href="mailto:bastien.chevreux@dsm.com" target="_blank">bastien.chevreux@dsm.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">> From: Joshua Klein [mailto:<a href="mailto:mobiusklein@gmail.com" target="_blank">mobiusklein@gmail.com</a>]
</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">> […] When assigning to the class itself, not the module, the new</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">> comparator function is called</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Yay, that worked, learning something new every day. Thanks a million.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Peter: the ultimate goal of that request was to be able to call sort() on features, with sometimes
 different and very custom sort criteria. Nothing which would fit BioPython really.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Best,</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">  Bastien</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Calibri",sans-serif;color:#008fd5">--
<br>
DSM Nutritional Products Microbia Inc | Bioinformatics<br>
60 Westview Street | Lexington, MA 02421 | United States<br>
Phone <a href="tel:(781)%20259-7613" value="+17812597613" target="_blank">+1 781 259 7613</a> | Fax <a href="tel:(781)%20259-0615" value="+17812590615" target="_blank">+1 781 259 0615</a></span><u></u><u></u></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"> </span><u></u><u></u></p>
<div>
<div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Joshua
 Klein [mailto:<a href="mailto:mobiusklein@gmail.com" target="_blank">mobiusklein@gmail.com</a>]
<br>
<b>Sent:</b> Tuesday, January 31, 2017 7:48 AM<br>
<b>To:</b> Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>><br>
<b>Cc:</b> Chevreux, Bastien <<a href="mailto:bastien.chevreux@dsm.com" target="_blank">bastien.chevreux@dsm.com</a>>;
<a href="mailto:biopython@biopython.org" target="_blank">biopython@biopython.org</a><br>
<b>Subject:</b> Re: [Biopython] Cannot make SeqFeature() comparable?</span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">--- This mail has been sent from an external source ---
<u></u><u></u></p>
<div>
<div>
<div>
<div>
<div>
<p style="margin:1.2em!important">The reason the original code snippet doesn’t seem to be working as expected is that the
<code><span style="font-size:10.0pt;font-family:Consolas;border:solid #eaeaea 1.0pt;padding:0in;background:#f8f8f8">cmp1</span></code> function is assigned to the
<code><span style="font-size:10.0pt;font-family:Consolas;border:solid #eaeaea 1.0pt;padding:0in;background:#f8f8f8">__lt__</span></code> attribute of the
<code><span style="font-size:10.0pt;font-family:Consolas;border:solid #eaeaea 1.0pt;padding:0in;background:#f8f8f8">SeqFeature</span></code> module, not the
<code><span style="font-size:10.0pt;font-family:Consolas;border:solid #eaeaea 1.0pt;padding:0in;background:#f8f8f8">SeqFeature</span></code> class, which is located at
<code><span style="font-size:10.0pt;font-family:Consolas;border:solid #eaeaea 1.0pt;padding:0in;background:#f8f8f8">SeqFeature.SeqFeature</span></code>. When assigning to the class itself, not the module, the new comparator function is called.<u></u><u></u></p>
<p style="margin:1.2em!important">This sort of patching works differently for old-style and new-style classes, having to do with how special methods are looked up. Old style classes look up special methods on the instance, new style classes look them up on
 the instance’s class.<u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:1.0pt">​</span><u></u><u></u></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">On Tue, Jan 31, 2017 at 4:07 AM, Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal">Hi Bastien,<br>
<br>
I'm not immediately sure if "monkey patching" the class<br>
methods at run time like that would work in principle.<br>
If you insert a print into it, it does not seem to be invoked.<br>
<br>
It might be worth trying a modified Biopython, or an<br>
explicit subclass to narrow down where this breaks.<br>
<br>
Or more simply, can you just do the start position<br>
comparison explicitly if that's what you want to use?<br>
<br>
f1.location.start < f2.location.start<br>
<br>
Peter<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<br>
On Mon, Jan 30, 2017 at 11:05 PM, Chevreux, Bastien<br>
<<a href="mailto:bastien.chevreux@dsm.com" target="_blank">bastien.chevreux@dsm.com</a>> wrote:<br>
> Hi there,<br>
><br>
><br>
><br>
> I have a problem making the SeqFeature() class comparable by providing a<br>
> __lt__ function. Consider the following:<br>
><br>
><br>
><br>
> ------------------------------<wbr>------------------------------<wbr>------<br>
><br>
> #!/usr/bin/env python3<br>
><br>
><br>
><br>
> from Bio import SeqFeature<br>
><br>
><br>
><br>
> def cmp1(this,other):<br>
><br>
>     return int(this.location.start) < int(other.location.start);<br>
><br>
><br>
><br>
> SeqFeature.__lt__=cmp1;<br>
><br>
> f1 = SeqFeature.SeqFeature(<wbr>SeqFeature.FeatureLocation(10, 200));<br>
><br>
> f2 = SeqFeature.SeqFeature(<wbr>SeqFeature.FeatureLocation(<wbr>1000, 1200));<br>
><br>
><br>
><br>
> if f1<f2:<br>
><br>
>     print("f1<f2");<br>
><br>
> else:<br>
><br>
>     print("nope, f1>=f2");<br>
><br>
> ------------------------------<wbr>------------------------------<wbr>------<br>
><br>
><br>
><br>
> The code above runs with an error message:<br>
><br>
>     if f1<f2:<br>
><br>
> TypeError: unorderable types: SeqFeature() < SeqFeature()<br>
><br>
><br>
><br>
> What I do not understand is that this should be the canonical recipe for<br>
> making any class comparable via LT operator. Compare to the following code<br>
> which runs without problems:<br>
><br>
><br>
><br>
> ------------------------------<wbr>------------------------------<wbr>------<br>
><br>
> #!/usr/bin/env python3<br>
><br>
><br>
><br>
> class myclass():<br>
><br>
>     def __init__(self, value):<br>
><br>
>         self.bla=value;<br>
><br>
><br>
><br>
> def cmp2(this,other):<br>
><br>
>     return this.bla < other.bla;<br>
><br>
><br>
><br>
> myclass.__lt__=cmp2;<br>
><br>
> m1=myclass(1);<br>
><br>
> m2=myclass(2);<br>
><br>
><br>
><br>
> if m1<m2:<br>
><br>
>     print("m1<m2");<br>
><br>
> else:<br>
><br>
>     print("nope, m1>=m2");<br>
><br>
> ------------------------------<wbr>------------------------------<wbr>------<br>
><br>
><br>
><br>
> What am I missing?<br>
><br>
><br>
><br>
> Best,<br>
><br>
>   Bastien<br>
><br>
><br>
><br>
> --<br>
> DSM Nutritional Products Microbia Inc | Bioinformatics<br>
> 60 Westview Street | Lexington, MA 02421 | United States<br>
> Phone <a href="tel:(781)%20259-7613" value="+17812597613" target="_blank">+1 781 259 7613</a> | Fax <a href="tel:(781)%20259-0615" value="+17812590615" target="_blank">+1 781 259 0615</a><br>
><br>
><br>
><br>
><br>
> ______________________________<wbr>__<br>
><br>
> DISCLAIMER:<br>
> This e-mail is for the intended recipient only.<br>
> If you have received it by mistake please let us know by reply and then<br>
> delete it from your system; access, disclosure, copying, distribution or<br>
> reliance on any of it by anyone else is prohibited.<br>
> If you as intended recipient have received this e-mail incorrectly, please<br>
> notify the sender (via e-mail) immediately.<br>
><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal">> ______________________________<wbr>_________________<br>
> Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org" target="_blank">
Biopython@mailman.open-bio.org</a><br>
> <a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">
http://mailman.open-bio.org/<wbr>mailman/listinfo/biopython</a><br>
______________________________<wbr>_________________<br>
Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org" target="_blank">
Biopython@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/<wbr>mailman/listinfo/biopython</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><br>
______________________________<wbr>_________________<br>
Biopython mailing list  -  <a href="mailto:Biopython@mailman.open-bio.org" target="_blank">Biopython@mailman.open-bio.org</a><br>
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" target="_blank">http://mailman.open-bio.org/<wbr>mailman/listinfo/biopython</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></div></div>
</div>

</blockquote></div><br></div>