Skip to content

Compress top-level metadata #35

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

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ def test_small_msprime_migration(self):
self.assertGreater(ts.num_trees, 2)
self.verify(ts)

def test_small_msprime_top_level_metadata(self):
ts = msprime.simulate(10, recombination_rate=2, mutation_rate=2, random_seed=2)
self.assertGreater(ts.num_sites, 2)
self.assertGreater(ts.num_trees, 2)
tables = ts.dump_tables()
top_level_schema = {
'codec': 'json',
'properties': {'my_int': {'type': 'integer'}}
}
tables.metadata_schema = tskit.MetadataSchema(top_level_schema)
tables.metadata = {"my_int": 1234}
self.verify(tables.tree_sequence())

def test_small_msprime_individuals_metadata(self):
ts = msprime.simulate(10, recombination_rate=1, mutation_rate=2, random_seed=2)
self.assertGreater(ts.num_sites, 2)
Expand Down
6 changes: 6 additions & 0 deletions tszip/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def compress_zarr(ts, root, variants_only=False):
root.attrs["format_version"] = FORMAT_VERSION
root.attrs["sequence_length"] = tables.sequence_length
root.attrs["provenance"] = provenance_dict
if tables.metadata_schema.schema is not None:
root.attrs["metadata_schema"] = tables.metadata_schema.schema
root.attrs["metadata"] = tables.metadata

columns = [
Column("coordinates", coordinates),
Expand Down Expand Up @@ -280,6 +283,9 @@ def load_zarr(path):
def decompress_zarr(root):
tables = tskit.TableCollection(root.attrs["sequence_length"])
coordinates = root["coordinates"][:]
if "metadata_schema" in root.attrs and "metadata" in root.attrs:
tables.metadata_schema = tskit.MetadataSchema(root.attrs["metadata_schema"])
tables.metadata = root.attrs["metadata"]

tables.individuals.set_columns(
flags=root["individuals/flags"],
Expand Down