[Biopython-dev] SeqRecord comparison suggestion

Peter Cock p.j.a.cock at googlemail.com
Wed Feb 5 18:15:08 UTC 2014


On Tue, Feb 4, 2014 at 8:56 PM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
>
> We should probably switch the current FutureWarning to a noisy
> BiopythonWarning ... because the current warning is (almost) silent. I think
> this was silenced in a recentish Python release, from memory it used to give
> a clear warning to the user :(

Correction - I should have double checked this before writing the email,
the FutureWarning from Seq comparison works fine:

>>> from Bio.Seq  import Seq
>>> Seq("ACGT") == "ACGT"
False
>>> Seq("ACGT") == Seq("ACGT")
/Library/Python/2.7/site-packages/Bio/Seq.py:179: FutureWarning: In
future comparing Seq objects will use string comparison (not object
comparison). Incompatible alphabets will trigger a warning (not an
exception). In the interim please use id(seq1)==id(seq2) or
str(seq1)==str(seq2) to make your code explicit and to avoid this
warning.

(It may be time to actually try switching Seq equality to be string like...)

On Tue, Feb 4, 2014 at 12:57 PM, Iddo Friedberg <idoerg at gmail.com> wrote:

> Thanks!
>
> My initial thoughts are that seqrecord instances should not have an __eq__
> operator. The equality operation here is somewhat meaningless when you
> consider the number of parameters that can constitute a seqrecord,
> especially when dealing with a genomic record or  a contig. This can lead
> to unexpected behaviour.

Indeed, which is one reason why we never defined __eq__ etc for the
SeqRecord (how equal is equal? Same ID? Same sequence? Same
annotions?).

Therefore the SeqRecord gets the default Python object equality, which
is are they the same object in memory?

Peter



More information about the Biopython-dev mailing list