[Biopython] Cannot make SeqFeature() comparable?

Chevreux, Bastien bastien.chevreux at dsm.com
Mon Jan 30 23:05:21 UTC 2017


Hi there,

I have a problem making the SeqFeature() class comparable by providing a __lt__ function. Consider the following:

------------------------------------------------------------------
#!/usr/bin/env python3

from Bio import SeqFeature

def cmp1(this,other):
    return int(this.location.start) < int(other.location.start);

SeqFeature.__lt__=cmp1;
f1 = SeqFeature.SeqFeature(SeqFeature.FeatureLocation(10, 200));
f2 = SeqFeature.SeqFeature(SeqFeature.FeatureLocation(1000, 1200));

if f1<f2:
    print("f1<f2");
else:
    print("nope, f1>=f2");
------------------------------------------------------------------

The code above runs with an error message:
    if f1<f2:
TypeError: unorderable types: SeqFeature() < SeqFeature()

What I do not understand is that this should be the canonical recipe for making any class comparable via LT operator. Compare to the following code which runs without problems:

------------------------------------------------------------------
#!/usr/bin/env python3

class myclass():
    def __init__(self, value):
        self.bla=value;

def cmp2(this,other):
    return this.bla < other.bla;

myclass.__lt__=cmp2;
m1=myclass(1);
m2=myclass(2);

if m1<m2:
    print("m1<m2");
else:
    print("nope, m1>=m2");
------------------------------------------------------------------

What am I missing?

Best,
  Bastien

--
DSM Nutritional Products Microbia Inc | Bioinformatics
60 Westview Street | Lexington, MA 02421 | United States
Phone +1 781 259 7613 | Fax +1 781 259 0615


________________________________

DISCLAIMER:
This e-mail is for the intended recipient only.
If you have received it by mistake please let us know by reply and then delete it from your system; access, disclosure, copying, distribution or reliance on any of it by anyone else is prohibited.
If you as intended recipient have received this e-mail incorrectly, please notify the sender (via e-mail) immediately.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20170130/11eec3ba/attachment.html>


More information about the Biopython mailing list