4.4 Comparison To 4.3
The SeqRecord objects can be very complex, but here’s a simple example: ** SeqRecord is very complex, but there is a simple example: **
>>> from Bio.Seq import Seq
>>> from Bio.SeqRecord import SeqRecord
>>> record1 = SeqRecord(Seq("ACGT"), id="test")
>>> record2 = SeqRecord(Seq("ACGT"), id="test")
What happens when you try to compare these “identical” records? ** What happens if I compare the same record? ** **
>>> record1 == record2
...
Perhaps surprisingly older versions of Biopython would use Python’s default object comparison for the SeqRecord, meaning record1 == record2 would only return True if these variables pointed at the same object in memory. In this example, record1 == record2 would have returned False here! ** Older versions of Biopython use the python default object comparison, so comparing record1 and record2 pointing to the same point in memory returns True. This example returns False. ** **
>>> record1 == record2 # on old versions of Biopython!
False
As of Biopython 1.67, SeqRecord comparison like record1 == record2 will instead raise an explicit error to avoid people being caught out by this: ** In Biopython 1.67, SeqRecord comparisons raise an explicit exception. *** ***
>>> record1 == record2
Traceback (most recent call last):
...
NotImplementedError: SeqRecord comparison is deliberately not implemented. Explicitly compare the attributes of interest.
Instead you should check the attributes you are interested in, for example the identifier and the sequence: ** Please try the others yourself. For example, when comparing array identifiers: **
>>> record1.id == record2.id
True
>>> record1.seq == record2.seq
True
Beware that comparing complex objects quickly gets complicated (see also Section 3.11). ** Beware that comparing complex objects can be confusing. ** **
Recommended Posts