[Biopython-dev] [Bug 2883] Errors after unpickling of 1.49 seqrecords
bugzilla-daemon at portal.open-bio.org
bugzilla-daemon at portal.open-bio.org
Wed Jul 22 15:44:47 UTC 2009
http://bugzilla.open-bio.org/show_bug.cgi?id=2883
------- Comment #2 from biopython-bugzilla at maubp.freeserve.co.uk 2009-07-22 11:44 EST -------
It sounds like pickling and unpickling worked for you on Biopython 1.49, but I
am not 100% sure that is what you meant.
The good news is I can pickle/unpickle a new SeqRecord object:
>>> import pickle
>>> from Bio.Seq import Seq
>>> from Bio.Alphabet import generic_dna
>>> s = Seq("ACGT", generic_dna)
>>> s2 = pickle.loads(pickle.dumps(s))
>>> s2
Seq('ACGT', DNAAlphabet())
>>> from Bio.SeqRecord import SeqRecord
>>> r = SeqRecord(s, id="test", letter_annotations={"dummy":[4,3,2,1]})
>>> print r
ID: test
Name: <unknown name>
Description: <unknown description>
Number of features: 0
Per letter annotation for: dummy
Seq('ACGT', DNAAlphabet())
>>> r2 = pickle.loads(pickle.dumps(r))
>>> print r2
ID: test
Name: <unknown name>
Description: <unknown description>
Number of features: 0
Per letter annotation for: dummy
Seq('ACGT', DNAAlphabet())
And this also works with cPickle:
>>> import cPickle
>>> s3 = cPickle.loads(cPickle.dumps(s))
>>> s3
Seq('ACGT', DNAAlphabet())
>>> r3 = cPickle.loads(cPickle.dumps(r))
>>> print r3
ID: test
Name: <unknown name>
Description: <unknown description>
Number of features: 0
Per letter annotation for: dummy
Seq('ACGT', DNAAlphabet())
I would expect you to be able to pickle/unpickle new objects on your system
too.
However, I can confirm trying to unpickle the example you attached to this bug
also fails for me (using the latest Biopython from CVS).
As you may be aware, per-letter-annotation support was added in Biopython 1.50
which is stored internally by a private property of the SeqRecord,
_per_letter_annotations. The seq property is also now stored internally by a
private property of the SeqRecord, _seq. This means if you unpickle a
pre-Biopython 1.50 SeqRecord on Biopython 1.50 or later, the
_per_letter_annotations and _seq properties never gets initialised. This causes
the two errors you saw.
I don't think there is much we can do about this... not without making the
SeqRecord even more complicated, e.g.
http://code.activestate.com/recipes/521901/
Peter
P.S. Bug 2838 was a problem in the DBSeqRecord (used for BioSQL), and shouldn't
be relevant to the underlying SeqRecord object, or this issue.
--
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the Biopython-dev
mailing list