LoginSignup
0

More than 1 year has passed since last update.

posted at

Biopython Tutorial and Cookbook和訳(4.4)

4.4 Comparison

4.3へ

The SeqRecord objects can be very complex, but here’s a simple example:
SeqRecordはとても複雑ですが、簡単な例があります:

>>> 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?
同じ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!
古いッバージョンのBiopythonはpythonデフォルトのオブジェクト比較を使うため、メモリ上同じポイントを指すrecord1とrecord2の比較はTrueを返します。
この例では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:
Biopython 1.67ではSeqRecordの比較は明示的な例外を起こします。*

>>> 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:
他はご自身で試して見てください。例えば配列の識別子の比較なら:

>>> record1.id == record2.id
True
>>> record1.seq == record2.seq
True

Beware that comparing complex objects quickly gets complicated (see also Section 3.11).
複雑なオブジェクトを比較するとややこしくなることに用心しましょう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0