-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization #154
Serialization #154
Conversation
@@ -35,12 +35,6 @@ def __str__(self): | |||
return "Exon(exon_id=%s, gene_name=%s, contig=%s, start=%d, end=%s)" % ( | |||
self.id, self.gene_name, self.contig, self.start, self.end) | |||
|
|||
def __repr__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to repr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of our implementations just call str
so I made that the default in Serializable
. Maybe that object needs to be renamed to something like SaneDefaultsForClassesWhichImplementToDict
.
|
||
def __str__(self): | ||
fields_str = ", ".join( | ||
"%s=%s" % (k, v) for (k, v) in sorted(self.to_dict().items())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see a use-case for not wanting to rely on sorting, but rather on some instrinsic ordering (e.g. ID first, name second, etc.). Any interest in using OrderedDict
s instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean just use the order of items()
but have to_dict()
return an OrderedDict
?
|
||
def _object_to_primitive_types(self): | ||
""" | ||
Given an instance of a Python object, returns a tuple whose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting confused between the tuple
here and the one above. Maybe rename _class_to_tuple
to _class_to_full_name_tuple
and _tuple_to_class
to _full_name_tuple_to_class
?
LGTM % comments 👍 |
…d_objects_in_state_dict
…tstate__ with __reduce__
…er than class methods
__reduce__ in Py2, dse a globally defined from_dict to get __reduce__ working on py2
7122fa0
to
b341b14
Compare
We previously had implementations of
__getstate__
and__setstate__
which (1) didn't work for non-human genomes and (2) used fragile positional arguments. This PR:Serializable
base class forGenome
,EnsemblRelease
,Gene
,Transcript
, andExon
,Species
. This allows us to share serialization/flattening code between these objects with copy/paste madness.to_json
/from_json
andto_dict
/from_dict
methods to all serializable objects.normalize_chromosome
andnormalize_strand
to a separate module (no changes to actual code)species.py
onto theSpecies
classThis change is