Skip to content

Commit

Permalink
Merge pull request #265 from molpopgen/binary_format_compatibility
Browse files Browse the repository at this point in the history
Binary format compatibility fixes and tests.
  • Loading branch information
molpopgen authored Jul 22, 2019
2 parents 75e0766 + ccf82a4 commit 3c6c3e5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include COPYING
include CMakeLists.txt
include fwdpy11/CMakeLists.txt
include tests/CMakeLists.txt
include tests/v045.bin
include tests/v045.lzma
include configure
include setup.py.in
include doc/conf.py
Expand Down
2 changes: 2 additions & 0 deletions doc/misc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Major changes include:
* Updating the fwdpp back-end to the pre-release code for fwdpp 0.8.0. Almost none of these changes are "user facing".
* Add :class:`fwdpy11.SiteTable`, :class:`fwdpy11.Site` and new fields to :class:`fwdpy11.MutationRecord`. `PR 258 <https://github.com/molpopgen/fwdpy11/pull/258>`_ These changes affect the API for some function calls. See :ref:`upgrade_path` for details.

Even though this release changes some of the tree sequence data structures, we are still able to read in files generated by version 0.4.5! (This is actually unit tested.)

Minor changes include:

* Add :func:`fwdpy11.gsl_version`. :class:`fwdpy11.MutationRecord`. `PR 256 <https://github.com/molpopgen/fwdpy11/pull/256>`_
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/headers/fwdpp
10 changes: 10 additions & 0 deletions fwdpy11/headers/fwdpy11/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ namespace fwdpy11
buffer, pop.ancient_sample_records);
fwdpp::io::deserialize_population(buffer, pop);
pop.tables = fwdpp::ts::io::deserialize_tables(buffer);
// NOTE: version 0.5.0 added in a site table that previous versions
// did not have. Further, the mutation table entries differed in
// previous versions.
if (!pop.tables.mutation_table.empty()
&& pop.tables.site_table.empty())
{
fwdpp::ts::io::
fix_mutation_table_repopulate_site_table(
pop.tables, pop.mutations);
}
if (!pop.tables.edge_table.empty())
{
std::vector<fwdpp::ts::TS_NODE_INT> samples(2 * pop.N);
Expand Down
2 changes: 1 addition & 1 deletion fwdpy11/src/fwdpp_types/MutationRecord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ init_ts_MutationRecord(py::module& m)
"Node id of the mutation")
.def_readonly("key", &fwdpp::ts::mutation_record::key,
"Index of the mutation in the population")
.def_readonly("site", &fwdpp::ts::mutation_record::key,
.def_readonly("site", &fwdpp::ts::mutation_record::site,
R"delim(Index of the mutation's site in the population.
.. versionadded:: 0.5.0)delim")
Expand Down
23 changes: 23 additions & 0 deletions tests/test_binary_format_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest
import fwdpy11
import pickle
import lzma


class TestOldBinaryFileFormats(unittest.TestCase):
def test_reading_045(self):
pop = fwdpy11.DiploidPopulation.load_from_file("tests/v045.bin")
for i in pop.tables.mutations:
self.assertEqual(
pop.mutations[i.key].pos, pop.tables.sites[i.site].position)

def test_unpickling_045(self):
with lzma.open('tests/v045.lzma', 'rb') as f:
pop = pickle.load(f)
for i in pop.tables.mutations:
self.assertEqual(
pop.mutations[i.key].pos, pop.tables.sites[i.site].position)


if __name__ == "__main__":
unittest.main()
Binary file added tests/v045.bin
Binary file not shown.
Binary file added tests/v045.lzma
Binary file not shown.

0 comments on commit 3c6c3e5

Please sign in to comment.