def test_serialization(): variants = [ Variant(1, start=10, ref="AA", alt="AAT", ensembl=ensembl77), Variant(10, start=15, ref="A", alt="G"), Variant(20, start=150, ref="", alt="G"), ] for original in variants: # This causes the variant's ensembl object to make a SQL connection, # which makes the ensembl object non-serializable. By calling this # method, we are checking that we don't attempt to directly serialize # the ensembl object. original.effects() # Test pickling. serialized = pickle.dumps(original) reconstituted = pickle.loads(serialized) assert original == reconstituted assert original.contig == reconstituted.contig assert original.ref == reconstituted.ref assert original.alt == reconstituted.alt assert original.start == reconstituted.start assert original.end == reconstituted.end # Test json. serialized = original.to_json() reconstituted = Variant.from_json(serialized) assert original == reconstituted
def test_serialization(): variants = [ Variant( 1, start=10, ref="AA", alt="AAT", ensembl=ensembl_grch38), Variant(10, start=15, ref="A", alt="G"), Variant(20, start=150, ref="", alt="G"), ] for original in variants: # This causes the variant's ensembl object to make a SQL connection, # which makes the ensembl object non-serializable. By calling this # method, we are checking that we don't attempt to directly serialize # the ensembl object. original.effects() # Test pickling. serialized = pickle.dumps(original) reconstituted = pickle.loads(serialized) eq_(original, reconstituted) eq_(original.contig, reconstituted.contig) eq_(original.ref, reconstituted.ref) eq_(original.alt, reconstituted.alt) eq_(original.start, reconstituted.start) eq_(original.end, reconstituted.end) eq_(original.original_ref, reconstituted.original_ref) eq_(original.original_alt, reconstituted.original_alt) eq_(original.original_start, reconstituted.original_start) # Test json. serialized = original.to_json() reconstituted = Variant.from_json(serialized) eq_(original, reconstituted)
def test_serialization(): variants = [ Variant( 1, start=10, ref="AA", alt="AAT", genome=ensembl_grch38), Variant(10, start=15, ref="A", alt="G"), Variant(20, start=150, ref="", alt="G"), ] for original in variants: # This causes the variant's ensembl object to make a SQL connection, # which makes the ensembl object non-serializable. By calling this # method, we are checking that we don't attempt to directly serialize # the ensembl object. original.effects() # Test pickling. serialized = pickle.dumps(original) reconstituted = pickle.loads(serialized) eq_(original, reconstituted) eq_(original.contig, reconstituted.contig) eq_(original.ref, reconstituted.ref) eq_(original.alt, reconstituted.alt) eq_(original.start, reconstituted.start) eq_(original.end, reconstituted.end) eq_(original.original_ref, reconstituted.original_ref) eq_(original.original_alt, reconstituted.original_alt) eq_(original.original_start, reconstituted.original_start) # Test json. serialized = original.to_json() reconstituted = Variant.from_json(serialized) eq_(original, reconstituted)
def test_deserialization_old_keywords(): old_variant_representation_json = """ { "ref": "T", "contig": "22", "start": 23230319, "__class__": { "__name__": "Variant", "__module__": "varcode.variant" }, "normalize_contig_name": true, "alt": "G", "allow_extended_nucleotides": false, "ensembl": { "__class__": { "__name__": "EnsemblRelease", "__module__": "pyensembl.ensembl_release" }, "release": 75, "server": "ftp://ftp.ensembl.org", "species": { "__class__": { "__name__": "Species", "__module__": "pyensembl.species" }, "latin_name": "homo_sapiens" } } } """ variant = Variant.from_json(old_variant_representation_json) eq_(variant.contig, "22") eq_(variant.ref, "T") eq_(variant.alt, "G") eq_(variant.reference_name, "GRCh37") eq_(variant.normalize_contig_names, True) eq_(variant.allow_extended_nucleotides, False)